Skip to content

Commit d44a930

Browse files
committed
Solution for 2024, day 25
1 parent b35eaaf commit d44a930

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

2024/25/Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
input:
2+
http "https://adventofcode.com/2024/day/25/input" "Cookie:session=${AOC_SESSION};" >input
3+
4+
main1:
5+
go build -o main1 main1.go
6+
7+
.PHONY: run1 clean
8+
9+
run1: main1 input
10+
./main1 <input
11+
12+
clean:
13+
rm -f main1 input

2024/25/main1.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
)
8+
9+
const (
10+
Pins = 5
11+
Height = 7
12+
)
13+
14+
type Schematic [Pins]int
15+
16+
func main() {
17+
keys, locks := parseInput()
18+
19+
count := 0
20+
for _, key := range keys {
21+
for _, lock := range locks {
22+
if !overlap(key, lock) {
23+
count++
24+
}
25+
}
26+
}
27+
fmt.Println(count)
28+
}
29+
30+
func overlap(key, lock Schematic) bool {
31+
for i := 0; i < Pins; i++ {
32+
if key[i]+lock[i] > Height-2 {
33+
return true
34+
}
35+
}
36+
return false
37+
}
38+
39+
func parseInput() ([]Schematic, []Schematic) {
40+
var keys, locks []Schematic
41+
42+
scanner := bufio.NewScanner(os.Stdin)
43+
for {
44+
m := [Height]string{}
45+
for i := 0; i < Height; i++ {
46+
if !scanner.Scan() {
47+
return keys, locks
48+
}
49+
m[i] = scanner.Text()
50+
}
51+
52+
val, isLock := parseSchema(m)
53+
if isLock {
54+
locks = append(locks, val)
55+
} else {
56+
keys = append(keys, val)
57+
}
58+
scanner.Scan()
59+
}
60+
}
61+
62+
func parseSchema(m [Height]string) (Schematic, bool) {
63+
res := Schematic{}
64+
for j := 0; j < Pins; j++ {
65+
count := 0
66+
// ignore first and last line
67+
for i := 1; i < Height-1; i++ {
68+
if m[i][j] == '#' {
69+
count++
70+
}
71+
}
72+
res[j] = count
73+
}
74+
return res, m[0] == "#####" && m[Height-1] == "....."
75+
}

0 commit comments

Comments
 (0)