mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement day 13 in Go.
This commit is contained in:
@@ -13,6 +13,7 @@ The current plan, in no particular order:
|
|||||||
- [x] C# - [Day 07](./day-07/solution.cs)
|
- [x] C# - [Day 07](./day-07/solution.cs)
|
||||||
- [x] Clojure - [Day 03](./day-03/solution.clj)
|
- [x] Clojure - [Day 03](./day-03/solution.clj)
|
||||||
- [ ] Coffeescript
|
- [ ] Coffeescript
|
||||||
|
- [x] Go - [Day 13](./day-13/solution.go)
|
||||||
- [ ] Haskell
|
- [ ] Haskell
|
||||||
- [ ] Java
|
- [ ] Java
|
||||||
- [x] Kotlin - [Day 10](./day-10/solution.kt)
|
- [x] Kotlin - [Day 10](./day-10/solution.kt)
|
||||||
|
|||||||
43
2017/day-13/input.txt
Normal file
43
2017/day-13/input.txt
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
0: 3
|
||||||
|
1: 2
|
||||||
|
2: 4
|
||||||
|
4: 6
|
||||||
|
6: 4
|
||||||
|
8: 6
|
||||||
|
10: 5
|
||||||
|
12: 6
|
||||||
|
14: 8
|
||||||
|
16: 8
|
||||||
|
18: 8
|
||||||
|
20: 6
|
||||||
|
22: 12
|
||||||
|
24: 8
|
||||||
|
26: 8
|
||||||
|
28: 10
|
||||||
|
30: 9
|
||||||
|
32: 12
|
||||||
|
34: 8
|
||||||
|
36: 12
|
||||||
|
38: 12
|
||||||
|
40: 12
|
||||||
|
42: 14
|
||||||
|
44: 14
|
||||||
|
46: 12
|
||||||
|
48: 12
|
||||||
|
50: 12
|
||||||
|
52: 12
|
||||||
|
54: 14
|
||||||
|
56: 12
|
||||||
|
58: 14
|
||||||
|
60: 14
|
||||||
|
62: 14
|
||||||
|
64: 14
|
||||||
|
70: 10
|
||||||
|
72: 14
|
||||||
|
74: 14
|
||||||
|
76: 14
|
||||||
|
78: 14
|
||||||
|
82: 14
|
||||||
|
86: 17
|
||||||
|
88: 18
|
||||||
|
96: 26
|
||||||
54
2017/day-13/solution.go
Normal file
54
2017/day-13/solution.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func read_input() map[int]int {
|
||||||
|
var level, depth int
|
||||||
|
|
||||||
|
var result = make(map[int]int)
|
||||||
|
|
||||||
|
for {
|
||||||
|
if n, err := fmt.Scanf("%d: %d", &level, &depth); n != 2 || err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
result[level] = depth
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func penalty(firewalls map[int]int) int {
|
||||||
|
var score = 0
|
||||||
|
|
||||||
|
for level, depth := range firewalls {
|
||||||
|
if level % (2 * depth - 2) == 0 {
|
||||||
|
score += level * depth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return score
|
||||||
|
}
|
||||||
|
|
||||||
|
func caught(firewalls map[int]int, offset int) bool {
|
||||||
|
for level, depth := range firewalls {
|
||||||
|
if (level + offset) % (2 * depth - 2) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
firewalls := read_input()
|
||||||
|
|
||||||
|
fmt.Printf("Penalty: %d\n", penalty(firewalls))
|
||||||
|
|
||||||
|
var offset = 1
|
||||||
|
|
||||||
|
for ; caught(firewalls, offset); offset++ {
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Wait time: %d\n", offset)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user