-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02p2.odin
38 lines (31 loc) · 836 Bytes
/
02p2.odin
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
package main
import "core:fmt"
import "core:strconv"
import "core:strings"
D02P2 :: proc() {
input_string := #load("./inputs/02.txt", string)
lines := strings.split(input_string, "\n", context.temp_allocator)
depth_increase_count := parse_submarine_instructions(lines)
fmt.printfln("Product of final position: %v", depth_increase_count)
}
parse_submarine_instructions :: proc(input: []string) -> int {
pos := Coordinate{0, 0}
aim := 0
for instruc in input {
if instruc == "" {
continue
}
direction := strings.split(instruc, " ", context.temp_allocator)[0]
weight := strconv.atoi(strings.split(instruc, " ", context.temp_allocator)[1])
switch direction {
case "forward":
pos.x += weight
pos.y += aim * weight
case "up":
aim -= weight
case "down":
aim += weight
}
}
return pos.x * pos.y
}