2018 day 2

This commit is contained in:
dece 2020-11-16 16:36:46 +01:00
parent a6491289a7
commit 50eee15a8a
3 changed files with 38 additions and 0 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
day*.txt
venv/

30
2018/day2.py Normal file
View file

@ -0,0 +1,30 @@
def main():
with open("day2.txt", "rt") as f:
lines = [line.rstrip() for line in f.readlines()]
n2 = 0
n3 = 0
for line in lines:
occurences = [line.count(letter) for letter in line]
if 2 in occurences:
n2 += 1
if 3 in occurences:
n3 += 1
print(n2 * n3)
for line in lines:
for other in lines:
diffs = 0
common = ""
for c1, c2 in zip(line, other):
if c1 == c2:
common += c1
else:
diffs += 1
if diffs == 1:
print(common)
return
if __name__ == "__main__":
main()

7
2018/skel.py.txt Normal file
View file

@ -0,0 +1,7 @@
def main():
with open("", "rt") as f:
lines = [line.rstrip() for line in f.readlines()]
if __name__ == "__main__":
main()