Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created January 16, 2009 09:46
Show Gist options
  • Save maraigue/47886 to your computer and use it in GitHub Desktop.
Save maraigue/47886 to your computer and use it in GitHub Desktop.
年子平方数
class Integer
def toshigo?
# return nil if self <= 0
s = self.to_s
l = s.length
return false if l % 2 != 0
((s[0...(l/2)].to_i) - (s[(l/2)..-1].to_i)).abs == 1
end
end
i = 1
c = 0
while c < 21
t = i * i
if t.toshigo?
puts "#{i}^2 = #{t}"
c += 1
end
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment