Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Last active September 30, 2015 20:17
Show Gist options
  • Save joelibaceta/57c694efc3cbcd9f9177 to your computer and use it in GitHub Desktop.
Save joelibaceta/57c694efc3cbcd9f9177 to your computer and use it in GitHub Desktop.
def get_sum(n)
odd, even = 0, 0
(1..n).map{|i| i % 2 == 0 ? even += i : odd += i }
puts "Suma de Pares : #{even} \nSuma de Impares : #{odd}"
end
def get_sum(n)
puts "Suma de Pares : #{(0..n).step(2).reduce(:+)}"
puts "Suma de Impares : #{(1..n).step(2).reduce(:+)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment