diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/advent2020/4b.mu | 82 | ||||
-rwxr-xr-x | apps/assort | bin | 46677 -> 46769 bytes | |||
-rwxr-xr-x | apps/braces | bin | 48732 -> 48824 bytes | |||
-rwxr-xr-x | apps/calls | bin | 53727 -> 53819 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1 | bin | 46018 -> 46110 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1b | bin | 46565 -> 46657 bytes | |||
-rwxr-xr-x | apps/dquotes | bin | 50299 -> 50391 bytes | |||
-rwxr-xr-x | apps/factorial | bin | 45128 -> 45220 bytes | |||
-rwxr-xr-x | apps/hex | bin | 48857 -> 48949 bytes | |||
-rwxr-xr-x | apps/mu | bin | 596276 -> 596368 bytes | |||
-rwxr-xr-x | apps/pack | bin | 59367 -> 59459 bytes | |||
-rwxr-xr-x | apps/sigils | bin | 61101 -> 61193 bytes | |||
-rwxr-xr-x | apps/survey | bin | 56609 -> 56701 bytes | |||
-rwxr-xr-x | apps/tests | bin | 45468 -> 45560 bytes |
14 files changed, 82 insertions, 0 deletions
diff --git a/apps/advent2020/4b.mu b/apps/advent2020/4b.mu new file mode 100644 index 00000000..acc3b89d --- /dev/null +++ b/apps/advent2020/4b.mu @@ -0,0 +1,82 @@ +# https://adventofcode.com/2020/day/4 +# +# To run (on Linux): +# $ git clone https://github.com/akkartik/mu +# $ cd mu +# $ ./translate_mu apps/advent2020/4b.mu +# $ ./a.elf < input +# +# You'll need to register to download the 'input' file for yourself. + +fn main -> _/ebx: int { + var curr-passport-field-count/esi: int <- copy 0 + var valid-passport-count/edi: int <- copy 0 + var line-storage: (stream byte 0x100) # 256 bytes + var line/ecx: (addr stream byte) <- address line-storage + var key-slice-storage: slice + var key-slice/edx: (addr slice) <- address key-slice-storage + var val-slice-storage: slice + var val-slice/ebx: (addr slice) <- address val-slice-storage + $main:line-loop: { + # read line from stdin + clear-stream line + read-line-from-real-keyboard line + # if line is empty (not even a newline), quit + var done?/eax: boolean <- stream-empty? line + compare done?, 0 # false + break-if-!= + print-stream-to-real-screen line + # if line has just a newline, process passport + skip-chars-matching-whitespace line + var new-passport?/eax: boolean <- stream-empty? line + { + compare new-passport?, 0 # false + break-if-= + compare curr-passport-field-count, 7 + { + break-if-!= + valid-passport-count <- increment + print-string 0, "=> " + print-int32-decimal 0, valid-passport-count + print-string 0, "\n" + } + curr-passport-field-count <- copy 0 + loop $main:line-loop + } + $main:word-loop: { + skip-chars-matching-whitespace line + var done?/eax: boolean <- stream-empty? line + compare done?, 0 # false + break-if-!= + next-token line, 0x3a, key-slice # ':' + var dummy/eax: byte <- read-byte line # skip ':' + next-raw-word line, val-slice + print-slice-to-real-screen key-slice + print-string 0, " : " + print-slice-to-real-screen val-slice + print-string 0, "\n" + # treat cid as optional + var optional?/eax: boolean <- slice-equal? key-slice, "cid" + compare optional?, 0 # false + { + break-if-!= + # otherwise assume there are no invalid fields and no duplicate fields + curr-passport-field-count <- increment + print-string 0, "-> " + print-int32-decimal 0, curr-passport-field-count + print-string 0, "\n" + } + loop + } + loop + } + # process final passport + compare curr-passport-field-count, 7 + { + break-if-!= + valid-passport-count <- increment + } + print-int32-decimal 0, valid-passport-count + print-string 0, "\n" + return 0 +} diff --git a/apps/assort b/apps/assort index ee69e7e4..edf90788 100755 --- a/apps/assort +++ b/apps/assort Binary files differdiff --git a/apps/braces b/apps/braces index cd098220..610431a5 100755 --- a/apps/braces +++ b/apps/braces Binary files differdiff --git a/apps/calls b/apps/calls index 440185ca..19dfedb4 100755 --- a/apps/calls +++ b/apps/calls Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1 index 5a88adb7..d0ac4e5e 100755 --- a/apps/crenshaw2-1 +++ b/apps/crenshaw2-1 Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b index 95447807..c285a509 100755 --- a/apps/crenshaw2-1b +++ b/apps/crenshaw2-1b Binary files differdiff --git a/apps/dquotes b/apps/dquotes index 69183207..d4bef5ad 100755 --- a/apps/dquotes +++ b/apps/dquotes Binary files differdiff --git a/apps/factorial b/apps/factorial index 7040ea3e..305695b6 100755 --- a/apps/factorial +++ b/apps/factorial Binary files differdiff --git a/apps/hex b/apps/hex index 22db822a..c8f3d5aa 100755 --- a/apps/hex +++ b/apps/hex Binary files differdiff --git a/apps/mu b/apps/mu index 913cf1b1..e7183ec5 100755 --- a/apps/mu +++ b/apps/mu Binary files differdiff --git a/apps/pack b/apps/pack index 29e59e58..0665c0b9 100755 --- a/apps/pack +++ b/apps/pack Binary files differdiff --git a/apps/sigils b/apps/sigils index 3300a975..b14ff723 100755 --- a/apps/sigils +++ b/apps/sigils Binary files differdiff --git a/apps/survey b/apps/survey index 1adeef7c..67808f49 100755 --- a/apps/survey +++ b/apps/survey Binary files differdiff --git a/apps/tests b/apps/tests index b606df1d..b673925e 100755 --- a/apps/tests +++ b/apps/tests Binary files differ |