-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13p2.odin
54 lines (46 loc) · 1 KB
/
13p2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import "core:fmt"
import "core:strings"
D13P2 :: proc() {
input_string := #load("./inputs/13.txt", string)
lines := strings.split(input_string, "\n", context.temp_allocator)
visible_dots := fold_transparent_paper(lines, true)
fmt.printfln("Total visible dots: %v", visible_dots)
}
draw_dots :: proc(dots: [dynamic]Vec2) {
min_x, min_y, max_x, max_y := find_bounds(dots)
for y := min_y; y <= max_y; y += 1 {
for x := min_x; x <= max_x; x += 1 {
found := false
for dot in dots {
if dot.x == x && dot.y == y {
fmt.print("#")
found = true
}
}
if !found {
fmt.print(".")
}
}
fmt.print("\n")
}
}
find_bounds :: proc(dots: [dynamic]Vec2) -> (int, int, int, int) {
min_x, min_y := 1000000, 1000000
max_x, max_y := -1000000, -1000000
for dot in dots {
if dot.x < min_x {
min_x = dot.x
}
if dot.y < min_y {
min_y = dot.y
}
if dot.x > max_x {
max_x = dot.x
}
if dot.y > max_y {
max_y = dot.y
}
}
return min_x, min_y, max_x, max_y
}