Skip to content

Instantly share code, notes, and snippets.

@noplans
Created January 16, 2009 09:30
Show Gist options
  • Save noplans/47885 to your computer and use it in GitHub Desktop.
Save noplans/47885 to your computer and use it in GitHub Desktop.
def decimals(number)
number.to_s.split(//).size
end
def even?(number)
decimals(number) % 2 == 0
end
def split(number)
str = number.to_s
half = str.split(//).size / 2
first = str[0..half-1].to_i
later = str[half..-1].to_i
return first, later
end
def adjoin?(a, b)
(a - b).abs == 1
end
list = []
number = 0
while list.size < 21
number += 1
square = number * number
next unless even?(square) && adjoin?(*split(square))
list << square
puts "%2d: #{square} (%d^2)" % [list.size, number]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment