work
This commit is contained in:
76
2024/go/day25/day25.go
Normal file
76
2024/go/day25/day25.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package day25
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"math"
|
||||
)
|
||||
|
||||
type Lock struct {
|
||||
diagram string
|
||||
combination int
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
diagram string
|
||||
combination int
|
||||
}
|
||||
|
||||
type Pair struct {
|
||||
l Lock
|
||||
k Key
|
||||
}
|
||||
|
||||
func Part1(input string) int {
|
||||
data := strings.Split(input, "\n\n")
|
||||
locks := make([]Lock, 0)
|
||||
keys := make([]Key, 0)
|
||||
pairs := make([]Pair, 0)
|
||||
|
||||
for _, in := range data {
|
||||
if in[0] == '#' {
|
||||
locks = append(locks, Lock{diagram: in, combination: combination(in, '.') })
|
||||
} else {
|
||||
keys = append(keys, Key{diagram: in, combination: combination(in, '#')})
|
||||
}
|
||||
}
|
||||
|
||||
for _, l := range locks {
|
||||
for _, k := range keys {
|
||||
if key_fits(l.combination, k.combination) {
|
||||
pairs = append(pairs, Pair{l: l, k: k})
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Printf("locks: %d, keys: %d\n", len(locks), len(keys))
|
||||
fmt.Printf("pair0 lock\n%s\n%d\n", pairs[0].l.diagram , pairs[0].l.combination)
|
||||
fmt.Printf("pair0 key\n%s\n%d\n",pairs[0].k.diagram, pairs[0].k.combination)
|
||||
return len(pairs)
|
||||
}
|
||||
|
||||
func Part2(input string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func combination(d string, k rune) int {
|
||||
comb := 0
|
||||
rows := strings.Split(d, "\n")
|
||||
columns := len(rows[0])
|
||||
for _, r := range rows {
|
||||
for i, c := range r {
|
||||
if c == k {
|
||||
comb += 1 * int(math.Pow10(columns - i - 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
return comb
|
||||
}
|
||||
|
||||
func key_fits(l int, k int) bool {
|
||||
for i:=1;i<6;i++ {
|
||||
ll := l % int(math.Pow10(i))
|
||||
kk := k % int(math.Pow10(i))
|
||||
if ll < kk { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
24
2024/go/day25/day25_test.go
Normal file
24
2024/go/day25/day25_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package day25
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPart1(t *testing.T) {
|
||||
data, err := os.ReadFile("input.txt")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read file: %s", err)
|
||||
}
|
||||
|
||||
r := Part1(string(data))
|
||||
require.Equal(t, 0, r)
|
||||
}
|
||||
|
||||
func TestPart2(t *testing.T) {
|
||||
r := Part2("")
|
||||
require.Equal(t, 0, r)
|
||||
}
|
||||
3999
2024/go/day25/input.txt
Normal file
3999
2024/go/day25/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user