CARDIAC › Tips and tricks › Room
Cell 00 is the constant 1
Say you're counting cards until you hit a negative one.
You'd keep a cell holding 1 and add it to the count each time. An instruction names a cell, never a value, so on CARDIAC every constant costs you a cell.
cell contents notes
10 030 INP 30 cells 10-18: count cards until a negative one
11 130 CLA 30
12 317 TAC 17
13 131 CLA 31
14 232 ADD 32 count + 1, from a cell holding 1
15 631 STO 31
16 810 JMP 10
17 531 OUT 31
18 900 HRS 00
30 000
31 000 the count
32 001
Step through the natural way in Cardigan
Except one. Cell 00 is wired to hold 001, so there's a 1 sitting there that you never have to supply. ADD 00 and SUB 00 add and take away one for free.
cell contents notes
10 030 INP 30 cells 10-18: count cards until a negative one
11 130 CLA 30
12 317 TAC 17
13 131 CLA 31
14 200 ADD 00 count + 1, from cell 00
15 631 STO 31
16 810 JMP 10
17 531 OUT 31
18 900 HRS 00
30 000
31 000 the count
Step through the CARDIAC way in Cardigan
Both count three cards. Bringing your own 1 takes 12 cells, and using cell 00 takes 11. They both run 26 instructions, so the saving here is the cell, which on a hundred-cell machine is worth having.
From the tips in
cardiac-code on GitHub. All the tips.