Very interesting problem!
% 22 (which is 10110 in binary) has a population count of 3,
% which is prime, and therefore 22 is a pernicious number.
Why does the test suite shows true results for numbers that are not prime, i.e. the sum of digits of the given number is not prime?
With my function and R2015B, it works so I don't understand:
function y = isPernicious(x)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if(x == 1)
y = true;
else
if(mod(x,2) == 0)
y = false;
else
y = true; % PRIME
for k=3:2:x-2
if(mod(x,k) == 0)
y = false; % NOT PRIME
break;
end
end
end
end
end
Have provided a working and tested solution (two lines of code...), within the limits of the 2736 problem. The (my) solution had passed the Test Suite (!) - all 10 of them (tested at R2016b). Now, asking myself: is this worth time and effort - regarding the solutions assessment method for ... speaking, atm, only about this problem/solution issue.
Exactly, having the same issue: de2bi.
Now, MATLAB is made for solving problems. If, You must solve problems, with "stone age" limitations, how efficient is that? I do have a work-around for de2bin command, but it is not ... rational... to invest time into.
Sorry Cody, but: Wish You sincerely a Happy Anniversary, but those and similar limitations are missing the point of why is MATLAB - in the first place, made. And, ruining the fun...
Hello, Teodo. Just because "de2bi" isn't available in Cody (because it's part of an optional Toolbox), that _doesn't_ mean that there isn't a corresponding command among the core MATLAB functions. You will find it by searching the documentation. —DIV
What is wrong with the command de2bi?
de2bi is a function in the Communications System Toolbox, which is not a core part of MATLAB, and is not included in Cody.
This solution will not work for all values of x, only those in the given test suite.
1220 Solvers
Make one big string out of two smaller strings
1303 Solvers
Determine Whether an array is empty
705 Solvers
395 Solvers
248 Solvers