about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-12-02 22:12:55 -0800
committerKartik Agaram <vc@akkartik.com>2020-12-02 22:12:55 -0800
commit124f515826f30da1379dad5c921117e206040fa2 (patch)
treebd3263ef54ef22620fdead455859b92d0e7088a8
parent36b4bf1f1b8aaf9a036bfe77e1c8045b24d652eb (diff)
downloadmu-124f515826f30da1379dad5c921117e206040fa2.tar.gz
7321 - advent day 3 part 1
-rw-r--r--apps/advent2020/3a.mu29
1 files changed, 13 insertions, 16 deletions
diff --git a/apps/advent2020/3a.mu b/apps/advent2020/3a.mu
index a2cc6fb6..777a7be0 100644
--- a/apps/advent2020/3a.mu
+++ b/apps/advent2020/3a.mu
@@ -69,28 +69,25 @@ fn main -> _/ebx: int {
   print-string 0, "x"
   print-int32-decimal 0, width
   print-string 0, "\n"
-  var i/eax: int <- copy 0
+  var row/ecx: int <- copy 0
+  var col/edx: int <- copy 0
+  var num-trees-hit/edi: int <- copy 0
   {
-    compare i, num-rows
+    compare row, num-rows
     break-if->=
-    var j/ecx: int <- copy 0
+    var curr/eax: int <- index2d trees, row, col, width
+    compare curr, 0
     {
-      compare j, width
-      break-if->=
-#?       print-int32-decimal 0, i
-#?       print-string 0, " "
-#?       print-int32-decimal 0, j
-#?       print-string 0, "\n"
-      var src/eax: int <- index2d trees, i, j, width
-      print-int32-decimal 0, src
-#?       print-string 0, "\n"
-      j <- increment
-      loop
+      break-if-=
+      num-trees-hit <- increment
     }
-    print-string 0, "\n"
-    i <- increment
+    # right 3, down 1
+    col <- add 3
+    row <- add 1
     loop
   }
+  print-int32-decimal 0, num-trees-hit
+  print-string 0, "\n"
   return 0
 }