-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.go
62 lines (53 loc) · 923 Bytes
/
day25.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
package main
import (
"fmt"
"log"
"os"
"strings"
)
func main() {
filename := "input.txt"
if len(os.Args) >= 2 {
filename = os.Args[1]
}
data, err := os.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
var keys, locks [][]int
schematicsList := strings.Split(string(data), "\n\n")
for _, schematics := range schematicsList {
lines := strings.Split(schematics, "\n")
heights := []int{-1, -1, -1, -1, -1}
for _, line := range lines {
if len(line) == 5 {
for x, c := range line {
if c == '#' {
heights[x]++
}
}
}
}
if lines[0] == "#####" {
locks = append(locks, heights)
} else {
keys = append(keys, heights)
}
}
sum := 0
for _, lock := range locks {
for _, key := range keys {
valid := true
for i := range key {
if key[i]+lock[i] > 5 {
valid = false
break
}
}
if valid {
sum++
}
}
}
fmt.Println(sum)
}