Skip to main content
3 of 3
added 478 characters in body
G B
  • 22.8k
  • 1
  • 20
  • 53

Ruby, 78 bytes

f=->n,r=[[]]{r.find{|q|q.sum==n}||f[n,r.product([*-n..-1]).map{|x,y|x+[y*y]}]}

Try it online!

Old version, with squares in ascending order (wrong)

Ruby, 76 bytes

f=->n,r=[[]]{r.find{|q|q.sum==n}||f[n,r.product([*1..n]).map{|x,y|x+[y*y]}]}

Try it online!

G B
  • 22.8k
  • 1
  • 20
  • 53