[Python/2016] Move solutions into .py files
This commit is contained in:
parent
0269ad8fc3
commit
2514b1d11f
50 changed files with 1172 additions and 3386 deletions
22
Python/2016/04.py
Normal file
22
Python/2016/04.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2016, 4)
|
||||
|
||||
|
||||
out = 0
|
||||
|
||||
for room in input.splitlines():
|
||||
name, sector, checksum = re.match(r"^([a-z\-]+)-(\d+)\[([a-z]+)\]$", room).groups()
|
||||
|
||||
if [*checksum] == [a[0] for a in sorted(Counter(name.replace("-", "")).items(), key=lambda a: (-a[1], a[0]))[:5]]:
|
||||
out += int(sector)
|
||||
|
||||
print(out)
|
||||
for room in input.splitlines():
|
||||
name, sector = re.match(r"^([a-z\-]+)-(\d+)\[[a-z]+\]$", room).groups()
|
||||
|
||||
name = "".join(chr((ord(c) - 0x61 + int(sector)) % 26 + 0x61) if c != "-" else " " for c in name)
|
||||
|
||||
if "north" in name:
|
||||
print(sector)
|
||||
break
|
Loading…
Add table
Add a link
Reference in a new issue