AnnouncementsFunnyVideosMusicAncapsTechnologyEconomicsPrivacyGIFSCringeAnarchyFilmPicsThemesIdeas4MatrixAskMatrixHelpTop Subs
3

--- Day 7: Bridge Repair ---

The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side?

When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed.

You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and stole all the operators from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input).

For example:

190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20

Each line represents a single equation. The test value appears before the colon on each line; it is your job to determine whether the remaining numbers can be combined with operators to produce the test value.

Operators are always evaluated left-to-right, not according to precedence rules. Furthermore, numbers in the equations cannot be rearranged. Glancing into the jungle, you can see elephants holding two different types of operators: add (+) and multiply (*).

Only three of the above equations can be made true by inserting operators:

190: 10 19 has only one position that accepts an operator: between 10 and 19. Choosing + would give 29, but choosing * would give the test value (10 * 19 = 190).
3267: 81 40 27 has two positions for operators. Of the four possible configurations of the operators, two cause the right side to match the test value: 81 + 40 * 27 and 81 * 40 + 27 both equal 3267 (when evaluated left-to-right)!
292: 11 6 16 20 can be solved in exactly one way: 11 + 6 * 16 + 20.

The engineers just need the total calibration result, which is the sum of the test values from just the equations that could possibly be true. In the above example, the sum of the test values for the three equations listed above is 3749.

Determine which equations could possibly be true. What is their total calibration result?

Comment preview

Input:

  • 190: 10 19
  • 3267: 81 40 27
  • 83: 17 5
  • 156: 15 6
  • 7290: 6 8 6 15
  • 161011: 16 10 13
  • 192: 17 8 14
  • 21037: 9 7 18 13
  • 292: 11 6 16 20

Output:


my_Solution:


What i learned: >! NOTHING! This was a straight copy/pasta solution with chatGPT. So thats nice, cuz i got things to implement today! Breaking down the code however, it seems like it parses the string input into numbers (extra step but one that we did a few problems ago). this is put into a dictionary of target number and then the source numbers as a list in the kvp. It then generates all possible combinations of operators, which is an O(2n) operation so for larger sequence of numbers or more operators would make this unwieldy. I would approach that using either pruning combinations (Backtracking), a heuristics-based approach or something. Klep would be of no help here, :-(. Finally, it then brute forces the combination from its list of possible combinations. !<

[-]x0x7
0(+0|0)

I learned even less than you. I OCR'd your code, and fed it into an AI to translate to JS.

2664460013123 <- That's from the major input. I guess I'm tackling part 2 fresh though.

Part 2 was easy enough: https://files.catbox.moe/apzwr5.zip

[-]Aurelius0(+0|0)

As someone who's worked on bridge parts the solution is either blowtorches or grinding wheels.

For real though I dig these threads

[-]x0x7
0(+0|0)

Thanks man for keeping these going. My life got pulling in too many directions.