Discussion thread for day 1 of the Advent of Code - https://adventofcode.com/2023/day/1
Well now that was just a dirty trick to pull with part 2. But we're off!! #WestCoastBestCoast 😁
Part 1 was pretty straightforward - big fan of the Data Cleanse for making that one super easy to ditch a bunch of letters.
Part 2 seemed like it would be a breeze... until I was wrong with my first answer, and looked at the first few lines of my puzzle code code, and saw "oneight". NOT COOL. So I had to add some extra lookup values to combine numbers that start/end with the same letter (oneight, eightwo, etc.) Feels a bit brute force in the end (you could get in a real pickle if you started going down the infinite loop of oneightwoneightwoneightwo... where does it end?!?) but luckily the elves weren't that mean. Today.
Cheers to the most wonderful time of the year!!
My solution.
This year is not bad start(Last year I forgot the start time.I started one hour lator).
Part 1 gave me a false sense of confidence. Used REGEX Replace to remove any non-digit characters and then concatenate the first and last digits.
Part 2 tripped me up a bit - had a hard time figuring out the best way to isolate the very last word/digit in the string since phrases like "oneight" could hypothetically match either a 1 or an 8, but which it needed to match depended on where it was in the string. I like the brute force @NicoleJ - sometimes that's the fastest way! I ended up using the Regex tool inelegantly to parse the first and last value to handle for this, but it took me quite awhile to figure out.
first value regex pattern: "([1-9]|(?:one|two|three|four|five|six|seven|eight|nine)).*"
last value regex pattern: ".*([1-9]|(?:one|two|three|four|five|six|seven|eight|nine))"
Great warm up overall!
I joined.
Everybody so fast!
Interesting!
Cost me quite sometime, but managed to solve it.
Didn't want to hard-code the overlapping number string replacements.