-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (71 loc) · 1.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"github.com/Alex-Waring/AoC/utils"
)
func part1(input []string) {
defer utils.Timer("part1")()
keys := [][5]int{}
locks := [][5]int{}
for i := 0; i < len(input); i = i + 8 {
if input[i] == "....." {
keys = append(keys, parseKeys([6]string{input[i+1], input[i+2], input[i+3], input[i+4], input[i+5], input[i+6]}))
} else {
locks = append(locks, parseLocks([6]string{input[i+1], input[i+2], input[i+3], input[i+4], input[i+5], input[i+6]}))
}
}
possible := 0
for i := 0; i < len(keys); i++ {
for j := 0; j < len(locks); j++ {
key_to_try := keys[i]
lock_to_try := locks[j]
lock_fits := true
for k := 0; k < 5; k++ {
if key_to_try[k]+lock_to_try[k] > 5 {
lock_fits = false
break
}
}
if lock_fits {
possible += 1
}
}
}
fmt.Println(possible)
}
func parseLocks(input [6]string) [5]int {
returnValue := [5]int{}
for i := 0; i < 5; i++ {
returnValue[i] = 0
}
for i := 0; i < 6; i++ {
for j := 0; j < 5; j++ {
if input[i][j] == '#' {
returnValue[j] += 1
}
}
}
return returnValue
}
func parseKeys(input [6]string) [5]int {
returnValue := [5]int{}
for i := 0; i < 5; i++ {
returnValue[i] = 0
}
for i := 0; i < 5; i++ {
for j := 0; j < 5; j++ {
if input[i][j] == '#' {
returnValue[j] += 1
}
}
}
return returnValue
}
func part2(input []string) {
defer utils.Timer("part2")()
}
func main() {
input := utils.ReadInput("input.txt")
part1(input)
part2(input)
}