AoC2020/day11/solution1.rb

27 lines
842 B
Ruby
Raw Normal View History

2020-12-11 14:00:07 +00:00
#!/bin/env ruby
require 'pry'
def fill_seats (seats)
output = Array.new(seats.length, Array.new(seats[0].length, nil))
output.map!.with_index do |row, i|
row.each.with_index do |seat, j|
next if !seats[i][j]
adjecents = 0
adjecents += seats[i+1][j-1..j+1].compact.sum if i < seats.length - 1
adjecents += seats[i][j-1].to_i if j > 0
adjecents += seats[i-1][j-1..j+1].compact.sum if i > 0
adjecents += seats[i][j+1].to_i if j < seats[i].length
puts "#{i},#{j}:#{adjecents}"
adjecents >= 4 ? 0 : 1
end
end
return output
end
seats = File.readlines('./input.sample').map(&:strip)
.map! {|line| line.split('') }
.map! {|line| line.map { |char| char == 'L' ? 0 : nil }}
#next = fill_seats(seats)
binding.pry