My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update day20.py

+5 -11
+5 -11
2016/day20.py
··· 8 8 """Generator over all allowed IPs given a blacklist.""" 9 9 i = 0 10 10 11 - while i <= max_ip: 12 - if not blacklist: 13 - for n in range(i, max_ip + 1): 14 - yield n 15 - 16 - return 17 - 18 - start, end = blacklist.pop(0) 19 - 11 + for start, end in sorted(blacklist): 20 12 if i < start: 21 13 for n in range(i, start): 22 14 yield n ··· 24 16 if i <= end: 25 17 i = end + 1 26 18 19 + if i <= max_ip: 20 + for n in range(i, max_ip + 1): 21 + yield n 22 + 27 23 28 24 if __name__ == '__main__': 29 25 blacklist = [] ··· 31 27 for line in fileinput.input(): 32 28 start, end = parse_line(r'(\d+)-(\d+)', line) 33 29 blacklist.append((start, end)) 34 - 35 - blacklist.sort() 36 30 37 31 whitelist = list(allowed_ips(blacklist)) 38 32