We have already defined a folding number here.
But now we are going to define a Super Folding Number. A Super Folding number is a number that if folded enough times it will eventually reach one less than a power of two. The method of folding is slightly different than in the folding number question.
The folding algorithm goes as follows:
Take the binary representation
e.g. 5882
1011011111010
Spilt it into three partitions. First half, last half and middle digit (iff it has a odd number of digits)
101101 1 111010
If the middle digit is zero this number cannot be folded
Reverse the second half and superimposed on the first half
010111 101101
Add the digits in place
111212
- Iff there are any 2s in the result the number cannot be folded otherwise the new number is the result of the folding algorithm.
A number is a Super Folding number if it can be folded to a continuous string of ones. (All Folding numbers are also Super Folding Numbers)
Your task is to write code that takes in a number and outputs a truthy value if the number is a Super Folding number and falsy otherwise. You will be scored on the size of your program.
Examples
5200
Convert to binary:
1010001010000
Split in half:
101000 1 010000
The middle is one so we continue Superimpose the halves:
000010
101000
Added them:
101010
No twos so we continue Split in half:
101 010
Fold:
010
101
111
The result is 111
(7 in decimal) so this is a Super Folding Number.
Test Cases
The first 100 Super Folding Numbers are:
[1, 2, 3, 6, 7, 8, 10, 12, 15, 20, 22, 28, 31, 34, 38, 42, 48, 52, 56, 63, 74, 78, 90, 104, 108, 120, 127, 128, 130, 132, 142, 150, 160, 170, 178, 192, 204, 212, 232, 240, 255, 272, 274, 276, 286, 310, 336, 346, 370, 400, 412, 436, 472, 496, 511, 516, 518, 524, 542, 558, 580, 598, 614, 640, 642, 648, 666, 682, 704, 722, 738, 772, 796, 812, 852, 868, 896, 920, 936, 976, 992, 1023, 1060, 1062, 1068, 1086, 1134, 1188, 1206, 1254, 1312, 1314, 1320, 1338, 1386, 1440, 1458, 1506, 1572, 1596]
3
sneak into the test cases again? I can't see how it can be folded, since it splits to1 1
, immediately giving a2
. Or are you saying that folding it zero times counts also? \$\endgroup\$