chore: add day25 part 1
This commit is contained in:
parent
e046a6c06d
commit
0d652660f1
13
aoc2023/day25/example.txt
Normal file
13
aoc2023/day25/example.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
jqt: rhn xhk nvd
|
||||
rsh: frs pzl lsr
|
||||
xhk: hfx
|
||||
cmg: qnr nvd lhk bvb
|
||||
rhn: xhk bvb hfx
|
||||
bvb: xhk hfx
|
||||
pzl: lsr hfx nvd
|
||||
qnr: nvd
|
||||
ntq: jqt hfx bvb xhk
|
||||
nvd: lhk
|
||||
lsr: lhk
|
||||
rzs: qnr cmg lsr rsh
|
||||
frs: qnr lhk lsr
|
1261
aoc2023/day25/input.txt
Normal file
1261
aoc2023/day25/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
63
aoc2023/day25/main.go
Normal file
63
aoc2023/day25/main.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"iter"
|
||||
"strings"
|
||||
|
||||
aoc "go.sour.is/advent-of-code"
|
||||
)
|
||||
|
||||
// var log = aoc.Log
|
||||
|
||||
func main() { aoc.MustResult(aoc.Runner(run)) }
|
||||
|
||||
type result struct {
|
||||
valuePT1 int
|
||||
valuePT2 int
|
||||
}
|
||||
|
||||
func (r result) String() string { return fmt.Sprintf("%#v", r) }
|
||||
|
||||
func run(scan *bufio.Scanner) (*result, error) {
|
||||
g := aoc.Graph[string, int]()
|
||||
var root string
|
||||
|
||||
for scan.Scan() {
|
||||
line := scan.Text()
|
||||
v, lis, ok := strings.Cut(line, ": ")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if root == "" {
|
||||
root = v
|
||||
}
|
||||
|
||||
for _, l := range strings.Split(lis, " ") {
|
||||
g.AddEdge(v, l, 1)
|
||||
g.AddEdge(l, v, 1)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for i, v := range enumerate(g.BFS(root)) {
|
||||
fmt.Println(i, v)
|
||||
}
|
||||
|
||||
return &result{}, nil
|
||||
}
|
||||
|
||||
func enumerate[T any](vs iter.Seq[T]) iter.Seq2[int, T] {
|
||||
i := 0
|
||||
return func(yield func(int, T) bool) {
|
||||
for v := range vs {
|
||||
if !yield(i, v) {
|
||||
return
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
41
aoc2023/day25/main_test.go
Normal file
41
aoc2023/day25/main_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
//go:embed example.txt
|
||||
var example []byte
|
||||
|
||||
//go:embed input.txt
|
||||
var input []byte
|
||||
|
||||
func TestExample(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(example))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, 50)
|
||||
is.Equal(result.valuePT2, 0)
|
||||
}
|
||||
|
||||
func TestSolution(t *testing.T) {
|
||||
is := is.New(t)
|
||||
scan := bufio.NewScanner(bytes.NewReader(input))
|
||||
|
||||
result, err := run(scan)
|
||||
is.NoErr(err)
|
||||
|
||||
t.Log(result)
|
||||
is.Equal(result.valuePT1, 0)
|
||||
is.Equal(result.valuePT2, 0)
|
||||
}
|
Loading…
Reference in New Issue
Block a user