Compare commits

...

2 Commits

Author SHA1 Message Date
7b500eca53 Start Day 02 2026-02-11 19:09:49 -05:00
daafaf45f1 Fix Day 1 2026-02-11 19:09:32 -05:00
8 changed files with 4796 additions and 13 deletions

2
Brewfile Normal file
View File

@@ -0,0 +1,2 @@
brew "odin"
# brew "ols"

View File

@@ -1,6 +0,0 @@
1
10
1
200

View File

@@ -4,6 +4,7 @@ import "core:fmt"
import "core:os" import "core:os"
import "core:math" import "core:math"
import "core:strconv" import "core:strconv"
import "core:slice/heap"
scan_to_next :: proc(data: []byte, delim: byte, start_from: int) -> int { scan_to_next :: proc(data: []byte, delim: byte, start_from: int) -> int {
for idx := start_from; idx < len(data); idx += 1 { for idx := start_from; idx < len(data); idx += 1 {
@@ -114,7 +115,7 @@ main :: proc() {
fh, errno := os.open(os.args[1]) fh, errno := os.open(os.args[1])
if errno != os.ERROR_NONE { if errno != os.ERROR_NONE {
fmt.printf("Cannot open %s: %s\n", os.args[1], os.get_last_error_string()) fmt.printf("Cannot open %s: %s\n", os.args[1], os.get_last_error_string())
os.exit(int(errno)) os.exit(-1)
} }
defer os.close(fh) defer os.close(fh)
content, ok := os.read_entire_file_from_handle(fh) content, ok := os.read_entire_file_from_handle(fh)
@@ -124,10 +125,17 @@ main :: proc() {
} }
lines := split_lines(content, '\n') lines := split_lines(content, '\n')
total := 0 total := 0
max := 0 mh := make([dynamic]int, context.temp_allocator)
defer delete(mh)
comparator :: proc(a, b: int) -> bool {
return a < b
}
heap.make(mh[:], comparator)
for line, idx in lines { for line, idx in lines {
if len(line) == 0 { if len(line) == 0 {
max = math.max(max, total) append(&mh, total)
heap.push(mh[:], comparator)
total = 0 total = 0
} else { } else {
x: int x: int
@@ -140,6 +148,13 @@ main :: proc() {
} }
} }
} }
max = math.max(total, max) append(&mh, total)
fmt.printf("Largest grouping: %d\n", max) heap.make(mh[:], comparator)
total = 0
fmt.printf("Largest single value: %d\n", mh[0])
for _ in 0..<3 {
total += mh[0]
heap.pop(mh[:], comparator)
}
fmt.printf("Sum of three largest: %d\n", total)
} }

2249
odin/day01/input.txt Normal file

File diff suppressed because it is too large Load Diff

14
odin/day01/test.txt Normal file
View File

@@ -0,0 +1,14 @@
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000

View File

@@ -37,6 +37,15 @@ determine_score :: proc(friendly: Move, enemy: Move) -> int {
return result + int(friendly) return result + int(friendly)
} }
determine_score_alt :: proc(friendly: Move, outcome: Move) -> int {
// X = lose round
// Y = draw round
// Z = win round
// 3 defeats 2, 2 defeats 1, 1 defeats 3
// If w := enemy input and v := friendly input, then w = (v - 1) % 2 is a defeat
return 0
}
main :: proc () { main :: proc () {
init() init()
if len(os.args) < 2 { if len(os.args) < 2 {

2500
odin/day02/input.txt Normal file

File diff suppressed because it is too large Load Diff