Skip to content

Commit

Permalink
Jackson Day 9, Part 1, Part 2 (#41)
Browse files Browse the repository at this point in the history
* Jackson Day 8, Part 1, Part 2

* Jackson Day 9, Part 1, Part 2

* Remove part-2 split

* Remove mutable diff array
  • Loading branch information
jacksonmowry authored Dec 9, 2023
1 parent f2b17c9 commit af8de0d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 2023/09/jacksonmowry.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module main

import os
import arrays

fn main() {
mut forward := 0
mut backward := 0

lines := os.read_lines('mirage_maintenance.input')!.map(it.split(' ').map(it.int()))

for line in lines {
front, back := next_value(line)
backward += front
forward += back
}
println('Part 1: ${forward}')
println('Part 2: ${backward}')
}

fn next_value(input []int) (int, int) {
if input.all(it == 0) {
return 0, 0
}
diffs := arrays.flat_map_indexed[int, int](input, fn [input] (i int, e int) []int {
return [input[i + 1] or { return [] } - input[i]]
})
front, back := next_value(diffs)
return input.first() - front, input.last() + back
}
3 changes: 3 additions & 0 deletions 2023/09/mirage_maintenance.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
2 changes: 2 additions & 0 deletions known_outputs/2023/09/jacksonmowry.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Part 1: 114
Part 2: 2

0 comments on commit af8de0d

Please sign in to comment.