Discussion thread for day 1 of the Advent of Code - https://adventofcode.com/2023/day/1
Fairly fast first part to the question, I know there are faster methods such as cleanse and left() right() string functions... but it's 5am for me. So went with the reverse string option to find the last digit. Solved at 5:04am which is my fastest star for doing AoC so I was pleased with that.
My test for part two worked perfectly.. however in the example where it showed sixteen, this evaluated to six (ignoring the teen). So when I ran this on my data and got the wrong result, I thought aha, while sixteen works as it contains six, what happens when you see things like twelve so I would need to extend my lookup table. So after writing out loads of number then got to twenty and then released how am I going to deal with twenty vs twentyone - as I don't want twenty one to become 201... I decided to inspect my input file.
Great I thought no number > 9. However I didn't immediately spot things like eightwo. So after a bit of two and through started to write these out manually with oneight, twone, etc. But unlike @joshbennett who correctly did this programmatically, I made the mistake of missing some pairs. So it took about 40 mins to complete part 2!
Yeah! Figured it out in the end, those elves are such tricksters first thing on a Friday morning! 🤣
oooo, if someone came to me with data like this I would not be a happy chappy 😂 getting past the grumpyness and the urge to make everything a macro, sorted it pretty simply
I feel like I got lucky; the lookup gave me the right answer without any 'oneight' issues. I'll take the blessing on day 1, it will come back and bite me by day 5 😁
Alteryx wont let me upload images for some reason, but I abused regex to get me the first ( (\d) ) and last ( (\d)(?!.*\d) ) digit of the text.
Step 2 was a simple lookup for me, as mentioned I feel I got lucky on that one with no nasty lookups.
For such a small dataset, why would you not hard code it? Or simply challenging yourself
Part 2 took a while to get the point (just like the last year 😉)
Part 2 got me far too angry for day 1
IF REGEX_CountMatches([Input],'\d')>1 THEN
tonumber(REGEX_Replace([Input],'\D*(\d).*(\d)\D*','$1$2'))
ELSEIF REGEX_CountMatches([Input],'\d')=1 THEN
tonumber(REGEX_Replace([Input],'\D*(\d)\D*','$1$1'))
ELSE 0
ENDIF
My overlapping number replacement:
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(lowercase([Input]),'one','o1e'),'two','t2'),'three','t3e'),'four','4'),'five','5e'),'six','6'),'seven','7n'),'eight','e8'),'nine','9')
I don't care what you say about me, I hardcoded, ok??
I created a text library of the words and corresponding digit, as well as the double digits for the overlaps (cheeky elves!), I then simply used Find and Replace to create numbers from the words.
I then used the formula:
tonumber(left(REGEX_Replace([Config], "[^\d]", ""),1)+right(REGEX_Replace([Config], "[^\d]", ""),1))
This simply removed everything but the digits, and takes the first and last characters.
Nice start.
M.