Created
December 6, 2011 09:30
-
-
Save teenst/1437539 to your computer and use it in GitHub Desktop.
prob11
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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
#prob11 | |
file = open("prob11.txt","r") | |
grid = Array.new(20).map!{ Array.new( 20, 0 ) } | |
20.times do |i| | |
line = file.gets | |
line.chomp! | |
grid[i] = line.split | |
end | |
grid.each do |line| | |
print line,"\n" | |
end | |
max = 1 | |
#横列 | |
20.times do |j| | |
(20-3).times do |i| | |
tmp = grid[j][i].to_i*grid[j][i+1].to_i*grid[j][i+2].to_i*grid[j][i+3].to_i | |
if(tmp>max) | |
max=tmp | |
end | |
end | |
end | |
#縦列 | |
20.times do |j| | |
(20-3).times do |i| | |
tmp = grid[i][j].to_i*grid[i+1][j].to_i*grid[i+2][j].to_i*grid[i+3][j].to_i | |
if(tmp>max) | |
max=tmp | |
end | |
end | |
end | |
#右下がり列 | |
(20-3).times do |j| | |
(20-3).times do |i| | |
tmp = grid[j][i].to_i*grid[j+1][i+1].to_i*grid[j+2][i+2].to_i*grid[j+3][i+3].to_i | |
if(tmp>max) | |
max=tmp | |
end | |
end | |
end | |
#左下がり列 | |
(20-3).times do |j| | |
(20-3).times do |i| | |
tmp = grid[j][i+3].to_i*grid[j+1][i+2].to_i*grid[j+2][i+1].to_i*grid[j+3][i].to_i | |
if(tmp>max) | |
max=tmp | |
end | |
end | |
end | |
p max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment