-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
70 lines (57 loc) · 1.18 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
package main
import (
"fmt"
"github.com./believer/aoc-2024/utils/files"
)
func main() {
fmt.Println("Part 1: ", part1("input.txt"))
fmt.Println("Part 2: ", part2("input.txt"))
}
func part1(name string) int {
lines := files.ReadParagraphs(name)
locks := [][]int{}
keys := [][]int{}
for _, l := range lines {
lockOrKey := make([]int, 5)
// Locks with first row as #
// Keys with last row as #
if l[0][0] == '#' {
for _, r := range l[1:] {
for i, c := range r {
if c == '#' {
lockOrKey[i]++
}
}
}
locks = append(locks, lockOrKey)
} else {
for _, r := range l[:len(l)-1] {
for i, c := range r {
if c == '#' {
lockOrKey[i]++
}
}
}
keys = append(keys, lockOrKey)
}
}
matchingKeys := 0
for _, lock := range locks {
for _, key := range keys {
c1 := lock[0]+key[0] <= 5
c2 := lock[1]+key[1] <= 5
c3 := lock[2]+key[2] <= 5
c4 := lock[3]+key[3] <= 5
c5 := lock[4]+key[4] <= 5
// There are no overlaps if all column combinations
// are less than or equal to five
if c1 && c2 && c3 && c4 && c5 {
matchingKeys++
}
}
}
return matchingKeys
}
func part2(name string) int {
return 0
}