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 -> 1
2 -> 2
3 -> 12
4 -> 576
5 -> 161280
6 -> 812851200
7 -> 61479419904000
11 -> 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.