Skip to content

Instantly share code, notes, and snippets.

@charlesponti
Created May 6, 2013 18:09
Show Gist options
  • Save charlesponti/5526911 to your computer and use it in GitHub Desktop.
Save charlesponti/5526911 to your computer and use it in GitHub Desktop.
Project Euler: Problem 8
def largest_product(num)
nums = num.to_s.split(//)
products = []
i = 5
0.upto(nums.length-1) { |i|
products << nums[i].to_i*nums[i-1].to_i*nums[i-2].to_i*nums[i-3].to_i*nums[i-4].to_i
}
p products.sort.last
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment