I would have thought Jelly would be better at this, maybe a more mathematical approach will triumph?
ŒMḢḢ
+þ`¬ZṚ$ṛ¬Ç$¦€Ç¦‘ɼ$ḣÇȦƊ?ƬȦƇṂ
A monadic Link accepting a positive integer that yields a list of lists of positive integers (top-left 1
option).
Try it online!
How?
Start with an \$N\times N\$ table of zeros, then repeatedly either fill in the next number in the first zero of the first row that contains a maximal value, unless that row is filled in which case rotate. This process terminates with a full table but rotated further than we want, so we collect all the states along the way then pick the one we need out (using ȦƇṂ
).
ŒMḢḢ - Helper Link: list of list of integers (current state)
ŒM - multidimensional indices of maximal elements
Ḣ - head
Ḣ - head -> row index containing the maximum value
+þ`¬ZṚ$ṛ¬Ç$¦€Ç¦‘ɼ$ḣÇȦƊ?ƬȦƇṂ - Link: positive integer, N
+þ` - [1..N] addition table with [1..N]
¬ - logical NOT -> N×N table of zeros
Ƭ - collect inputs while distinct applying:
? - if...
Ɗ - ...condition: last three links as a monad:
Ç - call our helper link
ḣ - head (the current state) to that index
Ȧ - all truthy when flattened?
$ - ...then: last two links as a monad:
Z - transpose
Ṛ - reverse
- this rotates when we've finished a row
$ - ...else: last two links as a monad:
ɼ - apply to the register (initially 0) & yield:
‘ - increment
¦ - sparse application...
Ç - ...to indices: call our helper link
€ - ...apply: for each:
¦ - sparse application...
$ - ...to indices: last two links as a monad:
¬ - logical NOT (vectorises)
Ç - call our helper link
ṛ - ...apply: the incremented register value
Ƈ - filter keep those for which:
Ȧ - all truthy when flattened?
Ṃ - minimum (of the rotate tables we have left)
Another approach, but even more lengthy at 39:
RµṚĖm€0F;Ɱ"ḊṚ’$ṖṚ4ƭ³’Ḥ¤Ð¡UÐeẎIƇŒṬ€×"J$S
Try this one
This one works by building a list of the two-dimensional indices ordered by their final value then composing the table by adding up tables that are all zeros except the bottom-rightmost entry which is the number we want there in the end.