Wednesday, May 21, 2014

Reeborg programming challenges - Challenge #1

Can you have Reeborg do multiplication without using numerical variables?

Reeborg must show that it can multiply two numbers by taking a number N tokens located at x=1 and  y=Y, and leave a single token at row y=1 and x = N*Y.  For example, here's a starting position (image taken from RUR-PLE, so that it looks a bit different from the web version)
the final position must be
where a single token must be deposited.

So, without using numerical variables, and using only a single instruction per line (so no use of semi-colon, or having a colon followed by a statement), how short can a solution to this problem be?  Here's an example of a solution that is NOT allowed under the above rules:
y = 1      # numerical variables not allowed
tokens = 0;turn_left()  # use of ; is not allowed
def turn_around():
while not token_here():  
    y += 1  # not allowed
while token_here():
    tokens += 1  # not allowed

while front_is_clear():  move()  # not allowed, statement after colon

repeat(move, y*tokens-1)  # not allowed, multiplication

The solution must work for 5 different challenges (mul5x1, mul1x5, mul5x5, mul4x3, mul3x2) - or any other such challenges for which I could create a world. Excluding the line with think(0), which makes Reeborg move as quickly as possible, and the line select_challenge(...), can you write a solution shorter than 29 lines?  Solutions can be attempted at Reeborg's World. You may want to click on the help button to see a brief summary of all known instructions.


Unknown said...

Where ca I find more challanges?

André Roberge said...

The tutorial contains some relatively easy challenges.