Created
September 24, 2015 20:14
-
-
Save Drowze/7674c34ed6e6b3563626 to your computer and use it in GitHub Desktop.
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
10 | |
6 1 3 4 5 0 7 3 1 9 | |
8 1 3 4 5 9 7 2 9 2 | |
3 2 8 4 5 1 7 1 6 3 | |
1 9 3 4 5 6 7 9 5 3 | |
2 7 4 4 5 2 7 0 2 1 | |
6 2 9 4 5 7 7 7 3 2 | |
9 5 1 4 5 3 7 0 0 0 | |
6 2 3 4 5 5 7 0 0 0 | |
1 2 2 4 5 7 7 0 0 0 | |
1 2 8 4 5 9 7 4 5 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
class Terrain | |
attr_reader :coordinates, :matrix_size | |
def initialize (x) | |
first_line = true; | |
input = File.open(x, File::RDONLY){|f| f.read } | |
@coordinates = input.lines.map{ |l| l.split.map(&:to_i) } | |
@matrix_size = coordinates[0][0] | |
@coordinates.shift | |
end | |
def get_average | |
sum = 0; | |
coordinates.each do |line| | |
line.each do |element| | |
sum += element | |
end | |
end | |
average = (sum.to_f / (matrix_size * matrix_size)) | |
puts average | |
end | |
def get_lowest | |
lowest = coordinates[0][0] | |
x = 0 | |
y = 0 | |
x_temp = 0 | |
y_temp = 0 | |
coordinates.each do |line| | |
line.each do |element| | |
if lowest > element then | |
x = x_temp | |
y = y_temp | |
puts element | |
y_temp += 1 | |
end | |
end | |
x_temp += 1 | |
y_temp = 0 | |
end | |
puts "Lowest altitude coordinates: X: #{x}, Y: #{y}" | |
end | |
end | |
object = Terrain.new("terrain.dat") | |
object.get_average | |
object.get_lowest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment