Compare commits
No commits in common. "769f37a89e3f7f0cfa21a01cf33481ff173ffebc" and "7574cfa2aedd67a438631ef8f9e858a40a005689" have entirely different histories.
769f37a89e
...
7574cfa2ae
|
@ -1,36 +0,0 @@
|
||||||
#!/bin/env ruby
|
|
||||||
require 'pry'
|
|
||||||
numbers = File.read('./input').split("\n").map(&:to_i).sort
|
|
||||||
numbers.prepend(0)
|
|
||||||
numbers.push(numbers[-1] + 3)
|
|
||||||
#binding.pry
|
|
||||||
solution = numbers.map.with_index do |num, i|
|
|
||||||
next if i == 0
|
|
||||||
num - numbers[i-1]
|
|
||||||
end
|
|
||||||
solution.compact!
|
|
||||||
count = [0]
|
|
||||||
count_i = 0
|
|
||||||
solution.each.with_index do |num, i|
|
|
||||||
next if i == 0
|
|
||||||
if num == 3
|
|
||||||
count_i += 1
|
|
||||||
count.push(0)
|
|
||||||
next
|
|
||||||
end
|
|
||||||
count[count_i] += 1 if solution[i-1] == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
count.delete(0)
|
|
||||||
count.map! do |num|
|
|
||||||
case num
|
|
||||||
when 1
|
|
||||||
2
|
|
||||||
when 2
|
|
||||||
4
|
|
||||||
when 3
|
|
||||||
7
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
p count.reduce(:*)
|
|
|
@ -1,51 +1,27 @@
|
||||||
#!/bin/env ruby
|
#!/bin/env ruby
|
||||||
require 'pry'
|
require 'pry'
|
||||||
def convert (seats)
|
|
||||||
seats.map! do |row|
|
|
||||||
row.map! do |seat|
|
|
||||||
case seat
|
|
||||||
when 0 then 'L'
|
|
||||||
when 1 then '#'
|
|
||||||
when nil then '.'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
row.reduce(:+)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def fill_seats (seats)
|
def fill_seats (seats)
|
||||||
output = Array.new(seats.length, Array.new(seats[0].length, nil))
|
output = Array.new(seats.length, Array.new(seats[0].length, nil))
|
||||||
output.map!.with_index do |row, i|
|
output.map!.with_index do |row, i|
|
||||||
row.map.with_index do |seat, j|
|
row.each.with_index do |seat, j|
|
||||||
next if seats[i][j] == nil
|
next if !seats[i][j]
|
||||||
i == 0 ? row_min = 0 : row_min = i - 1
|
adjecents = 0
|
||||||
i == seats.length - 1 ? row_max = -1 : row_max = i + 1
|
adjecents += seats[i+1][j-1..j+1].compact.sum if i < seats.length - 1
|
||||||
j == 0 ? col_min = 0 : col_min = j - 1
|
adjecents += seats[i][j-1].to_i if j > 0
|
||||||
j == seats[0].length - 1 ? col_max = -1 : col_max = j + 1
|
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
|
||||||
row_range = (row_min..row_max)
|
puts "#{i},#{j}:#{adjecents}"
|
||||||
col_range = (col_min..col_max)
|
adjecents >= 4 ? 0 : 1
|
||||||
adjecents = seats[row_range].map {|line| line[col_range]}.flatten.compact.sum - seats[i][j]
|
|
||||||
combo = {:occupied? => seats[i][j], :adjecents => adjecents}
|
|
||||||
case
|
|
||||||
when combo[:occupied?] == 0 && combo[:adjecents] == 0 then 1
|
|
||||||
when combo[:occupied?] == 0 && combo[:adjecents] != 0 then 0
|
|
||||||
when combo[:occupied?] == 1 && combo[:adjecents] < 4 then 1
|
|
||||||
when combo[:occupied?] == 1 && combo[:adjecents] >= 4 then 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
seats = File.readlines('./input').map(&:strip)
|
seats = File.readlines('./input.sample').map(&:strip)
|
||||||
.map! {|line| line.split('') }
|
.map! {|line| line.split('') }
|
||||||
.map! {|line| line.map { |char| char == 'L' ? 0 : nil }}
|
.map! {|line| line.map { |char| char == 'L' ? 0 : nil }}
|
||||||
|
|
||||||
steps = []
|
#next = fill_seats(seats)
|
||||||
steps[0] = seats
|
binding.pry
|
||||||
until steps[-1] == steps[-2] do
|
|
||||||
steps.push(fill_seats(steps[-1]))
|
|
||||||
end
|
|
||||||
p steps[-1].map(&:compact).flatten.sum
|
|
|
@ -1,51 +0,0 @@
|
||||||
#!/bin/env ruby
|
|
||||||
require 'pry'
|
|
||||||
def convert (seats)
|
|
||||||
seats.map! do |row|
|
|
||||||
row.map! do |seat|
|
|
||||||
case seat
|
|
||||||
when 0 then 'L'
|
|
||||||
when 1 then '#'
|
|
||||||
when nil then '.'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
row.reduce(:+)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def fill_seats (seats)
|
|
||||||
output = Array.new(seats.length, Array.new(seats[0].length, nil))
|
|
||||||
output.map!.with_index do |row, i|
|
|
||||||
row.map.with_index do |seat, j|
|
|
||||||
next if seats[i][j] == nil
|
|
||||||
i == 0 ? row_min = 0 : row_min = i - 1
|
|
||||||
i == seats.length - 1 ? row_max = -1 : row_max = i + 1
|
|
||||||
j == 0 ? col_min = 0 : col_min = j - 1
|
|
||||||
j == seats[0].length - 1 ? col_max = -1 : col_max = j + 1
|
|
||||||
|
|
||||||
row_range = (row_min..row_max)
|
|
||||||
col_range = (col_min..col_max)
|
|
||||||
adjecents = seats[row_range].map {|line| line[col_range]}.flatten.compact.sum - seats[i][j]
|
|
||||||
combo = {:occupied? => seats[i][j], :adjecents => adjecents}
|
|
||||||
case
|
|
||||||
when combo[:occupied?] == 0 && combo[:adjecents] == 0 then 1
|
|
||||||
when combo[:occupied?] == 0 && combo[:adjecents] != 0 then 0
|
|
||||||
when combo[:occupied?] == 1 && combo[:adjecents] < 4 then 1
|
|
||||||
when combo[:occupied?] == 1 && combo[:adjecents] >= 4 then 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return output
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
seats = File.readlines('./input').map(&:strip)
|
|
||||||
.map! {|line| line.split('') }
|
|
||||||
.map! {|line| line.map { |char| char == 'L' ? 0 : nil }}
|
|
||||||
|
|
||||||
steps = []
|
|
||||||
steps[0] = seats
|
|
||||||
until steps[-1] == steps[-2] do
|
|
||||||
steps.push(fill_seats(steps[-1]))
|
|
||||||
end
|
|
||||||
p steps[-1].map(&:compact).flatten.sum
|
|
Loading…
Reference in New Issue