# [Ruby], 78 bytes <!-- language-all: lang-ruby --> f=->n,r=[[]]{r.find{|q|q.sum==n}||f[n,r.product([*-n..-1]).map{|x,y|x+[y*y]}]} [Try it online!][TIO-kvwqvwjr] [Ruby]: https://www.ruby-lang.org/ [TIO-kvwqvwjr]: https://tio.run/##LclLCsMgEADQfU/RZfNxwIBLe5FhFvkgZBFrTAXF8ewmJV29xfNhSrUaLd629xqRKHswq10y77zDETatbWE2eD04/1nC/H1hKyyAkNTANrrMsU8cO0xtokKluqdBSY8fw438O6hbpaie "Ruby – Try It Online" ## Old version, with squares in ascending order (wrong) # [Ruby], 76 bytes <!-- language-all: lang-ruby --> f=->n,r=[[]]{r.find{|q|q.sum==n}||f[n,r.product([*1..n]).map{|x,y|x+[y*y]}]} [Try it online!][TIO-kvw6r6mt] [Ruby]: https://www.ruby-lang.org/ [TIO-kvw6r6mt]: https://tio.run/##Lck7CoQwEADQfk9huf4GIqTMXmSYwg8BC2OMGzBkcvaoaPWK5/wQctaq/ZnGKUSi6EDPZoq88Qa7X5QyiVnj9WDdOvnx/8VKABgqYelt5KMJfNQYqkCJUraFRkGfm@5BvHbyUUrKJw "Ruby – Try It Online"