[Python/2016] Move solutions into .py files

This commit is contained in:
Felix Bargfeldt 2023-10-29 12:38:12 +01:00
parent 0269ad8fc3
commit 2514b1d11f
Signed by: Defelo
GPG key ID: 2A05272471204DD3
50 changed files with 1172 additions and 3386 deletions

22
Python/2016/04.py Normal file
View 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