Cody

# Problem 108. Given an unsigned integer x, find the largest y by rearranging the bits in x

Solution 1710573

Submitted on 20 Jan 2019 by Nikolaos Nikolaou
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = 76; y_correct = 112; assert(isequal(maxit(x),y_correct))

y1 = 0 0 0 0 1 1 1 y2 = 0 1 2 3 4 5 6 y3 = 2 2 2 2 2 2 2 y4 = 1 2 4 8 16 32 64 y = 112

2   Pass
x = 555; y_correct = 992; assert(isequal(maxit(x),y_correct))

y1 = 0 0 0 0 0 1 1 1 1 1 y2 = 0 1 2 3 4 5 6 7 8 9 y3 = 2 2 2 2 2 2 2 2 2 2 y4 = 1 2 4 8 16 32 64 128 256 512 y = 992

3   Pass
x = 1000; y_correct = 1008; assert(isequal(maxit(x),y_correct))

y1 = 0 0 0 0 1 1 1 1 1 1 y2 = 0 1 2 3 4 5 6 7 8 9 y3 = 2 2 2 2 2 2 2 2 2 2 y4 = 1 2 4 8 16 32 64 128 256 512 y = 1008

4   Pass
x = 10000000; y_correct = 16711680; assert(isequal(maxit(x),y_correct))

y1 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 y2 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 y3 = 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 y4 = Columns 1 through 14 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 Columns 15 through 24 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 y = 16711680