rubocop
This commit is contained in:
parent
f26768a7a7
commit
408f92c701
@ -1,17 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
input = File.readlines('./input').map(&:strip).map(&:chars)
|
||||
|
||||
$dirs = [
|
||||
[-1,-1],
|
||||
[-1,0],
|
||||
[-1,1],
|
||||
[0,-1],
|
||||
[0,1],
|
||||
[1,-1],
|
||||
[1,0],
|
||||
[1,1]
|
||||
[-1, -1],
|
||||
[-1, 0],
|
||||
[-1, 1],
|
||||
[0, -1],
|
||||
[0, 1],
|
||||
[1, -1],
|
||||
[1, 0],
|
||||
[1, 1]
|
||||
]
|
||||
|
||||
|
||||
def round(map)
|
||||
output = []
|
||||
map.each_index do |row|
|
||||
@ -21,8 +22,9 @@ def round(map)
|
||||
x_index = row + x
|
||||
y_index = col + y
|
||||
|
||||
next nil if x_index < 0 || y_index < 0
|
||||
map[row+x]&.[](col+y)
|
||||
next nil if x_index.negative? || y_index.negative?
|
||||
|
||||
map[row + x]&.[](col + y)
|
||||
end
|
||||
occupied = tmp.compact.count('#')
|
||||
output[row][col] = case [map[row][col], occupied]
|
||||
|
@ -1,17 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
input = File.readlines('./input').map(&:strip).map(&:chars)
|
||||
|
||||
$dirs = [
|
||||
[-1,-1],
|
||||
[-1,0],
|
||||
[-1,1],
|
||||
[0,-1],
|
||||
[0,1],
|
||||
[1,-1],
|
||||
[1,0],
|
||||
[1,1]
|
||||
[-1, -1],
|
||||
[-1, 0],
|
||||
[-1, 1],
|
||||
[0, -1],
|
||||
[0, 1],
|
||||
[1, -1],
|
||||
[1, 0],
|
||||
[1, 1]
|
||||
]
|
||||
|
||||
|
||||
def round(map)
|
||||
output = []
|
||||
map.each_index do |row|
|
||||
@ -22,11 +23,13 @@ def round(map)
|
||||
y_index = col + y
|
||||
|
||||
char = loop do
|
||||
break nil if x_index < 0 || y_index < 0 || x_index >= map.size || y_index >= map[row].size
|
||||
break nil if x_index.negative? || y_index.negative? || x_index >= map.size || y_index >= map[row].size
|
||||
|
||||
char = map[x_index]&.[](y_index)
|
||||
x_index += x
|
||||
y_index += y
|
||||
next if char == '.'
|
||||
|
||||
break char
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user