Cody

# Problem 2738. Sideways sum

Solution 1477449

Submitted on 3 Apr 2018 by bainhome
• Size: 13
• This is the leading solution.
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
N = 1; num_ones = 1; assert(isequal(popcount(N),num_ones))

2   Pass
N = 2; num_ones = 1; assert(isequal(popcount(N),num_ones))

3   Pass
N = 3; num_ones = 2; assert(isequal(popcount(N),num_ones))

4   Pass
for num_ones = 3:10 N = 2^num_ones-1; assert(isequal(popcount(N),num_ones)) end

5   Pass
for num_ones = 1:50 N = sum(2.^(find(randperm(50)<=num_ones)-1)); assert(isequal(popcount(N),num_ones)) end

6   Pass
N = 23; num_ones = 4; assert(isequal(popcount(N),num_ones))

7   Pass
N = 123; num_ones = 6; assert(isequal(popcount(N),num_ones))

8   Pass
N = 123456; num_ones = 6; assert(isequal(popcount(N),num_ones))

9   Pass
N = 1234567; num_ones = 11; assert(isequal(popcount(N),num_ones))

10   Pass
N = 1125899906842501; num_ones = 45; assert(isequal(popcount(N),num_ones))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!