|
@@ -43,11 +43,35 @@ func readInput(file string) []move {
|
|
|
return moves
|
|
|
}
|
|
|
|
|
|
+var actions map[string]int
|
|
|
+
|
|
|
+func init() {
|
|
|
+ actions = make(map[string]int)
|
|
|
+ actions["forward"] = 1
|
|
|
+ actions["down"] = 1
|
|
|
+ actions["up"] = -1
|
|
|
+}
|
|
|
+
|
|
|
+func part1(moves []move) int {
|
|
|
+ position := 0
|
|
|
+ depth := 0
|
|
|
+
|
|
|
+ for _, move := range moves {
|
|
|
+ if move.direction == "forward" {
|
|
|
+ position += move.steps * actions[move.direction]
|
|
|
+ } else {
|
|
|
+ depth += move.steps * actions[move.direction]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return position * depth
|
|
|
+}
|
|
|
+
|
|
|
func main() {
|
|
|
if len(os.Args) < 2 {
|
|
|
log.Fatal("No input file specified")
|
|
|
}
|
|
|
|
|
|
moves := readInput(os.Args[1])
|
|
|
- fmt.Println(moves)
|
|
|
+ fmt.Println("Part 1:", part1(moves))
|
|
|
}
|