How long is the longest prime diagonal? - MATLAB Cody - MATLAB Central

Problem 659. How long is the longest prime diagonal?

Difficulty:Rate
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

39.82% Correct | 60.18% Incorrect
Last Solution submitted on Jan 14, 2025

Problem Comments

Solution Comments

Show comments
R2025a Pre-release highlights
This topic is for discussing highlights to the current R2025a Pre-release.
14
6

Problem Recent Solvers398

Suggested Problems

More from this Author50

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page