Skip to content

Instantly share code, notes, and snippets.

@negamorgan
Created March 18, 2014 13:29
Show Gist options
  • Save negamorgan/9620021 to your computer and use it in GitHub Desktop.
Save negamorgan/9620021 to your computer and use it in GitHub Desktop.
Largest Product of Five (Euler 8)
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