Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 58 characters in body
Source Link
lyxal
  • 35.6k
  • 2
  • 69
  • 148

Vyxal, 14(削除) 14 (削除ここまで) 12 bytes

f=ṖL√vẇ'ÞDṖ'L√ẇÞDf?=;h

Try it Online! Try it Online!

Math? Sensible methods of putting things into arrays? Programs that finish in reasonable time? Couldn't be me.

Times out for anything bigger than a 2x2 matrix.

Takes input as a flattened list and outputs a flattened list.

Explained (old)

f=ṖL√vẇ'ÞD?=;h
f=ṖL√ # Push all permutations of the flattened input, as well as the square root of the length of the flattened input 
 vẇ # Split each permutation into chunks of that length
 'ÞD?=; # Keep those only where the diagonals equal the input (this basically means try each and every single possible matrix from the input until one is found with the same diagonals)
 h # Get the first (and only) item

Vyxal, 14 bytes

f=ṖL√vẇ'ÞD?=;h

Try it Online!

Math? Sensible methods of putting things into arrays? Programs that finish in reasonable time? Couldn't be me.

Times out for anything bigger than a 2x2 matrix.

Explained

f=ṖL√vẇ'ÞD?=;h
f=ṖL√ # Push all permutations of the flattened input, as well as the square root of the length of the flattened input 
 vẇ # Split each permutation into chunks of that length
 'ÞD?=; # Keep those only where the diagonals equal the input (this basically means try each and every single possible matrix from the input until one is found with the same diagonals)
 h # Get the first (and only) item

Vyxal, (削除) 14 (削除ここまで) 12 bytes

Ṗ'L√ẇÞDf?=;h

Try it Online!

Math? Sensible methods of putting things into arrays? Programs that finish in reasonable time? Couldn't be me.

Times out for anything bigger than a 2x2 matrix.

Takes input as a flattened list and outputs a flattened list.

Explained (old)

f=ṖL√vẇ'ÞD?=;h
f=ṖL√ # Push all permutations of the flattened input, as well as the square root of the length of the flattened input 
 vẇ # Split each permutation into chunks of that length
 'ÞD?=; # Keep those only where the diagonals equal the input (this basically means try each and every single possible matrix from the input until one is found with the same diagonals)
 h # Get the first (and only) item
Source Link
lyxal
  • 35.6k
  • 2
  • 69
  • 148

Vyxal, 14 bytes

f=ṖL√vẇ'ÞD?=;h

Try it Online!

Math? Sensible methods of putting things into arrays? Programs that finish in reasonable time? Couldn't be me.

Times out for anything bigger than a 2x2 matrix.

Explained

f=ṖL√vẇ'ÞD?=;h
f=ṖL√ # Push all permutations of the flattened input, as well as the square root of the length of the flattened input 
 vẇ # Split each permutation into chunks of that length
 'ÞD?=; # Keep those only where the diagonals equal the input (this basically means try each and every single possible matrix from the input until one is found with the same diagonals)
 h # Get the first (and only) item

AltStyle によって変換されたページ (->オリジナル) /