-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday5-1-ungolfed.prdc
71 lines (69 loc) · 1.98 KB
/
day5-1-ungolfed.prdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
i .. read full input
Ig .. read int groups thereof
Hr .. put this array into H, the default hoard
0 .. pc
λ .. infinite loop
· .. assign pc to bullet
H= .. index pc into H to get the "first value" of an instruction
1h‰ .. divmod 100 to get the parameter mode value and the opcode
.. •"% % <- % loop stuff"pk;
[ .. case on the opcode...
1 .. addition:
{
.. "addition"p
A‰\A%‡ .. get the ones and then tens digit of the parameter mode value
•)3+y .. get the three addresses of the argument values
Ht) .. translate them; uncons the last
ζ .. under that last one, zip modes with addresses:
\ .. swap mode on top, then
H=b| .. index into H if it's false
}u .. (under)
\ .. swap the last address under the list,
Š .. sum the list, and
Hu .. update H
4 .. leave 4, indicating to increment pc by 4
}
2
{
.. "multiplication"p
A‰\A%‡ .. get the ones and then tens digit of the parameter mode value
•)3+y .. get the three addresses of the argument values
Ht) .. translate them; uncons the last
ζ .. under that last one, zip modes with addresses:
\ .. swap mode on top, then
H=b| .. index into H if it's false
}u .. (under)
\ .. swap the last address under the list,
Þ .. take the product of the list, and
Hu .. update H
4 .. increment pc by 4
}
3
{
.. "input"p
; .. pop the parameter mode value, not needed
•)H=Ho .. update 1 where specified
2
}
4
{
.. "output"p
•)H=\ .. find argument, swap under imode
H=b| .. index again if imode is false
: .. duplicate;
P_ .. if true, print
;_ .. if false, pop
? .. if-else
2
}
99
{
E .. exit
}
1_
{
"Unrecognized opcode" Ec
}
]s
•+
}