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