start 2024, 2024-01

This commit is contained in:
2025-11-25 11:22:03 -08:00
parent ef109439e6
commit ca26da6b3b
56 changed files with 20577 additions and 22 deletions

41
2024/01.odin Normal file
View File

@@ -0,0 +1,41 @@
package aoc
import "core:math"
import "core:fmt"
import "core:sort"
import "core:strconv"
import "core:strings"
day01 :: proc() {
input := slurp_lines("input/01")
defer delete(input)
left := make([dynamic]int, 0, len(input))
right := make([dynamic]int, 0, len(input))
for line in input {
sp := strings.split(line, " ")
a, _ := strconv.parse_int(sp[0])
b, _ := strconv.parse_int(sp[1])
append(&left, a)
append(&right, b)
}
sort.quick_sort(left[:])
sort.quick_sort(right[:])
p1: int
for i in 0..<len(left) {
p1 += math.abs(left[i] - right[i])
}
fmt.println(p1)
count: map[int]int
for r in right {
count[r] += 1
}
p2: int
for l in left {
p2 += l * count[l]
}
fmt.println(p2)
}