IBM Research

PUZZLE   IBM-210

Counting 12 bits using 5-to-2 functions

IBM Research · Ponder This · 2015-10

IBM Ponder This #210 · October 2015

Counting the number of 1s in a 12-bit input is a function from 12 to 4 bits.
Our challenge this month is to implement it with a minimal number of 5-to-2 functions (a function that receives 5 bits input and emits 2 bits output).
The format we request is several lines. Each line consists of <5 letters> followed by <32 base-4 digits>,
followed by the last line with 4 space separated numbers.
The 5 letters are the input to the function (the first letter is the msb) and the 32 digits are the output (the msb is the first output). The last line states which bits are used as the output.
To explain the format, here is an implementation that compares 2 numbers that are 2-bit, using 2 functions of 3-to-2
acd02113302
bef21133123
7 8
The input is a,b,c,d; the first line defines e,f as a function of the 3 bits a,c,d; and the second line applies a different 3-to-2 function on b,e,f, yielding a 2-bit output (g,h).
The last line states that the output of the computation is 7,8, where 7(=g) is the msb and 8(=h) is the lsb.
In the real problem, the output contains 4 bits. In our example, the output has 2 bits.

If a=0, c=0, d=0 then e=0 and f=0
If a=0, c=0, d=1 then e=1 and f=0
If a=0, c=1, d=0 then e=0 and f=1
If a=0, c=1, d=1 then e=0 and f=1
If a=1, c=0, d=0 then e=1 and f=1
If a=1, c=0, d=1 then e=1 and f=1
If a=1, c=1, d=0 then e=0 and f=0
If a=1, c=1, d=1 then e=1 and f=0
The output (g,h) is 0,1 if, and only if, 2*a+b < 2*c+d
The output (g,h) is 1,0 if, and only if, 2*a+b = 2*c+d
The output (g,h) is 1,1 if, and only if, 2*a+b > 2*c+d

Solution

Best opened after a real attempt

To be added.