Skip to content

Commit

Permalink
Day 5, Part 1, Part 2 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonmowry authored Dec 5, 2023
1 parent b8d4068 commit 8fd9355
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
48 changes: 48 additions & 0 deletions 2023/05/jacksonmowry.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module main

import os
import arrays
import math

fn main() {
input := os.read_file('seed_map.input')!
.split('\n\n')
.map(it.split_into_lines().map(it.trim_space()))
mut seeds := (input[0][0].split(': ')[1]).split(' ').map(it.i64())
for m in 1 .. 8 {
maps := input[m][1..].map(it.split(' ').map(it.i64()))
for i := 0; i < seeds.len; i++ {
for line in maps {
if seeds[i] >= line[1] && seeds[i] <= line[1] + line[2] {
seeds[i] = line[0] + (seeds[i] - line[1])
break
}
}
}
}

println('Part 1: ${arrays.min(seeds)!}')

mut seeds_2 := (input[0][0].split(': ')[1]).split(' ').map(it.u64())
mut part_2_min := max_u64
mut maps := [][][]u64{}
for i in 1 .. 8 {
maps << input[i][1..].map(it.split(' ').map(it.u64()))
}
for i := 0; i < seeds_2.len - 1; i += 2 {
end := seeds_2[i] + seeds_2[i + 1] - 1
for start := seeds_2[i]; start <= end; start++ {
mut copy := start
for mapx in maps {
for line in mapx {
if copy >= line[1] && copy < line[1] + line[2] {
copy = line[0] + copy - line[1]
break
}
}
}
part_2_min = math.min(part_2_min, copy)
}
}
println('Part 2: ${part_2_min}')
}
33 changes: 33 additions & 0 deletions 2023/05/seed_map.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
seeds: 79 14 55 13

seed-to-soil map:
50 98 2
52 50 48

soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15

fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4

water-to-light map:
88 18 7
18 25 70

light-to-temperature map:
45 77 23
81 45 19
68 64 13

temperature-to-humidity map:
0 69 1
1 0 69

humidity-to-location map:
60 56 37
56 93 4
2 changes: 2 additions & 0 deletions known_outputs/2023/05/jacksonmowry.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Part 1: 35
Part 2: 46

0 comments on commit 8fd9355

Please sign in to comment.