chore: add day25 part 1
Some checks failed
Go Bump / bump (push) Failing after 6s
Go Test / build (push) Failing after 45s

This commit is contained in:
xuu 2024-11-20 09:07:01 -07:00
parent e046a6c06d
commit 0d652660f1
Signed by: xuu
GPG Key ID: 8B3B0604F164E04F
5 changed files with 1380 additions and 2 deletions

13
aoc2023/day25/example.txt Normal file
View 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

File diff suppressed because it is too large Load Diff

63
aoc2023/day25/main.go Normal file
View 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++
}
}
}

View 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)
}

View File

@ -199,10 +199,10 @@ func (g *graph[V, W]) AddEdge(from, to V, w W) {
return return
} }
if _, ok := (*g)[from]; !ok { if _, ok := (*g)[from]; !ok {
return g.AddVertex(from, from)
} }
if _, ok := (*g)[to]; !ok { if _, ok := (*g)[to]; !ok {
return g.AddVertex(to, to)
} }
(*g)[from].Edges = append((*g)[from].Edges, edge[V, W]{(*g)[to], w}) (*g)[from].Edges = append((*g)[from].Edges, edge[V, W]{(*g)[to], w})