How many Latin Squares? A Latin Square is a square of size n × n containing numbers 1 to n inclusive. Each number occurs once in each row and column.

An example of a 3 × 3 Latin Square is:

[[1, 2, 3],
 [3, 1, 2],
 [2, 3, 1]]


Another is:

[[3, 1, 2],
 [2, 3, 1],
 [1, 2, 3]]


Given an integer input n where n > 0, determine how many Latin Squares there are with a size n  × n, where the possible values are anything from 1 to n inclusive.

Examples:

1 -&gt; 1
2 -&gt; 2
3 -&gt; 12
4 -&gt; 576
5 -&gt; 161280
6 -&gt; 812851200
7 -&gt; 61479419904000
11 -&gt; 776966836171770144107444346734230682311065600000 


This is OEIS sequence A002860. It has a Wikipedia article here.

Answers are only required to support inputs up to 6, due to anything above that being greater than 232. However, while this is not strictly enforceable, your algorithm must work for all inputs.
Jelly, 8 bytes

Œ!ṗµfZ€L


Brute force solution. Inputs 5 and higher will time out on TIO.

Try it online!

How it works

Œ!ṗµfZ€L  Main link. Argument: n

Œ!        Generate all permutations of R := [1, ..., n].
  ṗ       Take the n-th Cartesian power, yielding the array A of all n×n matrices
          whose rows are permutations of R.
   µ      New chain. Argument: A
     Z€   Zip each; transpose each matrix in A, yielding the array B of all n×n
          matrices whose columns are permutations of R.
    f     Filter; keep only matrices that appear in A and B.
       L  Compute the length, counting the kept matrices.