Day 25, no part 2 lmao

This commit is contained in:
2024-12-25 15:55:31 +01:00
parent 46859764ad
commit 5f7666ee13
5 changed files with 4106 additions and 0 deletions

3999
day25/data.txt Normal file

File diff suppressed because it is too large Load Diff

39
day25/example.txt Normal file
View File

@ -0,0 +1,39 @@
#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####

3
day25/go.mod Normal file
View File

@ -0,0 +1,3 @@
module stevenlr.com/aoc2024/day25
go 1.23.3

64
day25/main.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
fmt.Println(part1(readData("example.txt")), 3)
fmt.Println(part1(readData("data.txt")), 3)
}
type Data struct {
keys [][5]int
locks [][5]int
}
func fits(k, l [5]int) bool {
for i := range k {
if k[i]+l[i] > 5 {
return false
}
}
return true
}
func part1(data Data) (count int) {
for _, k := range data.keys {
for _, l := range data.locks {
if fits(k, l) {
count++
}
}
}
return
}
func readData(fileName string) (data Data) {
data = Data{}
fp, _ := os.Open(fileName)
scanner := bufio.NewScanner(fp)
for scanner.Scan() {
isKey := scanner.Text()[0] == '.'
code := [5]int{0, 0, 0, 0, 0}
for i := 0; scanner.Scan() && i < 5; i++ {
line := scanner.Text()
for j := range 5 {
if line[j] == '#' {
code[j]++
}
}
}
scanner.Scan()
if isKey {
data.keys = append(data.keys, code)
} else {
data.locks = append(data.locks, code)
}
}
return
}

View File

@ -17,6 +17,7 @@ use (
./day22
./day23
./day24
./day25
./day2
./day3
./day4