algorithm - function to find out how many magic squares are in rectangle made of n*m, where n,m - natural numbers -


enter image description here
need write algorithm how solve exercise, suggestions?

exercise:

we have rectangle, divided n x m squares, natural numbers. write function counts how many magic squares inside rectangle.

a magic square arrangement of k x k (k>=2) numbers , integers, in square grid, numbers in each row, , in each column, , numbers in main , secondary diagonals, add same number.

construct 4 arrays:

1: every element element original array + 1 left.

2: every element element original array + 1 top.

3: every element element original array + 1 top left.

4: every element element original array + 1 top right.

you array. have check every possible square fitting in array (there possibly better solution, can't think of any) looking in other four. since keep sums in array can see when checking array 3x3 (from top left) sums 15. means it's magic square.

when not starting in top left it's little less obvious still easy. @ example below second magic square highlighted. can see evey darker element minus corresponding lighter element constant (in case 12)

it work same first magic square, there zeroes, can skip it.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -