-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (37 loc) · 771 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
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/fbegyn/aoc2021/go/helpers"
)
func main() {
file := os.Args[1]
commands := make(chan string)
go helpers.StreamLines(file, commands)
x1, depth1 := 0, 0
x, depth, aim := 0, 0, 0
for command := range commands {
split := strings.Split(command, " ")
operation, operandStr := split[0], split[1]
operand, err := strconv.Atoi(operandStr)
if err != nil {
panic(err)
}
switch operation {
case "forward":
x1 += operand
x += operand
depth += aim * operand
case "up":
depth1 -= operand
aim -= operand
case "down":
depth1 += operand
aim += operand
}
}
fmt.Printf("Solution for part 1: %d\n", depth1*x1)
fmt.Printf("Solution for part 2: %d\n", depth*x)
}