Skip to content

Instantly share code, notes, and snippets.

@shelling
Created November 27, 2014 14:14
Show Gist options
  • Save shelling/bb5f3aed33dce6ceaa26 to your computer and use it in GitHub Desktop.
Save shelling/bb5f3aed33dce6ceaa26 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def integer?(number)
(number % 1) == 0
end
def double_square_number?(number)
sqrt = Math.sqrt(number)
if integer?(sqrt)
[sqrt.to_i, 0]
else
sqrt.floor.downto(1) do |n|
if integer?(m = Math.sqrt(number - n ** 2))
return [n, m.to_i]
end
end
return false
end
end
for i in 1..104 do
puts "#{i} => #{double_square_number?(i).inspect}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment