0 Z2
1 Z3
2 I4
3 J0,3 -> 5 // If r0 != 0, jump to add it to r2
4 J3,4 -> 9 // r0 == 0, force jump to check r1
5 I2 // add r0
6 I3
7 J0,3 -> 5
8 Z3
9 J1,3 -> 11 // If r1 != 0, jump to add it to r2
10 J3,4 -> exit // r1 == 0, force jump to exit
11 I2 // add r1
12 I3
13 J1,3 -> 11
14 exit
Phew that took a while. The simple case was easy enough. I guess exceptional candidates would be able to crack that out in an interview, otherwise they'd move you onto the balls.
I think this should work:
Phew that took a while. The simple case was easy enough. I guess exceptional candidates would be able to crack that out in an interview, otherwise they'd move you onto the balls.Edited!