Compare commits
2 Commits
73aefb8c9c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b500eca53 | |||
| daafaf45f1 |
@@ -1,6 +0,0 @@
|
||||
1
|
||||
10
|
||||
1
|
||||
|
||||
|
||||
200
|
||||
@@ -4,6 +4,7 @@ import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:math"
|
||||
import "core:strconv"
|
||||
import "core:slice/heap"
|
||||
|
||||
scan_to_next :: proc(data: []byte, delim: byte, start_from: int) -> int {
|
||||
for idx := start_from; idx < len(data); idx += 1 {
|
||||
@@ -114,7 +115,7 @@ main :: proc() {
|
||||
fh, errno := os.open(os.args[1])
|
||||
if errno != os.ERROR_NONE {
|
||||
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)
|
||||
content, ok := os.read_entire_file_from_handle(fh)
|
||||
@@ -124,10 +125,17 @@ main :: proc() {
|
||||
}
|
||||
lines := split_lines(content, '\n')
|
||||
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 {
|
||||
if len(line) == 0 {
|
||||
max = math.max(max, total)
|
||||
append(&mh, total)
|
||||
heap.push(mh[:], comparator)
|
||||
total = 0
|
||||
} else {
|
||||
x: int
|
||||
@@ -140,6 +148,13 @@ main :: proc() {
|
||||
}
|
||||
}
|
||||
}
|
||||
max = math.max(total, max)
|
||||
fmt.printf("Largest grouping: %d\n", max)
|
||||
}
|
||||
append(&mh, total)
|
||||
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
2249
odin/day01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
14
odin/day01/test.txt
Normal file
14
odin/day01/test.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
||||
@@ -37,6 +37,15 @@ determine_score :: proc(friendly: Move, enemy: Move) -> int {
|
||||
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 () {
|
||||
init()
|
||||
if len(os.args) < 2 {
|
||||
@@ -92,4 +101,4 @@ main :: proc () {
|
||||
}
|
||||
delete(rune_move);
|
||||
fmt.printf("Your score is: %d\n", total_score)
|
||||
}
|
||||
}
|
||||
|
||||
2500
odin/day02/input.txt
Normal file
2500
odin/day02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user