From e12436c99bb04897d6344b6351d0336e4c627573 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 28 Nov 2019 17:38:10 +0100 Subject: add rest --- day23.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 day23.rb (limited to 'day23.rb') diff --git a/day23.rb b/day23.rb new file mode 100644 index 0000000..d946376 --- /dev/null +++ b/day23.rb @@ -0,0 +1,21 @@ +file = File.read("day23") + +bots = file.lines.map { |l| + l.scan(/<(-?\d+),(-?\d+),(-?\d+)>.*r=(-?\d+)/).first.map(&:to_i) +} + +strongest = bots.max_by { |x,y,z,w| w } + +p bots.count { |x,y,z,w| + ((x-strongest[0]).abs + + (y-strongest[1]).abs + + (z-strongest[2]).abs) <= strongest[3] +} # 577 + + +p bots.map { |b| b[0] }.sum +p bots.map { |b| b[1] }.sum +p bots.map { |b| b[2] }.sum + +# 16933511,19092135,15403726 +# 51429372 -- cgit 1.4.1