mirror of
https://github.com/fredrikr79/advent_of_code.git
synced 2026-07-08 04:05:20 +02:00
2025/8/odin: wip
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package day_8
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
|
||||
input :: cast(string)#load("../ex_input")
|
||||
|
||||
Pos :: [3]int
|
||||
|
||||
parse :: proc(input: string) -> (res: []Pos, ok: bool) {
|
||||
data: [dynamic]Pos
|
||||
for line in strings.split_lines(strings.trim_space(input)) {
|
||||
raw_pos := strings.split(line, ",")
|
||||
pos: Pos
|
||||
for &v, i in pos {
|
||||
v = strconv.parse_int(raw_pos[i]) or_return
|
||||
}
|
||||
append(&data, pos)
|
||||
}
|
||||
return data[:], true
|
||||
}
|
||||
|
||||
solve_1 :: proc(data: []Pos) -> int {
|
||||
edges: map[Pos]Pos
|
||||
for p1 in data {
|
||||
for p2 in data {
|
||||
if p1 == p2 do continue
|
||||
if p1 not_in edges do edges[p1] = p2
|
||||
}
|
||||
}
|
||||
fmt.println(edges)
|
||||
return 0
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
data, ok := parse(input)
|
||||
if !ok do fmt.eprintln("failed to parse")
|
||||
fmt.println(solve_1(data))
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
162,817,812
|
||||
57,618,57
|
||||
906,360,560
|
||||
592,479,940
|
||||
352,342,300
|
||||
466,668,158
|
||||
542,29,236
|
||||
431,825,988
|
||||
739,650,466
|
||||
52,470,668
|
||||
216,146,977
|
||||
819,987,18
|
||||
117,168,530
|
||||
805,96,715
|
||||
346,949,466
|
||||
970,615,88
|
||||
941,993,340
|
||||
862,61,35
|
||||
984,92,344
|
||||
425,690,689
|
||||
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:slice"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
|
||||
PUZZLE_INPUT: string : #load("example")
|
||||
|
||||
Pos :: distinct struct {
|
||||
x, y, z: int,
|
||||
}
|
||||
|
||||
parse :: proc(input: string) -> (output: []Pos) {
|
||||
lines := strings.split_lines(input)
|
||||
output = make([]Pos, len(lines))
|
||||
digits := make([dynamic]int, context.temp_allocator)
|
||||
defer free_all(context.temp_allocator)
|
||||
nums: [3]int
|
||||
for line, row in lines {
|
||||
for num, i in strings.split(line, ",") do nums[i], _ = strconv.parse_int(num)
|
||||
output[row] = Pos{nums[0], nums[1], nums[2]}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
solve :: proc(data: []Pos) -> (output: int) {
|
||||
context.allocator = context.temp_allocator
|
||||
|
||||
distances := make([]int, len(data) * len(data))
|
||||
for p1, row in data {
|
||||
for p2, col in data {
|
||||
d := Pos{p1.x - p2.x, p1.y - p2.y, p1.z - p2.z}
|
||||
distance := d.x * d.x + d.y * d.y + d.z * d.z
|
||||
distances[row * len(data) + col] = distance == 0 ? 1e9 : distance // TODO: triangle
|
||||
}
|
||||
}
|
||||
fmt.println(distances)
|
||||
shortest := make([]int, len(data))
|
||||
for i in 0 ..< len(data) {
|
||||
row := distances[i * len(data):(i + 1) * len(data)]
|
||||
shortest[i] = slice.min_index(row)
|
||||
}
|
||||
fmt.println(shortest)
|
||||
return
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
fmt.println(solve(parse(PUZZLE_INPUT)))
|
||||
}
|
||||
Reference in New Issue
Block a user