From 408f92c70124a95994ee4756d624bc2268316e21 Mon Sep 17 00:00:00 2001 From: Patrick Michl Date: Fri, 11 Dec 2020 15:15:17 +0100 Subject: [PATCH] rubocop --- day_11/first.rb | 24 +++++++++++++----------- day_11/second.rb | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/day_11/first.rb b/day_11/first.rb index c48b37b..2827859 100644 --- a/day_11/first.rb +++ b/day_11/first.rb @@ -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] diff --git a/day_11/second.rb b/day_11/second.rb index 75ec06b..d180318 100644 --- a/day_11/second.rb +++ b/day_11/second.rb @@ -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