Compare commits
2 commits
8b035ab9b6
...
2bfcdf0956
Author | SHA1 | Date | |
---|---|---|---|
dece | 2bfcdf0956 | ||
dece | 958cc852f3 |
27
2020/day2.py
Normal file
27
2020/day2.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
def main():
|
||||||
|
with open("day2.txt", "rt") as f:
|
||||||
|
lines = [line.rstrip() for line in f.readlines()]
|
||||||
|
# Part 1
|
||||||
|
valid = 0
|
||||||
|
for line in lines:
|
||||||
|
count, letter, password = line.split()
|
||||||
|
min_n, max_n = count.split("-")
|
||||||
|
letter = letter.rstrip(":")
|
||||||
|
if int(min_n) <= password.count(letter) <= int(max_n):
|
||||||
|
valid += 1
|
||||||
|
print("Valids:", valid)
|
||||||
|
# Part 2
|
||||||
|
valid = 0
|
||||||
|
for line in lines:
|
||||||
|
count, letter, password = line.split()
|
||||||
|
ofs_a, ofs_b = count.split("-")
|
||||||
|
letter = letter.rstrip(":")
|
||||||
|
a = password[int(ofs_a) - 1]
|
||||||
|
b = password[int(ofs_b) - 1]
|
||||||
|
if (a == letter or b == letter) and not (a == b == letter):
|
||||||
|
valid += 1
|
||||||
|
print("Valids:", valid)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
19
2020/new.py
Executable file
19
2020/new.py
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
TEMPLATE = """
|
||||||
|
def main():
|
||||||
|
with open("{}", "rt") as f:
|
||||||
|
lines = [line.rstrip() for line in f.readlines()]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
"""
|
||||||
|
|
||||||
|
day = date.today().day
|
||||||
|
with open(f"day{day}.py", "wt") as f:
|
||||||
|
f.write(TEMPLATE.format(f"day{day}.txt"))
|
||||||
|
os.system(f"python ../fetch.py {day}")
|
|
@ -1,7 +0,0 @@
|
||||||
def main():
|
|
||||||
with open("", "rt") as f:
|
|
||||||
lines = [line.rstrip() for line in f.readlines()]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Loading…
Reference in a new issue