Skip to content

Instantly share code, notes, and snippets.

@shelling
Last active August 29, 2015 14:10
Show Gist options
  • Save shelling/d5c2b56c634b777345bc to your computer and use it in GitHub Desktop.
Save shelling/d5c2b56c634b777345bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class String
def *(str)
maxshift = self.length + str.length - 2
results = Array.new(maxshift+1, 0)
self.split(//).map(&:to_i).each_with_index do |i, at1|
str.split(//).map(&:to_i).each_with_index do |j, at2|
results[maxshift - at1 - at2] += i * j
end
end
results.each_with_index do |i, shift|
if i > 9
results[shift+1] = results[shift+1].to_i + (i / 10)
results[shift] = i % 10
end
end
results.reverse.join
end
end
for i in 1..1000000
a = (i.to_s * i.to_s).to_i
b = i * i
unless a == b
puts a
puts b
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment