From 0ba970d5177ee8d3e8810f90f189b48e74c0c493 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 4 Dec 2020 21:52:45 -0800 Subject: [PATCH] Clean up day 5. --- day5.cr | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/day5.cr b/day5.cr index 9c13978..9e91049 100644 --- a/day5.cr +++ b/day5.cr @@ -14,32 +14,23 @@ end def get_id(str) col = str[0..6] row = str[7..] - {partition(col, (0..127).to_a)[0], partition(row, (0..7).to_a)[0]} + id({partition(col, (0..127).to_a)[0], partition(row, (0..7).to_a)[0]}) end def id(t) - r, c = t - r * 8 + c + t[0]*8 + t[1] end def part1 input = INPUT.clone - max = input.max_of do |line| - r, c = get_id(line) - r * 8 + c - end - puts max + puts(input.max_of &->get_id(String)) end def part2 input = INPUT.clone - seen = Set(Int32).new - max = input.each do |line| - seen << id(get_id(line)) - end + seen = input.map &->get_id(String) candidates = [] of Int32 128.times do |r| - next if r == 0 || r == 127 8.times do |c| next if seen.includes? id({r, c}) candidates << id({r,c})