1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { LoadInput } from "../common.ts";
- import { ParseInput, MapSeed, isSeedMapArray } from "./5_common.ts"
- const tests = [
- "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",
- ];
- const input = await LoadInput(5);
- // Parse the input
- const maps = ParseInput(input);
- // Map the seeds
- const seeds = maps.Seeds.map((seed) => MapSeed(seed, maps));
- // Get the output
- let closestLocationID = Number.MAX_SAFE_INTEGER;
- if (isSeedMapArray(seeds)) {
- seeds.forEach((seed) => {
- if (seed.LocationID < closestLocationID) { closestLocationID = seed.LocationID; }
- });
- }
- console.log(`The lowest location ID found is: ${closestLocationID}`);
|