Since Cody is 5 years old, it's pernicious. A Pernicious number is an integer whose population count is a prime. Check if the given number is pernicious.
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;
if(mod(x,2) == 0)
y = false;
y = true; % PRIME
if(mod(x,k) == 0)
y = false; % NOT PRIME
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.
Angle between two vectors
Get the length of a given vector
Say something funny
Pancake sorting - minimum flips.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office