After many more attempts, ChatGPT could not format your DAY 4 code without errors (either moving your comments or failing indentation).
I switched over to Google's large language model on their browser (it is not Gemini AI) and it balked at writing a reformating program, saying that proper formatting requires a lot of details, though it did offer to generate a basic formating tool.. It said a
Without a robust, grammar-based Picat parser written in Python (which doesn't currently exist as an off-the-shelf library), it is not possible to automatically reformat the provided code perfectly using Python.
However, I can manually format the code for readability and provide the result here, following typical Picat style conventions (indentation, line breaks after commas/commas before new lines in lists, consistent spacing).
Here is the provided Picat code, manually reformatted:
import util.
import aoc.
% Define a function/predicate 'n' (neighbor count)
% Counts '@' neighbors for cell (I, J) in board B of size N
n(B, N, I, J) =
[1 : U in -1..1, V in -1..1,
I + U >= 1, I + U <= N,
J + V >= 1, J + V <= N,
B[I + U, J + V] = '@',
abs(U) + abs(V) != 0].sum.
% Define a function 'still'
% Checks if any '@' cells would change state based on neighbor count
still(B, N) =
[[R : J in 1..N,
R = cond((n(B, N, I, J) < 4, B[I, J] = '@'), 1, 0)].sum
: I in 1..N].sum.
main([F]) =>
B = rcm(F), % Read configuration matrix from file F
pp(B), % Pretty print board
Init = [1 : Y in B, X in Y, X = '@'].sum, % Initial count of '@' cells
N = B.length, % Board size
while(still(B, N) > 0)
B := [[R : J in 1..N,
R = cond((n(B, N, I, J) < 4, B[I, J] = '@'), '.', B[I, J])]
: I in 1..N],
pp(B)
end,
Fin = [1 : Y in B, X in Y, X = '@'].sum, % Final count of '@' cells
% The following lines are commented out in the original:
% ,pp([[R:J in 1..N,R=cond((n(B,N,I,J)<4,B[I,J]='@'),1,0)]:I in 1..N])
% ,pp([[R:J in 1..N,R=n(B,N,I,J)]:I in 1..N])
p(Init - Fin). % Print the difference
CLAUDE AI
As a third attempt, I tried the Claude AI. I asked it if it could reformat your code, which I provided to it by simple copy/paste.
Amazingly, it produced a very good reformat of your code. This is the link to the chat:
https://claude.ai/share/9c7a4b83-f416-44c7-9638-6d5a0042a304SPOILER ALERT that link contains the solution to the puzzle (2025 AOC Day 4)
I did not ask Claude to generate a script that could be used for other picat code But after it produced the reformatted code, I asked it how to input the puzzle date into your program, which it provided.
I asked Claude to explain how your code worked (derived the solution), and it explained the algorithm and stepped through the process.
I did not ask it to create a tool for reformating
I suggest to anyone interested in which AI to look to for guidance with learning Picat to check out this chat with CLAUDE.