Created
January 27, 2010 00:54
-
-
Save jawspeak/287433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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