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