working on part 1

master
Jeff Yates 2020-12-11 09:00:07 -05:00
parent 3153761e14
commit 29d813cf0d
1 changed files with 27 additions and 0 deletions

27
day11/solution1.rb Executable file
View File

@ -0,0 +1,27 @@
#!/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