2024 All Complete!

This commit is contained in:
Brian Buller 2024-12-25 08:10:36 -06:00
parent 40da8b1a0a
commit 521b8c2bcf
3 changed files with 4119 additions and 0 deletions

3999
2024/day25/input Normal file

File diff suppressed because it is too large Load Diff

81
2024/day25/main.go Normal file
View File

@ -0,0 +1,81 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
}
func part1(inp []string) {
fmt.Println("# Part 1")
keys, locks := parseInput(inp)
var pairs int
for k := range keys {
for l := range locks {
if fits(keys[k], locks[l]) {
pairs++
}
}
}
fmt.Println("Unique Pairs:", pairs)
}
func parseInput(inp []string) ([][]int, [][]int) {
var keys, locks [][]int
for i := 0; i < len(inp); i += 8 {
switch inp[i] {
case "#####":
locks = append(locks, findPinDepths(inp[i:i+7]))
case ".....":
keys = append(keys, findToothDepths(inp[i:i+7]))
}
}
return keys, locks
}
func findPinDepths(inp []string) []int {
pins := make(map[int]int)
for i := range inp {
for pin := range inp[i] {
if _, ok := pins[pin]; !ok {
if inp[i][pin] == '.' {
pins[pin] = i - 1
}
}
}
}
ret := []int{pins[0], pins[1], pins[2], pins[3], pins[4]}
return ret
}
func findToothDepths(inp []string) []int {
teeth := make(map[int]int)
for i := range inp {
for tooth := range inp[i] {
if _, ok := teeth[tooth]; !ok {
if inp[i][tooth] == '#' {
teeth[tooth] = 6 - i
}
}
}
}
ret := []int{teeth[0], teeth[1], teeth[2], teeth[3], teeth[4]}
return ret
}
func fits(key, lock []int) bool {
if len(key) != len(lock) {
return false
}
for i := 0; i < len(key); i++ {
if key[i]+lock[i] > 5 {
return false
}
}
return true
}

39
2024/day25/testinput Normal file
View File

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