Skip to content

Commit 0e49909

Browse files
committed
Solution for GCAQQ02
1 parent 72f3210 commit 0e49909

File tree

1 file changed

+39
-0
lines changed
  • gcaqq02_penguin_coding_2_ice_garden_walk

1 file changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
const input = `^v>>>vvvv<>><>>>>>><>^v>vvv<<>>vv<><>^>^^^>>>^>vv<><<>^<v^>^v<>>>^^>v^<^^^<^^><^>>>v^>^v<>v^<^v>>^<v>^<^>>><vv>v>>>v<><><v>v>v<<^v<<><>^<<<vvvv<^><v^<<^v><>>><^^<><<^v<v^<>><>^vv<><^<^^<vv<<^v<>>^<>>>>>>v^>>>>><^v><>v^<<^v^>^^^<^<v<>^v<<v>^^^vv>>^>>^^<v^^<v<^v<>>><<>>>>>>>>>>>>>^^<^^<^vv>>><^^v<^v>><v>>^vv>v^>>v>^><>vv<>>^v<<^v>>v^^vvv^^^^vv<<<<<<<<<<>vvvv^<^^^v<<^v^vv^^<<<<<<<<<v<v<<>^^v^v<<^^<vv>><><^v<<>^^<<<>>>>>^<v>vv>^v>>v<`
9+
10+
type point struct {
11+
x, y int
12+
}
13+
14+
func main() {
15+
count := 0
16+
curr := point{0, 0}
17+
visited := map[point]bool{curr: true}
18+
19+
for _, c := range input {
20+
switch c {
21+
case '^':
22+
curr.y++
23+
case 'v':
24+
curr.y--
25+
case '<':
26+
curr.x--
27+
case '>':
28+
curr.x++
29+
default:
30+
fmt.Println("illegal input: ", c)
31+
os.Exit(1)
32+
}
33+
count++
34+
visited[curr] = true
35+
}
36+
37+
fmt.Printf("curr = %v |visited| = %d count = %d\n", curr, len(visited), count)
38+
fmt.Println(len(input))
39+
}

0 commit comments

Comments
 (0)