--
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/b6dbdc84-8e21-41db-9c65-cc4516298044n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/a9032cd0-72ad-4bcf-bc21-9143e605d7dcn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/737c1ee9-15ed-47f9-b9c5-c11a88d919afn%40googlegroups.com.
Hi everyone, answering...
Day 2 without CP:
Indeed, Neng-Fa, CP wasn’t necessary to solve Day 2. I rewrote a version that avoids CP entirely. For checking order, I initially used the 'increasing' and 'decreasing' constraints from CP library. However, with 'sorting' and using 'reverse' predicates/functions achieve the same result. Hakan’s approach demonstrated this effectively.
Part B – Borrowed Logic:
For Part B of Day 2, I borrowed this line: I borrowed this line "elseif (select(_A,Line,Line2) && safe(Line2)==1) then" from Hakan. The use of 'select' is indeed very fitting here, and I hadn’t considered it before.
Neng-Fa’s Solutions:
Neng-Fa, I reviewed your solutions for Day 2—they’re truly impressive. The use of the @ operator in predicates like safe(L@[X,Y|_]) and inc([X|L@[Y|_]]) left me speechless. I’ve seen the @ operator in your codes before but never fully understood its usage. Could you point me to some examples or resources to learn more? Your solutions are incredibly concise—congratulations!
I also enjoy of this reading: 'Rs = [R : Line in read_file_lines(File), R = [to_int(T) : T in split(Line)]]', a list comprehension inside another list comprehension, cool and hard to think. So interesting of a map applying a split like Hakan's version.
Day 3 – On Hold:
I’ll skip Day 3 for now and come back to it later.
Let’s see what the next challenges bring!
Best regards,
Claudio
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/874c4a4d-33ed-4140-aba8-928561a489f3n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/f9cca5ca-9230-439b-b0be-fc5fb6ec3dean%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/fc941d71-f361-4af7-a1d9-2dfe73df7507n%40googlegroups.com.
Today's (Day 16) challenge is a pathfinding problem. Part 1 can be straightforwardly modeled as a planning problem and solved efficiently using Picat's planner.
Part 2, however, is more challenging because it involves determining whether each square lies on an optimal path. Here is my solution:
https://github.com/nfzhou/aoc/blob/main/aoc_24_6_part2.pi
The solution checks each square by:
While this approach works on smaller sample instances, it struggles with larger ones. The program has been running for over an hour on the large instance without completing.
Do you have any suggestions for optimizing the solution?
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/70154026-1d9e-4869-9346-a01ff36fb440n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/3b6f590d-9bb2-433e-a3aa-2737e2b86b1en%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/bcaa92ec-dc48-4b3f-b480-2c8731cd2c32n%40googlegroups.com.
Puzzle inputs differ by user. Please log in to get your puzzle input.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/948c6d17-b697-45fc-843c-45c861ea82f5n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/618f04c8-db6f-4259-9374-2978edef062cn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/b6fd91c0-89c7-487c-b263-1dd56b885915n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/8b6e4d8d-f8b9-4582-b853-e4a5e8e64a14n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/2c34e017-a07a-4f8d-8110-c301dff2874en%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/8ef01fbb-c026-4cde-ba16-c60f63a14168n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/f49cf8e8-df31-433f-a2a9-5f1a9c1cea6fn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/35bfe2e0-9ecb-4e26-8052-0010e5239150n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/picat-lang/19c294f0-8760-4d96-879a-5279617c2c6dn%40googlegroups.com.
Thanks to C.G. for his help—I’ve rewritten his model for the Day 24 Part-2 problem into a more readable program:
https://github.com/nfzhou/aoc/blob/main/aoc_24_24_part2.pi
It’s truly a brilliant CSP model! CP has been used to train networks, and this is yet another excellent example.
Additionally, I’ve developed a new Picat solution for the Day 21 Part-2 problem:
https://github.com/nfzhou/aoc/blob/main/aoc_24_21_part2.pi
As I suspected, this problem doesn’t require non-deterministic search. An optimal path is always the one that is shortest, has the fewest turns, and follows the direction ordering of <^v>
(a handy insight I found on Reddit). This program uses a nice feature of Picat's tabling that allows multiple objectives to be optimized.
With these updates, my repository now includes solutions for all the 2024 Advent of Code problems! It’s been incredibly rewarding to participate, and I’m grateful to everyone who joined the discussions, offered help, and provided feedback.
Now let me collect all the stars for Picat and the Picat community!
Cheers,
NF