Skip to main content
added 1046 characters in body
Source Link

Jelly, 9 bytes

ŒṗƲẠ$ƇṪU

Try it online!Try it online!

ŒṗfƑƇ²€ṪU

Try it online!

Times out for test cases larger than 50.

How they work

ŒṗƲẠ$ƇṪU - Main link. Takes n on the left
Œṗ        - Integer partitions of n; Ways to sum positive integers to n
     $Ƈ   - Keep those partitions P for which the following is true:
    Ạ     -   All elements are:
  Ʋ      -   Square numbers
       ṪU - Take the last (the shortest) and reverse it

ŒṗfƑƇ²€ṪU - Main link. Takes n on the left
Œṗ        - Integer partitions of n; Ways to sum positive integers to n
      €   - For each integer to n:
     ²    -   Yield its square
   ƑƇ     - Keep partitions that are unchanged after:
  f  ²€   -   Removing all non-squares
       ṪU - Take the last (the shortest) and reverse it

Jelly, 9 bytes

ŒṗƲẠ$ƇṪU

Try it online!

Jelly, 9 bytes

ŒṗƲẠ$ƇṪU

Try it online!

ŒṗfƑƇ²€ṪU

Try it online!

Times out for test cases larger than 50.

How they work

ŒṗƲẠ$ƇṪU - Main link. Takes n on the left
Œṗ        - Integer partitions of n; Ways to sum positive integers to n
     $Ƈ   - Keep those partitions P for which the following is true:
    Ạ     -   All elements are:
  Ʋ      -   Square numbers
       ṪU - Take the last (the shortest) and reverse it

ŒṗfƑƇ²€ṪU - Main link. Takes n on the left
Œṗ        - Integer partitions of n; Ways to sum positive integers to n
      €   - For each integer to n:
     ²    -   Yield its square
   ƑƇ     - Keep partitions that are unchanged after:
  f  ²€   -   Removing all non-squares
       ṪU - Take the last (the shortest) and reverse it
Source Link

Jelly, 9 bytes

ŒṗƲẠ$ƇṪU

Try it online!