From 29d813cf0d6779c476ecbedd98bcec677ed5a090 Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Fri, 11 Dec 2020 09:00:07 -0500 Subject: [PATCH] working on part 1 --- day11/solution1.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 day11/solution1.rb diff --git a/day11/solution1.rb b/day11/solution1.rb new file mode 100755 index 0000000..1f39f0b --- /dev/null +++ b/day11/solution1.rb @@ -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 \ No newline at end of file