diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-17 20:42:29 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-17 20:42:29 +0000 |
commit | 5a13478012d0968eec24e1962153886f512a6ee2 (patch) | |
tree | 0507bab054095686b3f6cfd001d21808fcfe5052 | |
parent | b2ab1dda5fedd20b05ec2fa10b4a2af8196465dc (diff) | |
download | aoc2021-5a13478012d0968eec24e1962153886f512a6ee2.tar.gz aoc2021-5a13478012d0968eec24e1962153886f512a6ee2.tar.xz aoc2021-5a13478012d0968eec24e1962153886f512a6ee2.zip |
day 17: faster again
-rw-r--r-- | 17.py | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -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) |