Cody

Solution 560788

Submitted on 20 Jan 2015 by Pranav
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))