Cody

Solution 1588479

Submitted on 20 Jul 2018
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))

population = 1

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

population = 1.5850

Assertion failed.

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

population = 2

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

population = 3 population = 4 population = 5 population = 6 population = 7 population = 8 population = 9 population = 10

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

population = 48.0000

Assertion failed.

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

population = 4.5850

Assertion failed.

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

population = 6.9542

Assertion failed.

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

population = 16.9136

Assertion failed.

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

population = 20.2356

Assertion failed.

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

population = 50.0000

Assertion failed.