Skip to content

Instantly share code, notes, and snippets.

@Jared-Prime
Created May 30, 2014 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jared-Prime/0f72c41a1f360d9588c8 to your computer and use it in GitHub Desktop.
Save Jared-Prime/0f72c41a1f360d9588c8 to your computer and use it in GitHub Desktop.
#! /bin/ruby
File.open( 'scala/euler/problem_11.txt', 'r' ) do |f|
grid = []
f.each_line do |line|
grid << line.split(' ').map(&:to_i)
end
products = []
for row in (0..16)
for col in (0..16)
products << grid[row][col] * grid[row][col+1] * grid[row][col+2] * grid[row][col+3]
products << grid[row][col] * grid[row+1][col] * grid[row+2][col] * grid[row+3][col]
products << grid[row][col] * grid[row+1][col+1] * grid[row+2][col+2] * grid[row+3][col+3]
products << grid[row+3][col] * grid[row+2][col+1] * grid[row+1][col+2] * grid[row][col+3]
end
end
puts products.max
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment