From 6935393e9c9841f7ae418b235b5c9e0f22418116 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 28 Oct 2019 22:59:09 +0000 Subject: day 18, part2. part2 is just another uninteresting now do it an impossible number of times type puzzle --- day18/part1 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 day18/part1 (limited to 'day18/part1') diff --git a/day18/part1 b/day18/part1 new file mode 100755 index 0000000..d17faed --- /dev/null +++ b/day18/part1 @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby + +def adj(arr, r, c) + a = [] + + a << arr[r-1][c-1] if r > 0 && c > 0 + a << arr[r-1][c ] if r > 0 + a << arr[r-1][c+1] if r > 0 && c < 49 + a << arr[r ][c-1] if c > 0 + a << arr[r ][c+1] if c < 49 + a << arr[r+1][c-1] if r < 49 && c > 0 + a << arr[r+1][c ] if r < 49 + a << arr[r+1][c+1] if r < 49 && c < 49 + + a +end + +now = $stdin.readlines.map(&:strip).map{|x|x.split("")} +nxt = [] + +10.times do + 50.times do |r| + nxtr = [] + 50.times do |c| + a = adj(now, r, c) + nxtr << case now[r][c] + when "." + if a.count("|") >= 3 then + "|" + else + "." + end + when "|" + if a.count("#") >= 3 then + "#" + else + "|" + end + when "#" + if a.count("#") > 0 && a.count("|") > 0 then + "#" + else + "." + end + end + end + nxt << nxtr + end + + now = nxt + nxt = [] +end + +puts now.flatten.count("|") * now.flatten.count("#") -- cgit v1.2.1