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
-
25974 Solvers
-
1599 Solvers
-
Calculate the area of a triangle between three points
3144 Solvers
-
Multiples of a Number in a Given Range
770 Solvers
-
Number of Even Elements in Fibonacci Sequence
1431 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!