title: Writing a type contract for a magic square
body: <p>I was given this question to write the code for this magic square.</p>
  
  <blockquote>
    <p>A two dimensional integer matrix <code>s</code> is a magic square if </p>
    
    <ol>
    <li>The dimensions of s is nxn</li>
    <li>Every integer in [1,2,...,n*n] appears in s, exactly once.</li>
    <li>The sum of all rows in s is the same as the sum of all columns in s, is the same as the sum of the diagonal elements in s.</li>
    </ol>
    
    <p>Example: <code>s=[[8, 3, 4], [1, 5, 9], [6, 7, 2]]</code> represents the
    following integer matrix:</p>
  
  <pre><code>8 3 4
  1 5 9
  6 7 2
  </code></pre>
    
    <p>Note that <code>s</code> above is a two dimensional integer array</p>
    
    <ol>
    <li>s is a 3x3 square </li>
    <li>All numbers in [1,2,...,9] appear in s exactly once.</li>
    <li><p>The sum of all rows is the same as the sum of all columns is the same as the sums along both diagonals.</p>
    
    <ul>
    <li>Row  sums: <code>8+3+4 == 1+5+9 == 6+7+2 == 15</code></li>
    <li>Col  sums: <code>8+1+6 == 3+5+7 == 4+9+2 == 15</code></li>
    <li>Diag sums: <code>8+5+2 == 6+5+4 == 15</code></li>
    </ul></li>
    </ol>
    
    <p>Example: The following are also magic: <code>[[8, 1, 6], [3, 5, 7], [4, 9,
    2]], [[6, 7, 2], [1, 5, 9], [8, 3, 4]]</code></p>
  </blockquote>
  
  <p>I understand how to program and write this code but my question is how to write a type contract for this. I know how to write a program to execute this but when it comes to type contracts for any program, how do you know how many parameters there are going to be, and how do you know how to write examples of what you want it to do for a program like this. Is there a general method to follow when writing a type contract and making examples for a program?</p>