Skip to content

Instantly share code, notes, and snippets.

@jasonnoble
Created September 21, 2010 18:57
Show Gist options
  • Save jasonnoble/590290 to your computer and use it in GitHub Desktop.
Save jasonnoble/590290 to your computer and use it in GitHub Desktop.
#
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
# The sum of these multiples is 23.
#
# Find the sum of all the multiples of 3 or 5 below 1000.
# puts (1..10).inject{|sum, n| sum + n if (n % 3 == 0 || n % 5 == 0)}
["9", "99", "999", "9999", "99999", "999999", "9999999", "99999999"].each do |num|
print "NUM: #{num}\n\t"
print "2"
print "3"
if num.length > 1
if num.length > 2
print "3"*(num.length - 2)
end
print "1"
if num.length > 2
print "6"*(num.length - 2)
end
print "8"
end
print "\n"
# puts "\t" + (1..num.to_i).inject(0){|sum, n| (n % 3 == 0 || n % 5 == 0) ? sum + n : sum}.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment