Problem 2736. Pernicious Anniversary Problem
Solution Stats
Problem Comments
-
1 Comment
Very interesting problem!
Solution Comments
-
1 Comment
% 22 (which is 10110 in binary) has a population count of 3,
% which is prime, and therefore 22 is a pernicious number.
-
1 Comment
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?
-
1 Comment
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
-
3 Comments
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
-
2 Comments
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.
-
1 Comment
This solution will not work for all values of x, only those in the given test suite.
Problem Recent Solvers784
Suggested Problems
-
454 Solvers
-
10517 Solvers
-
Number of 1s in a binary string
6310 Solvers
-
Write c^3 as sum of two squares a^2+b^2
308 Solvers
-
Solve a System of Linear Equations
8431 Solvers
More from this Author40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!