-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d4068
commit 8fd9355
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Part 1: 35 | ||
Part 2: 46 |