Problem 659. How long is the longest prime diagonal?
Stanislaw Ulam once observed that if the counting numbers are arranged in a spiral, the prime numbers contained in it form a surprising pattern. They appear to cluster along diagonals of the spiral matrix.
Given n, return the length of the longest diagonal sequence of primes in spiral(n).
Example:
Input n = 7
Output d = 4
Since isprime(spiral(n)) is
1 0 0 0 1 0 0
0 0 0 1 0 0 0
1 0 1 0 0 0 0
0 1 0 0 1 1 0
0 0 1 0 1 0 1
0 1 0 0 0 1 0
1 0 0 0 0 0 1
Solution Stats
Problem Comments
-
9 Comments
Show
6 older comments
HighPhi
on 24 Jul 2020
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
mahesh kumar
on 8 Nov 2020
for i=1:50
spy(isprime(spiral(i)))
pause(0.1)
end
Dara Murray
on 19 Jul 2021
Nice Problem
Solution Comments
Show commentsProblem Recent Solvers399
Suggested Problems
-
28336 Solvers
-
Find the longest sequence of 1's in a binary sequence.
6377 Solvers
-
Renaming a field in a structure array
1551 Solvers
-
Set the array elements whose value is 13 to 0
1377 Solvers
-
There are 10 types of people in the world
1152 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!