mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-04-19 11:13:48 +01:00
Compare commits
No commits in common. "1c60c034e3040a939ae25babc6830161843c3bb1" and "df605fba1516f688c6a848931d687eabaf2c57b4" have entirely different histories.
1c60c034e3
...
df605fba15
@ -2,14 +2,14 @@ goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/onyx-and-iris/aoc2024/day-06
|
||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||
BenchmarkSolve-12 1 1787027305 ns/op
|
||||
BenchmarkSolve-12 1 1669661404 ns/op
|
||||
BenchmarkSolve-12 1 1702069604 ns/op
|
||||
BenchmarkSolve-12 1 1702577205 ns/op
|
||||
BenchmarkSolve-12 1 1708872905 ns/op
|
||||
BenchmarkSolve-12 1 1825434105 ns/op
|
||||
BenchmarkSolve-12 1 1667198605 ns/op
|
||||
BenchmarkSolve-12 1 1650618104 ns/op
|
||||
BenchmarkSolve-12 1 1726260907 ns/op
|
||||
BenchmarkSolve-12 1 1667980407 ns/op
|
||||
ok github.com/onyx-and-iris/aoc2024/day-06 17.133s
|
||||
BenchmarkSolve-12 1 1815042506 ns/op
|
||||
BenchmarkSolve-12 1 1670139306 ns/op
|
||||
BenchmarkSolve-12 1 1708459605 ns/op
|
||||
BenchmarkSolve-12 1 1687274507 ns/op
|
||||
BenchmarkSolve-12 1 1722070212 ns/op
|
||||
BenchmarkSolve-12 1 1728997012 ns/op
|
||||
BenchmarkSolve-12 1 1738883012 ns/op
|
||||
BenchmarkSolve-12 1 1686811712 ns/op
|
||||
BenchmarkSolve-12 1 1701938016 ns/op
|
||||
BenchmarkSolve-12 1 1701384522 ns/op
|
||||
ok github.com/onyx-and-iris/aoc2024/day-06 17.190s
|
||||
|
@ -2,5 +2,5 @@ goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/onyx-and-iris/aoc2024/day-06/internal/one
|
||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||
BenchmarkSolve-12 1000000000 0.006992 ns/op
|
||||
BenchmarkSolve-12 1000000000 0.007368 ns/op
|
||||
ok github.com/onyx-and-iris/aoc2024/day-06/internal/one 0.052s
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type graph struct {
|
||||
startPoint point
|
||||
data []string
|
||||
startPoint point
|
||||
}
|
||||
|
||||
func newGraph() *graph {
|
||||
|
@ -2,5 +2,5 @@ goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/onyx-and-iris/aoc2024/day-06/internal/two
|
||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||
BenchmarkSolve-12 1000000000 0.0000354 ns/op
|
||||
BenchmarkSolve-12 1000000000 0.0000547 ns/op
|
||||
ok github.com/onyx-and-iris/aoc2024/day-06/internal/two 0.006s
|
||||
|
@ -5,4 +5,5 @@ const (
|
||||
E
|
||||
S
|
||||
W
|
||||
obstacle
|
||||
)
|
||||
|
@ -7,12 +7,13 @@ import (
|
||||
)
|
||||
|
||||
type graph struct {
|
||||
startPoint point
|
||||
data []string
|
||||
startPoint point
|
||||
obstacles []point
|
||||
}
|
||||
|
||||
func newGraph(startPoint point, data []string) *graph {
|
||||
return &graph{startPoint: startPoint, data: data}
|
||||
func newGraph() *graph {
|
||||
return &graph{}
|
||||
}
|
||||
|
||||
func (g *graph) String() string {
|
||||
|
@ -24,7 +24,9 @@ func Solve(buf []byte) (int, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
g := newGraph(graph.startPoint, slices.Clone(graph.data))
|
||||
g := newGraph()
|
||||
g.startPoint = graph.startPoint
|
||||
g.data = slices.Clone(graph.data)
|
||||
g.data[loc.Y] = replaceAtIndex(g.data[loc.Y], 'O', loc.X)
|
||||
|
||||
p := g.startPoint
|
||||
@ -35,18 +37,19 @@ func Solve(buf []byte) (int, error) {
|
||||
p.y == 0 && p.direction == N ||
|
||||
p.y == len(g.data)-1 && p.direction == S ||
|
||||
p.x == len(g.data[p.y])-1 && p.direction == E) {
|
||||
_, ok := visited[p]
|
||||
if ok {
|
||||
log.Tracef("loop: \n%s\n", g.trace(visited))
|
||||
isLoop <- true
|
||||
return
|
||||
}
|
||||
visited[p] = struct{}{}
|
||||
|
||||
p = nextPoint(p)
|
||||
if g.valueAt(p.x, p.y) == '#' || g.valueAt(p.x, p.y) == 'O' {
|
||||
p.recalibrate()
|
||||
}
|
||||
|
||||
_, ok := visited[p]
|
||||
if !ok {
|
||||
visited[p] = struct{}{}
|
||||
} else {
|
||||
log.Tracef("loop: \n%s\n", g.trace(visited))
|
||||
isLoop <- true
|
||||
return
|
||||
}
|
||||
}
|
||||
isLoop <- false
|
||||
}()
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func parseLines(r io.Reader) (*graph, error) {
|
||||
graph := &graph{}
|
||||
graph := newGraph()
|
||||
|
||||
count := 0
|
||||
scanner := bufio.NewScanner(r)
|
||||
@ -18,6 +18,13 @@ func parseLines(r io.Reader) (*graph, error) {
|
||||
graph.startPoint = point{indx, count, N}
|
||||
}
|
||||
graph.data = append(graph.data, scanner.Text())
|
||||
|
||||
for i, r := range line {
|
||||
if r == '#' {
|
||||
graph.obstacles = append(graph.obstacles, point{i, count, obstacle})
|
||||
}
|
||||
}
|
||||
|
||||
count++
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user