Problem 659. How long is the longest prime diagonal?
Solution Stats
Problem Comments
-
9 Comments
I agree that the solution is mis-coded. isprime(spiral(4)) gives:
1 0 0 0
0 0 1 1
1 0 1 0
0 0 0 1
which means that d=2 for this case.
Rescoring based on corrected test suite. Sorry about that.
"find the longest diagonal arrangement of primes in spiral(n)" leaves room for misinterpretation.
I would have quickly understood:
"return the length of the longest diagonal sequence of primes in spiral(n)"
Like Jonathan Campelli, I still feel the problem statement could be clearer. From the example I eventually figure that reference is being made to the diagonally oriented elements running between elements (1,5) and (4,2) of isprime(spiral(n)). But arguably these are not on a/the "diagonal" of that matrix, per http://mathworld.wolfram.com/Diagonal.html (cf. https://en.wikipedia.org/wiki/Main_diagonal ).
Furthermore, there is no mention in the current online MATLAB documentation that "spiral" is actually a function that is already provided with MATLAB — i.e. that the user does not have to write their own function to make the spiral matrix. Apparently, "spiral can be found in the demo folder" [ref: https://stackoverflow.com/questions/29466058/spiral-loop-on-a-matrix-from-a-point].
hard
eh, I think the problem statement made sense. especially if you just run 'isprime(spiral(n))' in your command window. I liked this problem. Ended up using the technique I almost used on another problem awhile back but it made more sense to use here, so I had the basic framework already started :D
for i=1:50
spy(isprime(spiral(i)))
pause(0.1)
end
Nice Problem
Solution Comments
Show commentsProblem Recent Solvers396
Suggested Problems
-
Remove the small words from a list of words.
1496 Solvers
-
Return elements unique to either input
769 Solvers
-
Multiples of a Number in a Given Range
615 Solvers
-
MATCH THE STRINGS (2 CHAR) very easy
286 Solvers
-
Find my daddy long leg (No 's')
2382 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!