Created
March 18, 2014 13:29
-
-
Save negamorgan/9620021 to your computer and use it in GitHub Desktop.
Largest Product of Five (Euler 8)
This file contains 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
def largest_product(digits) | |
product_of_five(digits).max | |
end | |
def product_of_five(digits) | |
digit_array = digits.to_s.split("") | |
digit_array[0..-5].map.with_index do |digit, i| | |
digit.to_i * digit_array[i+1].to_i * digit_array[i+2].to_i * digit_array[i+3].to_i * digit_array[i+4].to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment