ôD©ø®Å\®Å/)O˜Ë²{¹nLQ*
Input format: 4\n[2,16,13,3,11,5,8,10,7,9,12,6,14,4,1,15]
. Outputs 1
/0
for truthy/falsey respectively.
Try it online or verify some more test cases.
Explanation:
ô # Split the 2nd (implicit) input into parts of a size of the 1st (implicit) input
# i.e. [2,16,13,3,11,5,8,10,7,9,12,6,14,4,1,15] and 4
# → [[2,16,13,3],[11,5,8,10],[7,9,12,6],[14,4,1,15]]
D # Duplicate it
© # And store it in the register (without popping)
ø # Zip/transpose; swapping rows/columns
# i.e. [[2,16,13,3],[11,5,8,10],[7,9,12,6],[14,4,1,15]]
# → [[2,11,7,14],[16,5,9,4],[13,8,12,1],[3,10,6,15]]
® # Push the matrix from the register again
Å\ # Get the top-left to bottom-right main diagonal of it
# i.e. [[2,16,13,3],[11,5,8,10],[7,9,12,6],[14,4,1,15]] → [2,5,12,15]
® # Push the matrix from the register again
Å/ # Get the top-right to bottom-left main diagonal of it
# i.e. [[2,16,13,3],[11,5,8,10],[7,9,12,6],[14,4,1,15]] → [3,8,9,14]
) # Wrap everything on the stack into a list
# → [[[2,16,13,3],[11,5,8,10],[7,9,12,6],[14,4,1,15]],
# [[2,11,7,14],[16,5,9,4],[13,8,12,1],[3,10,6,15]],
# [2,5,12,15],
# [3,8,9,14]]
O # Take the sum of each inner list:
# → [[34,34,34,34],[34,34,34,34],34,34]
˜ # Flatten this list
# i.e. [[34,34,34,34],[34,34,34,34],34,34] → [34,34,34,34,34,34,34,34,34,34]
Ë # Check if all values are equal to each other
# i.e. [34,34,34,34,34,34,34,34,34,34] → 1 (truthy)
² # Push the second input again
{ # Sort it
# i.e. [2,16,13,3,11,5,8,10,7,9,12,6,14,4,1,15]
# → [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
¹n # Push the first input again, and take its square
# i.e. 4 → 16
L # Create a list in the range [1, squared_input]
# i.e. 16 → [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
Q # Check if the two lists are equal
# i.e. [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
# and [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] → 1 (truthy)
* # Check if both checks are truthy by multiplying them with each other
# i.e. 1 and 1 → 1
# (and output the result implicitly)