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 Solvers400
Suggested Problems
-
Sort a list of complex numbers based on far they are from the origin.
5711 Solvers
-
Determine if input is a perfect number
242 Solvers
-
1513 Solvers
-
Simple equation: Annual salary
4211 Solvers
-
Find my daddy long leg (No 's')
2554 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!