Skip to main content
added 478 characters in body
Source Link
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!

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!

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!

deleted 15 characters in body
Source Link
G B
  • 22.8k
  • 1
  • 20
  • 53

Ruby, 8176 bytes

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

Try it online!Try it online!

Ruby, 81 bytes

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

Try it online!

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!

Source Link
G B
  • 22.8k
  • 1
  • 20
  • 53

Ruby, 81 bytes

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

Try it online!