Compare commits
No commits in common. "2bfcdf09560081fc3a20abedc2e0bb0b05eae86e" and "8b035ab9b69c0a9e638a858a97dbe7c94032582b" have entirely different histories.
2bfcdf0956
...
8b035ab9b6
27
2020/day2.py
27
2020/day2.py
|
@ -1,27 +0,0 @@
|
||||||
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
19
2020/new.py
|
@ -1,19 +0,0 @@
|
||||||
#!/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}")
|
|
7
2020/skel.py.txt
Normal file
7
2020/skel.py.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
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