Discussion thread for day 6 of the Advent of Code - https://adventofcode.com/2024/day/6
This is precisely when you realize Day 6 is hard 😂 No Solutions yet posted!
I'm reasonably confident in my solution. It's just that I estimate the runtime at ~600 hours.
That was the point at which I chose sleep.
My solution, Part 1 is fairly quick, but Part 2 took 1hr and 10min to run:
My First Solution:
Main Workflow:
Move Guard (Iterative Macro):
Part 2: Place Obstacles (Batch Macro w/ Move Guard macro nested inside):
Amazing Solution (Thanks to @gawa for the idea to not nest macros): With the power of smart optimizations and memoization of the guard's corner stops this workflow solves Day 6 in 2 minutes and 30 seconds!!!:
Pretty Picture of Part 1 Guard's Trajectory:
This one is really hard 😂
First Part was running 17min and Second I have to fine tune as it will run forever :P
Sheesh. More in spoiler
Very satisfying to get this one cracked. Originally didn't have a clue how to tackle it but tested out a few approaches and got there in the end. P1 runtime was 1.7 seconds, P2 was 1 hour 42 mins. A huge thanks to @CoG for the golden tip on optimising iterations!
Brute force way. For part2, it'll take 8 hours in my computer😂😂😂
(Edit_ve2)
Instead of nested macro(Iterative Macro inside Batch Macro), I made attempt by single Iteration Macro, that run within 15min.
I maintain the same algorithm(brute force) as previous attempt but running time got much faster.
Nested Macro is 'easy for human to understand' but 'not easy for Alteryx to process'...maybe.
Solved!
Day 6 is toooooo hard. Normally this difficulty puzzle is served after day15.
This is not fast, but it is needed for part 2 input.Part2 Batch macro(Place obstacles one by one from the path of Part1 and start the infinite loop detection macro):
To solve faster, I think that the gawa's parallel approach is needed.
Was too tired to post this in the wee hours of the morning when this FINALLY finished running... if I don't sleep, why should my computer be allowed to? (Note: this took even longer than it needed to as I FORGOT to disabled my computer's ability to go to sleep after set intervals until part way through... Part 1 runs in a couple seconds at least... doing so thousands of times however for part 2...)
I spent a long time for P2 but finally my WF can run in 23 sec for P1 and P2.I got the idea from @gawa to avoid nested macro.
My solution...
I went on a trip, and by the time I came back, the answer was output (it took about 3 hours).
part 1: 2 mins > 9 seconds
part 2: 12 hrs > 1hrs > 10 mins
python take 15 seconds without any optimise, but alteryx is take forever, so it may a good to use python sometimes. to reduce the run time.
Not smart, but it worked.
Missed posting my solution for part 1. Things are getting busy, so I'm not sure how much further I'll get this year.
Stuck on 1 star again . . . sometimes you just gotta roll along!
Ugly but got the job done! Part 2 took 1 hr, 47 min to run.
Part 1 macro:
Part 2 macro - Outer macro (should've been a Batch but I did it as Iterative)
Inner macro:
This is the beginning of the days where the runtime is horrendous - this one took multiple hours to run.
All solutions at SeanAdams10/AdventOfCodePython: Advent of code challenges in Python - across multiple years
For everyone who has a working solution - esp @gawa and @CoG and @mmontgomery and @DataNath - have you run procmon to see what Alteryx is doing that causes it to run in such a long runtime compared to doing this in code. This is the key to helping Alteryx to optimize the power of macros. this is my next task for day 6, to figure out what's causing the run-time difference.For example: - Day 6 part 1 in Alteryx with AMP turned on (multi-threaded): 1m48 sec (yes - I am a bit bashful since others have done part 1 so quickly)
- Day 6 part 1 in code: 0.012 seconds on a single thread
that's a factor of 9000x. Even taking some of the faster runtimes posted by folk (like 1 sec or so) - that's still a factor of 100 difference with very heavy optimization
so there's something going on in each of our machines that is generating workload for the PC which may not be needed - this may be a really valuable example for us to dive into as a group to see if we can spot what's happening and create a few ideas on the community to performance tune macros.
here's a guide for how to get started with ProcMon:https://chatgpt.com/share/6759637c-7fb0-8007-a05f-bfd08f0557f9
@SeanAdams As I've been interested in the performance of AMP, thank you for sharing this toping.
When it comes to Iterative Macro, handover of iteration record from previous to next iteration should be one of the factor of slow running time, I suppose. As a first step, I investigated the running time of Day6P1 under the several conditions. I will figure out why running speed varies and what's going on with help of ProcMon (I installed ProcMon in my computer just now. Thank you for introducing it.).
1 process in Macro
(164 iterations)
2 process in series in Macro
(82 iterations)
3 process in series in Macro
(54 iterations)
Terminology:
'2 process in series in Macro' is to arrange the same process in series to reduce the necessary iteration number into half.
Likewise, '3 process in series in Macro' is like this. The necessary iteration number is one-third.
After many different approaches and endless looping (a specialty of mine), I finally got Part 1 to run in 22.5 seconds.Somewhere in the back of my mind, Digan was reminding me to minimize what I actually send through the iterative macro, so only sent the next location of the guard after moving (while outputting all of the steps taken in that movement)More on this later. On to read Part 2.....
Finally...
But it is good to see the iterative macro runs in shorter time as the iteration goes on
Now it runs in 14:04 minutes for Part 1 & 2 combined.
Same as Day 5. I'm going to try later for that 2nd star.
Only got one part correct on this one.