Tracks
/
Prolog
Prolog
/
Exercises
/
Magic Square
Magic Square

Magic Square

Easy

Instructions

Your task is to, given a square of positive integers, determine if the square is a magic square. A magic square is one where the sum of the numbers in each row, column and both diagonals are the same.

As an example, consider the following square:

4 9 2
3 5 7
8 1 6

This is a magic square, as the sum of every row, column and both diagonals is equal to 15.

Edit via GitHub The link opens in a new window or tab
Prolog Exercism

Ready to start Magic Square?

Sign up to Exercism to learn and master Prolog with 109 exercises, and real human mentoring, all for free.