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