Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

AOC2024 - problem 16 - part 1

25 views
Skip to first unread message

Claudio Cesar de Sá

unread,
Jan 10, 2025, 11:30:47 AMJan 10
to Picat

Hi everyone,

First, I’d like to wish you all a wonderful 2025!

This week, I revisited solving Advent of Code 2024 - Day 16, Part 1 using the planner module, incorporating some tips from Hakan on action formulation. The problem passes the test cases with correct results and runs very efficiently.

However, when running it on a larger input instance from AoC, I encounter execution errors with various search methods. My solution is quite simple compared to those by Hakan and Neng-Fa.

Would anyone be able to review my code and help identify where I might be going wrong?

Thank you in advance for your time and insights!

Best regards,
Claudio

16_day_A.pi
16_input.txt

Oisín Mac Fhearaí

unread,
Jan 10, 2025, 12:44:48 PMJan 10
to Picat
Hi Claudio,

My day 16 part 1 solution was quite slow as well, but Hakan gave me another tip that made a huge improvement (6 seconds instead of 6 minutes, so 60x speedup!): try adding a "table" directive to your action predicates.

Here's my program for comparison (it's using my planner_star Dijkstra/A* module, but also works with the standard Picat planner): https://github.com/DestyNova/advent_of_code_2024/blob/main/16/part1.pi

Oisín

Claudio Cesar de Sa

unread,
Jan 10, 2025, 8:01:38 PMJan 10
to Oisín Mac Fhearaí, Picat
Hi Oisin

Yes I already added the "table" before the actions and a sleep up happen for both sample of this problem.

But when the code try the real input ...under a case a exception happen during the execution.

Which situation is happening this fail? A hard debug work ahead 

Anyway thanks for your feedback 

Claudio


--
You received this message because you are subscribed to the Google Groups "Picat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to picat-lang+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/a2e98da4-6d05-4309-999d-715182360b9an%40googlegroups.com.

Neng-Fa Zhou

unread,
Jan 13, 2025, 12:03:18 AMJan 13
to Claudio Cesar de Sa, Oisín Mac Fhearaí, Picat
Hi Claudio,

Here is the trace of your program:


I generated it using a new command line option "-d"  in version 3.8, which starts Picat in debug mode. You can see that clearly there is something wrong in your program.

Cheers,
NF

Claudio Cesar de Sá

unread,
Jan 13, 2025, 12:58:54 PMJan 13
to Picat
Thanks Neng-Fa

I was using Picat 3.6  and I really didn't know about this debugger option (-d). Really, it is very useful....
and idea should be for this options, with -d, stop just when the first fail happens.

Thanks... I will  recheck  the code.

Claudio

Neng-Fa Zhou

unread,
Jan 13, 2025, 8:21:48 PMJan 13
to Picat
I have several comments: First, you should not update the grid, but instead let the state carry the position and the direction of the robot. In this way, you don't need to copy the entire grid, and use so many assignments. Second, you should specify each action independently. So you need 6 rules: 4 for movements and 2 for turns. If you use deltas, then you only need one rule for movements. In the rule for downward movement, you also consider turns. It's too complicated. For example, what is this condition?

        (( Grid[X+1,Y] == '.' ; Grid[X+1,Y] == '#'), Grid[X,Y+1] == '.' ), %% free to right

Do you mean this?

        ( Grid[X+1,Y] == '.' ; (Grid[X+1,Y] == '#', Grid[X,Y+1] == '.' )), %% free to right

I hope my comments are helpful.

Cheers,
NF

Claudio Cesar de Sá

unread,
Jan 14, 2025, 4:04:10 PMJan 14
to Picat
Thanks Neng-Fa

As soon as I will be rewriting the whole code without a copy of Grid. I was copying all the grid to reproduce the path in the maze, like the sample B, below.
Really, instead of copy all the grid, jus store in list all coordinates which the robo is walking successful  and the print such coordenates.

Thanks for your help.


Claudio


Captura de tela de 2025-01-14 17-54-19.png
Reply all
Reply to author
Forward
0 new messages