Numbers spiral diagonals (Part 1) - MATLAB Cody - MATLAB Central

Problem 2340. Numbers spiral diagonals (Part 1)

Difficulty:Rate

Inspired by Project Euler n°28 et 58.

A n x n spiral matrix is obtained by starting with the number 1 and moving to the right in a clockwise direction.

For exemple with n=5, the spiral matrix is :

                       21 22 23 24 25
                       20  7  8  9 10
                       19  6  1  2 11
                       18  5  4  3 12
                       17 16 15 14 13

In this example, the sum of the numbers on the diagonals is 101.

What is the sum of the numbers on the diagonals in any n by n spiral (n always odd) ?

HINTS: You want the diagonals, not the whole matrix.

Solution Stats

57.08% Correct | 42.92% Incorrect
Last Solution submitted on Apr 07, 2025

Problem Comments

Solution Comments

Show comments
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Group

Matrix Patterns II Image
Matrix Patterns II
  • 15 Problems
  • 69 Finishers

Problem Recent Solvers210

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page