Cody

Solution 1733929

Submitted on 23 Feb 2019
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   Fail
N = 2; num_ones = 1; assert(isequal(popcount(N),num_ones))

Assertion failed.

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

Assertion failed.

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

Assertion failed.

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

Assertion failed.

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

Assertion failed.

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

Assertion failed.

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

Assertion failed.

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

Assertion failed.

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

Assertion failed.

Suggested Problems

More from this Author41