REMEMBER!
It is VERY important NOT to write any public spoilers
ALWAYS keep spoiler stuff hidden inside one of these
Summary
This text will be hidden
which you can obtain by clicking on the + icon and then selecting Hide Details
Good luck
FYI one of the features of Advent of Code is that we all get given different inputs so our answers will be different.
The examples are all the same but each of us gets different inputs for us to solve
First I standardized the number of digits between the start of the range and the end. Given that the combination of digits is repeated twice, the number of digits MUST be even. Thus, I can disqualify any ranges like 321-597 because the digits are odd. Ranges like 321-1597 can be turned in to 1000-1597 without losing possible numbers, and likewise 3210-15976 can become 3210-9999. These were the procedures I followed to set the variable “standardized number lengths”.
Next, I MAPPED over the data, determining what IDs were invalid. Here’s an example of how I did it. Take the range 123456-125789 - first I determine that the digits 1 and 2 at the start are required. Then, I take the third and final digit (4-6 are copies of 1-3) and take all of the possible values: 0-9. Adding each of these to 120, I get 120120,121121,122122, etc. Finally, I remove the values not in the original range, i.e. 120120 is less than 123456. At last, flatten and sum!
could someone please explain this? I have been looking at this for over an hour and wasted all of my free time today trying to figure out what they are asking.
Let’s say the range of numbers we are working with is 10-25. We need to find all numbers that are invalid IDs. Invalid IDs repeat the same string of numbers twice, exactly twice, and without any extra digits. This is best explained with some examples:
The number 12124 is not invalid because, even as it repeats 12 twice, it also has an additional 4.
The number 121212 is not invalid because it repeats 12 more than twice.
The number 18351835is invalid because it repeats 1835 twice; this is the simple case.
The number 12121212is invalid because it repeats 1212 twice, even as it repeats 12 four times.
Back to our range 10-25, we need to find all invalid numbers in that range. In this case, 11 is invalid because it repeats 1 twice and 22 is invalid because it repeats 2 twice. Finally, to get your puzzle answer, add all the values up - in my case, 33.
I was initially going to check every number in the range to see if it’s invalid, but then I realized I could just check if the possible invalid values are within the range. I also realized I have to make sure that the range starts on an even number of digits, so if it had an odd number of digits, I just set it to next number with an even number of digits (which happens to just be 10^(len(num)) ).