Skip to content

Commit

Permalink
18: apparently we don't need to check if a pair is regular
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Dec 20, 2021
1 parent 4b4b88f commit 3c6b5be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
14 changes: 3 additions & 11 deletions 18/solve.a68
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@ BEGIN
dive into(0,num)
END;

PROC is regular = (PAIR tuple)BOOL:
(BOOL result := TRUE;
[]NUMBER pair = (left OF tuple, right OF tuple);
FOR i TO UPB pair WHILE result DO
(pair[i] | (INT n): ~ | result := FALSE)
OD; result);

PROC snailfish reduce = (REF NUMBER data)VOID:
BEGIN
REF NUMBER last regular;
INT last regular value, add to next regular;
INT add to next regular;
BOOL exploded;

PROC explode = (INT depth, REF NUMBER cell)BOOL:
CASE cell IN (REF PAIR pair):
IF depth >= 4 AND is regular(pair) AND NOT exploded THEN
IF depth >= 4 AND NOT exploded THEN
IF REF NUMBER prev cell = last regular; prev cell ISNT NIL THEN
prev cell := last regular value + (left OF pair | (INT n): n)
prev cell := (prev cell | (INT n): n) + (left OF pair | (INT n): n)
FI;
add to next regular := (right OF pair | (INT n): n);
cell := 0;
Expand All @@ -43,7 +36,6 @@ BEGIN
BEGIN
cell := n + add to next regular;
last regular := cell;
last regular value := n;
IF exploded THEN just start again FI
END
ESAC;
Expand Down
14 changes: 3 additions & 11 deletions 18/solve2.a68
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ BEGIN
dive into(0,num)
END;

PROC is regular = (PAIR tuple)BOOL:
(BOOL result := TRUE;
[]NUMBER pair = (left OF tuple, right OF tuple);
FOR i TO UPB pair WHILE result DO
(pair[i] | (INT n): ~ | result := FALSE)
OD; result);

PRIO COPY = 1;
OP COPY = (NUMBER x)NUMBER:
CASE x IN
Expand All @@ -33,14 +26,14 @@ PROC snailfish reduce = (NUMBER n)NUMBER:
BEGIN
NUMBER data := COPY n;
REF NUMBER last regular;
INT last regular value, add to next regular;
INT add to next regular;
BOOL exploded;

PROC explode = (INT depth, REF NUMBER cell)BOOL:
CASE cell IN (REF PAIR pair):
IF depth >= 4 AND is regular(pair) AND NOT exploded THEN
IF depth >= 4 AND NOT exploded THEN
IF REF NUMBER prev cell = last regular; prev cell ISNT NIL THEN
prev cell := last regular value + (left OF pair | (INT n): n)
prev cell := (prev cell | (INT n): n) + (left OF pair | (INT n): n)
FI;
add to next regular := (right OF pair | (INT n): n);
cell := 0;
Expand All @@ -51,7 +44,6 @@ BEGIN
BEGIN
cell := n + add to next regular;
last regular := cell;
last regular value := n;
IF exploded THEN just start again FI
END
ESAC;
Expand Down

0 comments on commit 3c6b5be

Please sign in to comment.