Turing Tumble Community

Challenge: Square rooter

Given a 4-bit number in a register A, store the square root of that number, rounded down, in a 2-bit register B. The registers can be made up of any combination of bits and gear bits and put anywhere you like. You can choose the initial value of B.

Here is a possible starting template: https://www.lodev.org/jstumble/?board=f0z0ze0ff1faffbffee

1 Like

I can hardly find any purchase on this problem without listing out the cases, so I thought I’d do so here for the benefit of others as well.

-------------------------
| 0   | 1   | 0   | 1   |
| 0   | 0   | 1   | 1   |
| 0 0 | 0 1 | 0 1 | 0 1 |
| 0 0 | 0 0 | 0 0 | 0 0 |
-------------------------
| 0   | 1   | 0   | 1   |
| 0   | 0   | 1   | 1   |
| 1 0 | 1 0 | 1 0 | 1 0 |
| 0 1 | 0 1 | 0 1 | 0 1 |
-------------------------
| 0   | 1   | 0   | 1   |
| 0   | 0   | 1   | 1   |
| 0 0 | 0 1 | 0 1 | 0 1 |
| 1 1 | 1 1 | 1 1 | 1 1 |
-------------------------
| 0   | 1   | 0   | 1   |
| 0   | 0   | 1   | 1   |
| 1 1 | 1 1 | 1 1 | 1 1 |
| 1 1 | 1 1 | 1 1 | 1 1 |
-------------------------

My solution: https://www.lodev.org/jstumble/?board=0r00e00r1llr0xr0errrllerrr0eel0llerrr0eer0lieerlee1

It works on the fact that the difference between consecutive squares is 1,3,5,7,9… By the way, the 4-bit register is in the rightmost column that has bits and the other register is in the center column above the bottom-most bit.

Start with the red lever.

3 Likes

Very nice @donutcomputer. I started in a similar way to @elendiastarman and hard-coded a solution exploiting the patterns which I’ll post at the weekend as I don’t have it to hand at the moment. This is far more elegant and extensible.

Another approach to this problem, based on the same difference observation, would be to generate a sequence like
RRRRRRRbRRRRRbRRRbRb
The machine would be calculating the integer part of the square root of the number of Red balls supplied. The square root is the number of blue balls. With a large enough board, a counter could count the blue balls as they come through.

Does anyone have an idea about how to generate this sequence?

Here is my attempt. The number of red balls will be the square root of blue balls. When 25 blue balls are supplied, it will produce the pattern RbbbbbbbbbRbbbbbbbRbbbbbRbbbRb. If we have larger board, we can count the balls using registers.
https://lodev.org/jstumble/?board=rre0ere00ele0r0le0rrxeal1l1ex1l0lrrrlrerrrerelrlelx_25_20