Skip to content

Instantly share code, notes, and snippets.

@jawspeak
Created January 27, 2010 00:54
Show Gist options
  • Select an option

  • Save jawspeak/287433 to your computer and use it in GitHub Desktop.

Select an option

Save jawspeak/287433 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# http://projecteuler.net/index.php?section=problems&id=1
# 2010-01-26
def sums(n)
s, i, p = 0, 0, 0
while (p < 1000) do
p = n*i
i += 1
s += p
end
s
end
puts sums(3)
puts sums(5)
puts "sum of all multiples of 3 or 5 below 1000: %d" % (sums(3) + sums(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment