about summary refs log tree commit diff
path: root/day23.rb
blob: d9463760818f1e0a033f85dc149f9c0096523fac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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