diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-12-04 22:27:12 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-12-04 23:02:53 -0800 |
commit | eea6659a40b48e23cb660276248c7310ab879613 (patch) | |
tree | b7ff986d51bd035283b9699fa6820ad7156b486e /apps/advent2020 | |
parent | 273c42c06698f3e010739923714feba780a4c9cf (diff) | |
download | mu-eea6659a40b48e23cb660276248c7310ab879613.tar.gz |
7331 - hacky way to convert slice to string
Diffstat (limited to 'apps/advent2020')
-rw-r--r-- | apps/advent2020/4b.mu | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/apps/advent2020/4b.mu b/apps/advent2020/4b.mu index d4a3496e..ffeddb32 100644 --- a/apps/advent2020/4b.mu +++ b/apps/advent2020/4b.mu @@ -157,6 +157,26 @@ fn main -> _/ebx: int { var pid?/eax: boolean <- slice-equal? key-slice, "pid" compare pid?, 0 # false break-if-= + # convert val + var s: (handle array byte) + var s2: (addr handle array byte) <- address s + _slice-to-string val-slice, s2 + # check length + var len/eax: int <- length s2 + compare len, 9 + { + break-if-= + curr-passport-field-count <- copy 8 + } + # check valid decimal int + # parse-decimal-int-from-slice currently returns 0 on invalid parse, + # which isn't ideal but suffices for our purposes + var val/eax: int <- parse-decimal-int-from-slice val-slice + compare val, 0 + { + break-if-> + curr-passport-field-count <- copy 8 + } } loop } |