From 2c6235013e624bba8077f45fb9dec44acc85bc37 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Wed, 12 Dec 2018 11:20:49 +1030 Subject: [PATCH] Vectorised Part 2 2018 Day 11 SAT --- 2018/day11-cleaned.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/2018/day11-cleaned.py b/2018/day11-cleaned.py index 54c981e..8274383 100644 --- a/2018/day11-cleaned.py +++ b/2018/day11-cleaned.py @@ -39,10 +39,15 @@ max_power_s = 0 max_idx_s = (0,0,0) for x in range(1, 298): for y in range(1, 298): - for s in range(4, 302-max(x, y)): - val = sum_square(x, y, s) - if val > max_power_s: - max_power_s = val - max_idx_s = (x, y, s) + A = fuel_cs[x-1, y-1] + Ds = fuel_cs[x+3:, y+3:].diagonal() + Bs = fuel_cs[x+3:, y-1][:len(Ds)] + Cs = fuel_cs[x-1, y+3:][:len(Ds)] + sums = Ds - Cs - Bs + A + idx = sums.argmax() + val = sums[idx] + if val > max_power_s: + max_power_s = val + max_idx_s = (x, y, 4+idx) print(max_idx_s) # Part 2