Discussion thread for day 4 of the Advent of Code - https://adventofcode.com/2024/day/4
Most fun and head scratching one yet!
Never expected a use case like this in Alteryx. Tricky one to solve the word search diagonally. Had to take a hint for that bit.
Actually really enjoyed this one, I wasted a whole hour trouble shooting unnecessarily, I think my second answer to part 2 was mistyped into the website the first time I got it... As after a thorough troubleshoot I still couldn't find anything wrong with my solution, tried the same value I was getting consistently and voila.... Always fun to see what your actual input/solutions look like with these ones! (after the stars have been secured of course...)
Went with generating the row/col of each target letter, for each direction, for each possible starting letter to find the XMASs, then for each A as midpoint, what are the 4 corners, are they M or S, and then finally, are my matches conforming to the MAS diagonals logic.
Change the extension of my xml file to .twb to take a gander at the tableau output. Not insightful, but cool to see.
Well this one kicked my butt 😥 but I learned a lot! I was good up until the diagonal matches. I remember a puzzle with diagonal patterns from last year's AoC and I never got through it. Thankfully, everyone here is way smarter than me and posted solutions that were easy to follow so I could learn some new tricks with diagonal patterns 😉.
And a huge thank you to @CoG for having a solution that was so easy to follow that I was able to essentially repeat it (and understand why it worked) and live to see another day of AoC!
In a true act of self-hatred, I saw a couple of people mention RegEx in the WhatsApp discussion group and it made me think... surely this could be done in a single Formula expression? A bit of trial and error later and I present to you one of the most disgusting things created by mankind. 1473 & 765 characters respectively.
REGEX_CountMatches([DownloadData], '(?=XMAS|SAMX)') + REGEX_CountMatches([DownloadData], '(?=X.{'+ToString(FindString([DownloadData], ' '))+'}M.{'+ToString(FindString([DownloadData], ' '))+'}A.{'+ToString(FindString([DownloadData], ' '))+'}S)') + REGEX_CountMatches([DownloadData], '(?=S.{'+ToString(FindString([DownloadData], ' '))+'}A.{'+ToString(FindString([DownloadData], ' '))+'}M.{'+ToString(FindString([DownloadData], ' '))+'}X)') + REGEX_CountMatches([DownloadData], '(?=X.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))+1)+'}M.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))+1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))+1)+'}S)') + REGEX_CountMatches([DownloadData], '(?=S.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))+1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))+1)+'}M.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))+1)+'}X)') + REGEX_CountMatches([DownloadData], '(?=X.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}M.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}S)') + REGEX_CountMatches([DownloadData], '(?=S.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}M.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}X)')​
REGEX_CountMatches([DownloadData], '(?=M.M.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}S.S)') + REGEX_CountMatches([DownloadData], '(?=M.S.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}M.S)') + REGEX_CountMatches([DownloadData], '(?=S.M.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}S.M)') + REGEX_CountMatches([DownloadData], '(?=S.S.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}A.{'+ToString(ToNumber(ToString(FindString([DownloadData], ' ')))-1)+'}M.M)')​
Heavy use of regex again today for my 8/9 tool solution
@DataNath You are amazing..👍
Surprisingly straightforward today - a fun little puzzle this time around.
X Y cartesian no macros
part 1
part 2
Marcus Alvim
I liked this one - took a little time to carve out a spot to work on it, but it was enjoyable (a little geometric thinking)
Very slow. I may brash up this.
Finally managed to get through Day 4!
Took me way too long to realize I was counting diagonals in only one direction 😅
I'm still standing! Struggled on 'seeing' the diagonal part but once I did I got the rest!
Definitely needed help on this one. Probably due to the later hour for me.
When the RegEx tool and RegEx functions come up with different answers 🤔
Solved!
I built a solution for Part 1 that worked where I used non-macro Tools to check the rows & columns. Then I built a macro for the diagonals. Then I re-did part 1 and the macro so it could handle all 9 directions (counting not moving as a direction.... I guess I should've excluded those. Drat!)
Then Part 2 didn't need any tweaks to the macro (woohoo!) and involved an extra filter at the end.
I used a Text Input file for the values I was trying to get - e.g. "X", then "XM", then "XMA", etc. I feel like I could've done that differently but it also worked beautifully for Part 2 without any macro tweaks, so I think I'm calling that a win.
In past years, I've always solved problems like these with spatial tools. Wanted to try something different
and here is the accompanying python - part 1 is pretty awful, part 2 is sweet.
all code at SeanAdams10/AdventOfCodePython: Advent of code challenges in Python - across multiple years
This was an interesting one!
Nice! Love the grid style ones (may saying regret this) 😂
Today was pretty fun...diagonal considerations through Alteryx aren't exactly straightforward but I bet they are harder with other tools!
The iterative macro is a wonderful thing! And for me, today was the first time Part 2 was way easier for me than Part 1! Once again....and I don't think this is a spoiler but when using Regex....
Also, here are my screenshots
Here is my Day 4 solution. Pretty big workflow so not posting a spoiler picture. Again, better late than never!
Solution