aoc2017-day13-2

Run Settings
LanguagePython
Language Version
Run Command
import sys import re def parse_firewalls(inputf): return ([int(__) for __ in _.split()] for _ in (re.sub("[:]", " ", _) for _ in (_.strip() for _ in iter(inputf)) if _)) def scanner_pos(tick, depth): x = depth - 1 return x - abs(x - tick % (2*x)) def positions(tick, firewalls): return ((_, scanner_pos(tick + _[0], _[1])) for _ in firewalls) def collisions(tick, firewalls, pos): return ((f, p == pos) for f, p in positions(tick, firewalls) if p == pos) def has_next(seq): return next((True for _ in seq), False) def gen_range(start, stop=None): while stop == None or start < stop: yield start start += 1 def find_delay(firewalls, pos): return next((_ for _, col in ((_, has_next(collisions(_, firewalls, pos))) for _ in gen_range(0)) if not col), None) with sys.stdin as f: firewalls = list(parse_firewalls(f)) print(find_delay(firewalls, 0))
Editor Settings
Theme
Key bindings
Full width
Lines