Skip to content

Commit

Permalink
day 1 to day 10: removed a few BEGIN/END blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Dec 17, 2021
1 parent 83bc0f6 commit 9d8a561
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 96 deletions.
2 changes: 0 additions & 2 deletions 1/solve.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);
INT x := 0, buf, acc := 0;
REF INT last := x;
Expand All @@ -9,4 +8,3 @@ BEGIN
OD;
finished:
print((acc, new line))
END
2 changes: 0 additions & 2 deletions 1/solve2.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);
[3]INT window := (0,0,0);
REF INT a = window[1];
Expand All @@ -14,4 +13,3 @@ BEGIN
OD;
finished:
print((acc, new line))
END
2 changes: 0 additions & 2 deletions 10/solve.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: done reading);
INT score := 0;
DO
Expand Down Expand Up @@ -34,4 +33,3 @@ break:
OD;
done reading:
print((score, new line))
END
2 changes: 0 additions & 2 deletions 2/solve.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);
make term(stand in, " ");
[2]INT pos := (0,0);
Expand All @@ -12,4 +11,3 @@ BEGIN
OD;
finished:
print((pos[1]*pos[2], new line))
END
2 changes: 0 additions & 2 deletions 2/solve2.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);
make term(stand in, " ");
[2]INT pos := (0,0);
Expand All @@ -13,4 +12,3 @@ BEGIN
OD;
finished:
print((pos[1]*pos[2], new line))
END
4 changes: 1 addition & 3 deletions 3/solve.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);

STRING bit string := "";
Expand All @@ -22,8 +21,7 @@ finished:
FOR i TO width DO
INT dominant bit = (count[i] >= num lines / 2 | 1 | 0);
gamma := 2*gamma + dominant bit;
epsilon := 2*epsilon + (1-dominant bit);
epsilon := 2*epsilon + (1-dominant bit)
OD;

print((gamma * epsilon))
END
2 changes: 0 additions & 2 deletions 6/solve.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
STRING fish := "";
read((fish));
CO remove "," CO
Expand All @@ -14,4 +13,3 @@ BEGIN
OD;

print((UPB fish, new line))
END
2 changes: 0 additions & 2 deletions 6/solve2.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
STRING fish := "";
read((fish));
[0:8]LONG INT pop;
Expand All @@ -20,4 +19,3 @@ BEGIN
LONG INT sum := 0;
FOR i FROM 0 TO 8 DO sum +:= pop[i] OD;
print((sum, new line))
END
26 changes: 12 additions & 14 deletions 7/solve.a68
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ END;
PROC sum = (INT a, b, PROC(INT)INT value)INT:
(INT acc := 0; FOR i FROM a TO b DO acc +:= value(i) OD; acc);

BEGIN
FLEX[0]INT crabs := get positions;
INT best fuel := 1000000000;
INT best pos;
FOR pos FROM 0 TO 2000 DO
INT cand = sum(LWB crabs, UPB crabs, (INT i)INT: ABS(crabs[i] - pos));
IF cand < best fuel THEN
best fuel := cand;
best pos := pos
FI
OD;
print((best pos, new line));
print((best fuel, new line))
END
FLEX[0]INT crabs := get positions;
INT best fuel := 1000000000;
INT best pos;
FOR pos FROM 0 TO 2000 DO
INT cand = sum(LWB crabs, UPB crabs, (INT i)INT: ABS(crabs[i] - pos));
IF cand < best fuel THEN
best fuel := cand;
best pos := pos
FI
OD;
print((best pos, new line));
print((best fuel, new line))
26 changes: 12 additions & 14 deletions 7/solve2.a68
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ PROC sum = (INT a, b, PROC(INT)INT value)INT:
PROC triangle = (INT a)INT:
(INT x = ABS a; x*(x+1) % 2);

BEGIN
FLEX[0]INT crabs := get positions;
INT best fuel := 1000000000;
INT best pos;
FOR pos FROM 0 TO 2000 DO
INT cand = sum(LWB crabs, UPB crabs, (INT i)INT: triangle(crabs[i] - pos));
IF cand < best fuel THEN
best fuel := cand;
best pos := pos
FI
OD;
print((best pos, new line));
print((best fuel, new line))
END
FLEX[0]INT crabs := get positions;
INT best fuel := 1000000000;
INT best pos;
FOR pos FROM 0 TO 2000 DO
INT cand = sum(LWB crabs, UPB crabs, (INT i)INT: triangle(crabs[i] - pos));
IF cand < best fuel THEN
best fuel := cand;
best pos := pos
FI
OD;
print((best pos, new line));
print((best fuel, new line))
2 changes: 0 additions & 2 deletions 9/solve.a68
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BEGIN
INT risk level := 0;
[100,100]INT map;
PROC is local minimum = (INT x,y)BOOL:
Expand Down Expand Up @@ -27,4 +26,3 @@ done reading:
OD;

