Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Solução 2

  • Loading branch information...
commit 2b5b8756fa64efa68f92546cfaafa308290bcbd7 1 parent f86e26d
Plínio authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 001/ruby/euler001.rb
13 001/ruby/euler001.rb
View
@@ -1,5 +1,11 @@
-# http://projecteuler.net/problem=1
-
+# Problem 1 - Multiples of 3 and 5
+
+# 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.
+
+# Source: http://projecteuler.net/problem=1
+
+# Solução 1
sum = 0
(0..999).each do |n|
@@ -9,3 +15,6 @@
end
puts sum
+
+# Solução 2
+puts (1..999).to_a.keep_if{|n| n % 3 == 0 || n % 3 == 5}.reduce(:+)
Please sign in to comment.
Something went wrong with that request. Please try again.