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.
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.
Part 2 took me a while, I decided to brute force it all in a single Formula tool.
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.
The hardest is on day one right?!?
2 stars down, 48 to go!
My solution, did not enjoy the regex I had to build but yes!
Part 2 threw me for a loop! Ended up just inputting the possible overlappings in my lookup values, since there weren't that many possible combinations. Excited for tomorrow!
Was not expecting the misfits on day 1
And when I started to think of the myriad of combos of digits, I didn't want to go brute force with a find replace.
So, I went brute force with 9 formulae.
Won't be doing the midnight drop tonight because Shabbat. So a little catch up right off the bat.
Loving the use of regex in this one!! Seems my brain doesn't regex at midnight....
It's finally that time of the year to be stressed out by daily challenges again 😅
My 1st workflow was very redundant. So I remade it with a cool head.
And I tried to make it using Designer Cloud.
I can't reproduction my workflow in Designer Cloud because there is no first and last option at Summarize tool. So I adopted the @NicoleJ 's Idea(Data Creansing tool)
What can possibly go wrong with hard coding? If it works now it will always work...
Question 2 was brutal on my mind
Happy to be back at it for my third year participating in AOC using alteryx! I used reverse string here to avoid having to come up with complex regex or formulas to solve for instances of overlapping strings or single digits. Not going for tool golf here, just a straightforward solution I was able to build out quickly. Anyone else use reverse string to help with this one?
@phottovy our solutions were almost completely identical! I would understand if someone accused me of plagiarism
Really I would think this is something we should look into adding to the find/replace as an option!