Created
January 16, 2009 10:21
-
-
Save darashi/47891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
i = 0 | |
founds = 0 | |
begin | |
i += 1 | |
sq = i ** 2 | |
digits = Math.log10(sq).to_i + 1 | |
next if digits % 2 == 1 | |
m = 10**(digits/2) | |
if (sq/m - sq%m).abs == 1 | |
founds += 1 | |
puts "%d: %d (%d^2)" % [founds, sq, i] | |
end | |
end while founds < 21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment