3_1.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { LoadInput } from "../common.ts";
  2. import { BuildSchematicsMap, ParseSchematics, ValidateEngineParts } from "./3_common.ts";
  3. const tests = [
  4. "467..114..",
  5. "...*......",
  6. "..35..633.",
  7. "......#...",
  8. "617*......",
  9. ".....+.58.",
  10. "..592.....",
  11. "......755.",
  12. "...$.*....",
  13. ".664.598..",
  14. ];
  15. /**
  16. * Test case from /u/i_have_no_biscuits
  17. * @see https://www.reddit.com/r/adventofcode/comments/189q9wv/2023_day_3_another_sample_grid_to_use/
  18. */
  19. const tests_reddit = [
  20. "12.......*..",
  21. "+.........34",
  22. ".......-12..",
  23. "..78........",
  24. "..*....60...",
  25. "78..........",
  26. ".......23...",
  27. "....90*12...",
  28. "............",
  29. "2.2......12.",
  30. ".*.........*",
  31. "1.1.......56",
  32. ];
  33. const input = await LoadInput(3);
  34. // Build the find
  35. const schematics = BuildSchematicsMap(input);
  36. // Find all possible parts
  37. let engineParts = ParseSchematics(schematics);
  38. // Validate those parts
  39. engineParts = ValidateEngineParts(engineParts, schematics);
  40. // Get our output
  41. const sumOfPartNumbers = engineParts.reduce((accumulator, part) => accumulator += part.PartNumber, 0);
  42. console.log(`The sum of part numbers is: ${sumOfPartNumbers}`);