5_1.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { LoadInput } from "../common.ts";
  2. import { ParseInput, MapSeed, isSeedMapArray } from "./5_common.ts"
  3. const tests = [
  4. "seeds: 79 14 55 13",
  5. "",
  6. "seed-to-soil map:",
  7. "50 98 2",
  8. "52 50 48",
  9. "",
  10. "soil-to-fertilizer map:",
  11. "0 15 37",
  12. "37 52 2",
  13. "39 0 15",
  14. "",
  15. "fertilizer-to-water map:",
  16. "49 53 8",
  17. "0 11 42",
  18. "42 0 7",
  19. "57 7 4",
  20. "",
  21. "water-to-light map:",
  22. "88 18 7",
  23. "18 25 70",
  24. "",
  25. "light-to-temperature map:",
  26. "45 77 23",
  27. "81 45 19",
  28. "68 64 13",
  29. "",
  30. "temperature-to-humidity map:",
  31. "0 69 1",
  32. "1 0 69",
  33. "",
  34. "humidity-to-location map:",
  35. "60 56 37",
  36. "56 93 4",
  37. ];
  38. const input = await LoadInput(5);
  39. // Parse the input
  40. const maps = ParseInput(input);
  41. // Map the seeds
  42. const seeds = maps.Seeds.map((seed) => MapSeed(seed, maps));
  43. // Get the output
  44. let closestLocationID = Number.MAX_SAFE_INTEGER;
  45. if (isSeedMapArray(seeds)) {
  46. seeds.forEach((seed) => {
  47. if (seed.LocationID < closestLocationID) { closestLocationID = seed.LocationID; }
  48. });
  49. }
  50. console.log(`The lowest location ID found is: ${closestLocationID}`);