robota dodoano

This commit is contained in:
Adrian Hinz 2018-03-22 15:26:51 +01:00
parent 03cc99720f
commit 448403c922
1 changed files with 27 additions and 0 deletions

27
bin/robot.rb Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# encoding: UTF-8
@table = [
['0','0','0','0','0','0','0','0','0','0','0','0','0'],
['0','1','1','1','1','1','1','1','1','0','0','0','0'],
['0','0','1','0','0','0','1','0','1','1','0','0','0'],
['0','1','1','0','0','1','0','0','0','1','1','0','0'],
['0','1','1','1','1','1','1','1','1','0','1','0','0'],
['0','0','0','0','0','0','0','0','1','0','1','0','0'],
['0','1','1','1','1','1','1','0','1','0','1','0','0'],
['0','1','0','0','0','0','1','0','1','0','1','0','0'],
['0','1','1','1','1','0','1','0','1','0','1','0','0'],
['0','S','1','0','1','0','1','1','1','0','1','1','1'],
['0','0','0','0','0','0','0','0','0','0','0','0','0']
]
def find_start_pos(table, start_symbol='S')
table.each_with_index { |row,index_row|
row.each_with_index { |cell,index_cell|
return [index_row, index_cell] if cell.eql?(start_symbol)
}
}
return nil
end
puts find_start_pos(@table).inspect