@@ -43,11 +43,24 @@ func loop(
43
43
return
44
44
}
45
45
46
- loop (r .turnClockwise (), i , set )
47
- loop (r .turnCounterClockwise (), i , set )
48
- fwd , err := r .forward (i .m )
46
+ newR , err := r .forward (i .m )
49
47
if err == nil {
50
- loop (fwd , i , set )
48
+ loop (newR , i , set )
49
+ }
50
+
51
+ newR , err = r .turnClockwise ().forward (i .m )
52
+ if err == nil {
53
+ loop (newR , i , set )
54
+ }
55
+
56
+ newR , err = r .turnClockwise ().turnClockwise ().forward (i .m )
57
+ if err == nil {
58
+ loop (newR , i , set )
59
+ }
60
+
61
+ newR , err = r .turnCounterClockwise ().forward (i .m )
62
+ if err == nil {
63
+ loop (newR , i , set )
51
64
}
52
65
53
66
return
@@ -57,27 +70,17 @@ func lowestSoFar(
57
70
i parsedInput ,
58
71
set visitedSet ,
59
72
) int {
60
- lowest := 0
61
- for _ , n := range set [i .e .Y ][i .e .X ] {
62
- if lowest == 0 || n < lowest {
63
- lowest = n
64
- }
65
- }
66
- return lowest
73
+ return set [i .e .Y ][i .e .X ]
67
74
}
68
75
69
76
func initializeVisitedSet (
70
77
i parsedInput ,
71
78
) visitedSet {
72
79
set := make (visitedSet )
73
80
for y , line := range i .m {
74
- set [y ] = make (map [intX ]map [ intDirection ] intScore )
81
+ set [y ] = make (map [intX ]intScore )
75
82
for x , _ := range line {
76
- set [y ][x ] = make (map [intDirection ]intScore )
77
- set [y ][x ][North ] = math .MaxInt
78
- set [y ][x ][South ] = math .MaxInt
79
- set [y ][x ][West ] = math .MaxInt
80
- set [y ][x ][East ] = math .MaxInt
83
+ set [y ][x ] = math .MaxInt
81
84
}
82
85
}
83
86
return set
0 commit comments