print((risk level, new line))
END
96 changes: 47 additions & 49 deletions 9/solve2.a68
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
BEGIN
[100,100]INT map;
[100,100]INT map;

PROC read input = VOID:
BEGIN
INT line := 0;
on line end(stand in, (REF FILE f)BOOL: (line+:=1; newline(f); TRUE));
on logical file end(stand in, (REF FILE f)BOOL: done reading);
DO
STRING s;
read((s));
FOR i TO UPB s DO map[line, i] := ABS s[i] - ABS "0" OD
OD;
done reading:
SKIP
END;
PROC read input = VOID:
BEGIN
INT line := 0;
on line end(stand in, (REF FILE f)BOOL: (line+:=1; newline(f); TRUE));
on logical file end(stand in, (REF FILE f)BOOL: done reading);
DO
STRING s;
read((s));
FOR i TO UPB s DO map[line, i] := ABS s[i] - ABS "0" OD
OD;
done reading:
SKIP
END;

read input;
read input;

CO mark off all borders CO
[0:1 UPB map+1, 0:2 UPB map+1]BOOL visited;
FOR x TO 1 UPB map DO
visited[x,2 UPB map+1] := visited[x,0] := TRUE;
FOR y TO 2 UPB map DO
visited[x,y] := map[x,y] = 9
OD
OD;
CO mark off all borders CO
[0:1 UPB map+1, 0:2 UPB map+1]BOOL visited;
FOR x TO 1 UPB map DO
visited[x,2 UPB map+1] := visited[x,0] := TRUE;
FOR y TO 2 UPB map DO
visited[1 UPB map+1,y] := visited[0,y] := TRUE
OD;
visited[x,y] := map[x,y] = 9
OD
OD;
FOR y TO 2 UPB map DO
visited[1 UPB map+1,y] := visited[0,y] := TRUE
OD;

PROC basin size= (INT x,y)INT:
(visited[x,y] := TRUE;
1+ (visited[x+1,y] | 0 | basin size(x+1,y)) +
(visited[x-1,y] | 0 | basin size(x-1,y)) +
(visited[x,y+1] | 0 | basin size(x,y+1)) +
(visited[x,y-1] | 0 | basin size(x,y-1)));
PROC basin size= (INT x,y)INT:
(visited[x,y] := TRUE;
1+ (visited[x+1,y] | 0 | basin size(x+1,y)) +
(visited[x-1,y] | 0 | basin size(x-1,y)) +
(visited[x,y+1] | 0 | basin size(x,y+1)) +
(visited[x,y-1] | 0 | basin size(x,y-1)));

[3]INT best basins := (0,0,0);
PROC cmp swap = (REF INT x, y)VOID:
(INT tmp = x;
IF tmp < y THEN x := y; y := tmp FI);
[3]INT best basins := (0,0,0);
PROC cmp swap = (REF INT x, y)VOID:
(INT tmp = x;
IF tmp < y THEN x := y; y := tmp FI);

FOR x TO 1 UPB map DO
FOR y TO 2 UPB map DO
IF NOT visited(x,y) THEN
INT this basin = basin size(x,y);
IF this basin > best basins[3] THEN
best basins[3] := this basin;
cmp swap(best basins[2], best basins[3]);
cmp swap(best basins[1], best basins[2])
FI
FOR x TO 1 UPB map DO
FOR y TO 2 UPB map DO
IF NOT visited(x,y) THEN
INT this basin = basin size(x,y);
IF this basin > best basins[3] THEN
best basins[3] := this basin;
cmp swap(best basins[2], best basins[3]);
cmp swap(best basins[1], best basins[2])
FI
OD
OD;
FI
OD
OD;

print((best basins[1]*best basins[2]*best basins[3], new line))
END
print((best basins[1]*best basins[2]*best basins[3], new line))

0 comments on commit 9d8a561

Please sign in to comment.