# [Hard] "Long Division"

#1

The Turing Tumble can do division! Here’s the setup I used, as a puzzle.

Challenge: Divide register A by register B, and store the result in register C. Register B uses green ramps instead of blue switches. A ramp that directs marbles to the left is a 0, and a ramp that directs to the right is a 1, just like in Challenge 56. So in the picture, B=2.

Details: The division should be truncated (so C = A/B, rounded down). If the answer is too big to fit in C, it should wrap around (though honestly, what else would it do?). If register B is zero, your program can do whatever it likes. For some of the longer divisions, my solution would run out of marbles unless I put some back up top as it was running.

It’s not easy. If no one figures it out in a while, I’ll post my solution. I’d be interested to see some other ways of dividing. I bet if you stored some of the registers diagonally you could do much longer divisions.

#2

Ho hooooo - yes. This is what I’m talking about. Nice one!

#3

Here’s a solution, no image to avoid spoilers:
http://www.lodev.org/jstumble/?board=1rr1erexre0ellllllxrr0rrl0llrrrr0err0lierxlfrxeel_99_99