Challenge: Square rooter


#1

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


#2

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 |
-------------------------

#3

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.


#4

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.