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.

Fix bug in day07.py

+19 -11
+19 -11
2016/day07.py
··· 18 18 yield a, b 19 19 20 20 21 - tls_ips = 0 22 - ssl_ips = 0 21 + def parse_address(address): 22 + runs = re.findall(r'(\w+)', address.strip()) 23 + return runs[::2], runs[1::2] 23 24 24 - for line in fileinput.input(): 25 - runs = re.findall(r'(\w+)', line.strip()) 26 25 27 - sequences = runs[0::2] 28 - hypernets = runs[1::2] 26 + def supports_tls(address): 27 + sequences, hypernets = parse_address(address) 29 28 30 29 if any(is_abba(s) for s in sequences): 31 30 if not any(is_abba(h) for h in hypernets): 32 - tls_ips += 1 31 + return True 32 + 33 + return False 34 + 35 + 36 + def supports_ssl(address): 37 + sequences, hypernets = parse_address(address) 33 38 34 39 for seq in sequences: 35 40 for a, b in find_abas(seq): 36 41 bab = b + a + b 37 42 38 43 if any(bab in h for h in hypernets): 39 - ssl_ips += 1 40 - break 44 + return True 45 + 46 + return False 47 + 41 48 42 - print "Number of TLS IPs: %i" % tls_ips 43 - print "Number of SSL IPs: %i" % ssl_ips 49 + ADDRESSES = [line.strip() for line in fileinput.input()] 50 + print "Number of TLS IPs: %i" % sum(supports_tls(a) for a in ADDRESSES) 51 + print "Number of SSL IPs: %i" % sum(supports_ssl(a) for a in ADDRESSES)