https://github.com/akkartik/mu/blob/main/linux/apps/advent2020/4a.mu
1
2
3
4
5
6
7
8
9
10
11 fn main -> _/ebx: int {
12 var curr-passport-field-count/esi: int <- copy 0
13 var valid-passport-count/edi: int <- copy 0
14 var line-storage: (stream byte 0x100)
15 var line/ecx: (addr stream byte) <- address line-storage
16 var slice-storage: slice
17 var slice/edx: (addr slice) <- address slice-storage
18 $main:line-loop: {
19
20 clear-stream line
21 read-line-from-real-keyboard line
22
23 var done?/eax: boolean <- stream-empty? line
24 compare done?, 0/false
25 break-if-!=
26 print-stream-to-real-screen line
27
28 skip-chars-matching-whitespace line
29 var new-passport?/eax: boolean <- stream-empty? line
30 {
31 compare new-passport?, 0/false
32 break-if-=
33 compare curr-passport-field-count, 7
34 {
35 break-if-!=
36 valid-passport-count <- increment
37 print-string 0, "=> "
38 print-int32-decimal 0, valid-passport-count
39 print-string 0, "\n"
40 }
41 curr-passport-field-count <- copy 0
42 loop $main:line-loop
43 }
44 $main:word-loop: {
45 next-word line, slice
46 var done?/eax: boolean <- slice-empty? slice
47 compare done?, 0/false
48 break-if-!=
49 print-string 0, " "
50 print-slice-to-real-screen slice
51
52 var optional?/eax: boolean <- slice-starts-with? slice, "cid:"
53 compare optional?, 0/false
54 {
55 break-if-!=
56
57 curr-passport-field-count <- increment
58 print-string 0, " => "
59 print-int32-decimal 0, curr-passport-field-count
60 }
61 print-string 0, "\n"
62 loop
63 }
64 loop
65 }
66
67 compare curr-passport-field-count, 7
68 {
69 break-if-!=
70 valid-passport-count <- increment
71 }
72 print-int32-decimal 0, valid-passport-count
73 print-string 0, "\n"
74 return 0
75 }