-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
50 lines (44 loc) · 888 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bufio"
"io"
aoc "github.com/teivah/advent-of-code"
)
func fs1(input io.Reader) int {
scanner := bufio.NewScanner(input)
pos := aoc.Position{}
for scanner.Scan() {
line := scanner.Text()
del := aoc.NewDelimiter(line, " ")
n := del.GetInt(1)
switch del.GetString(0) {
case "forward":
pos = pos.Move(aoc.Right, n)
case "down":
pos = pos.Move(aoc.Down, n)
case "up":
pos = pos.Move(aoc.Up, n)
}
}
return pos.Row * pos.Col
}
func fs2(input io.Reader) int {
scanner := bufio.NewScanner(input)
pos := aoc.Position{}
aim := 0
for scanner.Scan() {
line := scanner.Text()
del := aoc.NewDelimiter(line, " ")
n := del.GetInt(1)
switch del.GetString(0) {
case "forward":
pos = pos.Move(aoc.Right, n)
pos = pos.Move(aoc.Down, aim*n)
case "down":
aim += n
case "up":
aim -= n
}
}
return pos.Row * pos.Col
}