From 5a13478012d0968eec24e1962153886f512a6ee2 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 17 Dec 2021 20:42:29 +0000 Subject: day 17: faster again --- 17.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/17.py b/17.py index be5bccb..ebe3116 100644 --- a/17.py +++ b/17.py @@ -1,6 +1,7 @@ from math import sqrt, ceil, floor from utils import parse_day from collections import defaultdict +from itertools import chain tx_min, tx_max, ty_min, ty_max = \ map(int, parse_day(17, r'.* x=(-?\d+)..(-?\d+), y=(-?\d+)..(-?\d+)')) @@ -39,11 +40,10 @@ for vy0 in range(vy_min, vy_max + 1): tmin, tmax = y_times(vy0) for t in range(tmin, tmax + 1): times[t].add(vy0) -points = set() +count = 0 for vx0 in range(vx_min, vx_max + 1): tmin, tmax = x_times(vx0) - for t, vy0set in times.items(): - if tmin <= t <= tmax: - for vy0 in vy0set: - points.add((vx0, vy0)) -print(len(points)) + count += len(set(chain.from_iterable( + vy0set for t, vy0set in times.items() if tmin <= t <= tmax + ))) +print(count) -- cgit v1.2.3-54-g00ecf