Deviopath › Karel

Binary Counter

Hard · Algorithms

The row is a number written in binary: a square with a ball is a 1, an empty square is a 0. The rightmost square is the smallest bit. Add 1 to the number.

Karel starts on the rightmost square, facing west. Adding 1 works like this: a 0 becomes a 1 and you are done; a 1 becomes a 0 and the 1 carries over to the next square on the left.

Your code runs in several worlds. If every bit is a 1, they all become 0 (the number rolls over, like a car odometer).

Next: Paw on the Wall