# Convert from binary to unary in 7x7 Manufactoria

In the game manufactoria, take in a binary number and output that number of red pieces. The catch? The board-size is only 7x7:

Here's the manufactoria code for the problem:

I have a solution, so it most definitely exists.

EDIT: Least "total parts" wins (as reported by manufactoria engine)

• How do you win the competition? – beary605 Aug 4 '12 at 5:24
• Lets say least pieces. I really just want to see if people come up with different solutions than I did – dspyz Aug 4 '12 at 7:28

# 2120 19 parts! Ha!

Edit 2: Back to the original design, but with two parts shaved off by creative reuse of conveyors. The 7 × 7 board really does start to feel confining — I've come up with several ways to shrink this further, if I only had one more row of vertical space...

• Way to steal the win over a year after the question was asked. – dspyz Feb 2 '14 at 3:53

# 30 26 24 22 Parts

Here is my entry, with 22 parts and a time of 4:16. This can be rearranged slightly to fit into a 5 wide by 7 tall space.

It works by dividing the tape into three sections: the instructions (blue and red), the data (green), and a data terminator symbol (yellow). Each cycle of operation, it reads and replaces the first instruction. It then cycles the rest on the instructions to the back of the tape until it reaches the data. For each data symbol read, it adds two of them to the back of the tape. Once the data terminator is read, the instructions are once again at the front of the tape. It deletes the first instruction (which was just executed). It then adds one more data symbol to the end of the tape if the current instruction (read earlier) is blue. The yellow symbol is then re-appended. Once there are no more instructions, then all of the green symbols are converted to red and are output.

Example: input is BBR (110 or 6)
These are the important steps in execution, in more detail than before
BBR
BBRY     #yellow is appended
YBBR     #the instructions are cycled through, execution is on the left half
YBBR     #all of the greens (none yet) are duplicated
BRG      #Y and B are removed and a G appended
BRGY     #yellow is appended
GYBR     #instructions are cycled, execution is on left half
YBRGG    #Gs are duplicated
GGGYR    #instructions are cycled, execution is on RIGHT half
YRGGGGGG #Gs duplicated
GGGGGG   #YR removed, G NOT added
YRRRRRR  #Greens are changed to red
RRRRRR   #output

• You appear to have me beaten by one. I'm amazed at how few movers you used and it's planar. – dspyz Aug 5 '12 at 20:43
• I just shrunk it by two more parts. It's still planar and uses even fewer movers. – PhiNotPi Aug 5 '12 at 22:43
• Once again, shrunk by two parts, still planar, with even fewer movers. I've done a good job of compressing. – PhiNotPi Aug 6 '12 at 2:46

I managed 27 parts, but it would fit on a 5x7 grid:

I'm using the double-and-add method. Start by putting a green to mark the start of the number and then a green or a yellow to determine whether the next digit pulled off is a zero or a one. Skip past the rest of the number and then double the number of reds currently in place. Finally add one more if the next piece is yellow. Repeat until the number goes to zero.

## 17 13 parts

I took some liberty with the specification. I'm going to define the input binary number to appear in little-endian order. You never say explicitly whether the input is little or big endian, but it appears you assume big endian because your tests assume that. I'm going to use these little-endian tests instead.

The code works by decrementing the binary number by 1 each loop and adding one yellow mark. At the end, it replaces the yellow with red and deletes the binary number (all blue at this point, representing -1).

• No, in Manufactoria all binary numbers are bigendian. It should pass the tests – dspyz Aug 6 '12 at 17:59