[Spoilers] Advent of Code 2023 Day 6 #2213
Replies: 1 comment 4 replies
-
Very interesting, thank you a lot for sharing this! You can use the ?- beats_record(B, (48938466,261119210191063)), labeling([down], [B]). B = 42843784 ; B = 42843783 ; B = 42843782 ; B = 42843781 ; B = 42843780 ; ... . Note that the domain (i.e., what |
Beta Was this translation helpful? Give feedback.
-
Hi!
I've been enjoying and struggling with solving a few AoC problems every year in Prolog and lately specifically in Scryer Prolog :). I have spent a lot of hours but I feel very much like a beginner. I happened to find a nice solution to part 2 but that felt kind of lucky. Wanted to share and discuss. Any feedback is welcome. This solution and those I've done can be found here.
I had this approach for Day 6 Part 1 (Link to problem):
When I was about to do part 2 which changes the input to one big time and distance in stead of several small ones I initially just tried using the exact same code but it turned out it was way too slow and never terminated. At first I tried labeling with min and max to try find the boundaries in order to calculate the number of solutions with something like this:
but I could never get the upper end of the boundary because max would not terminate (in reasonable time at least). Is there a faster way to start labeling from max even when the answer is "big"?
While experimenting a bit I noticed that the boundaries I was looking for would be printed by clpz when I did not label
B
:At this point I manually copied and subtracted the lower boundary from the upper and got my answer to Day 6 part 2!
Looking through some documentation a bit I found that I can use
fd_size/2
to get the size of B's value space which was just what I was after. This led to a quite short and neat solution for part 2.Happy coding days. Cheers!
Beta Was this translation helpful? Give feedback.
All reactions