summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-12-11 03:12:09 +0100
committerkdx <kikoodx@paranoici.org>2023-12-11 03:12:09 +0100
commitb921edf1747e806bd0bfcf25c1f24f6271366fd4 (patch)
treebd6d872cccf406414db4de6e4b7ecb6118c46c4f
parent49d83183fa41c7b8e6f126d8df0591d6698cd9e2 (diff)
downloadaoc23-b921edf1747e806bd0bfcf25c1f24f6271366fd4.tar.gz
10 golem
-rw-r--r--.gitignore1
-rwxr-xr-x10/golem.sh2
-rw-r--r--10/main.golem90
3 files changed, 93 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 38dcfd0..f9dfb65 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ a.out
target/
bin/
obj/
+out.rom
diff --git a/10/golem.sh b/10/golem.sh
new file mode 100755
index 0000000..2bbcbb2
--- /dev/null
+++ b/10/golem.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+golemc main.golem | orgaasm - out.rom && orgaemu out.rom <input
diff --git a/10/main.golem b/10/main.golem
new file mode 100644
index 0000000..ea46c3d
--- /dev/null
+++ b/10/main.golem
@@ -0,0 +1,90 @@
+define grid.width = 140;
+define grid.height = 140;
+define grid.size = grid.width * grid.height;
+global grid[grid.size];
+
+main() {
+ readgrid(grid, grid.size);
+ dbg traverse(grid, grid.width, grid.height) / 2;
+}
+
+readgrid(g, size) {
+ local i = 0;
+ loop {
+ if (i == size)
+ return;
+ red g + i;
+ if ([g + i] == '\n')
+ red g + i;
+ i++;
+ }
+}
+
+printgrid(g, w, h) {
+ local y = 0;
+ local x = 0 - 1;
+ loop {
+ x++;
+ if (x == w) {
+ x = 0;
+ wrt '\n';
+ y++;
+ if (y == h)
+ return;
+ }
+ wrt [g + x + y * w];
+ }
+}
+
+traverse(g, w, h) {
+ local y = 0;
+ local x = 0 - 1;
+ local dx = 0;
+ local dy;
+ local p;
+ local c;
+ local steps = 0;
+
+ // find start position
+ loop {
+ x++;
+ if (x == w) {
+ x = 0;
+ y++;
+ }
+ if ([g + x + y * w] == 'S')
+ break;
+ }
+
+ // find starting direction
+ p = g + x + y * w;
+ c = [p - 1];
+ if (c == '-' | c == 'L' | c == 'F')
+ dx = 0 - 1;
+ c = [p + 1];
+ if (c == '-' | c == 'J' | c == '7')
+ dx = 1;
+ if (dx == 0) {
+ c = [p - w];
+ dy = 1;
+ if (c == '|' | c == '7' | c == 'F')
+ dy = 0 - 1;
+ }
+
+ loop {
+ steps++;
+ x = x + dx;
+ y = y + dy;
+ c = [g + x + y * w];
+ if (c == '7' | c == 'L') {
+ p = dx;
+ dx = dy;
+ dy = p;
+ } else if (c == 'F' | c == 'J') {
+ p = dx;
+ dx = 0 - dy;
+ dy = 0 - p;
+ } else if (c == 'S')
+ return steps;
+ }
+}