3-2 fertig
This commit is contained in:
45
03/03-02.py
Normal file
45
03/03-02.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
|
# parse input
|
||||||
|
input_file = open("input", "r")
|
||||||
|
for line in input_file:
|
||||||
|
line = line.strip()
|
||||||
|
data.append(line)
|
||||||
|
input_file.close()
|
||||||
|
|
||||||
|
badges = []
|
||||||
|
for i in range(0, len(data)-2, 3):
|
||||||
|
# print(data[i], data[i+1], data[i+2])
|
||||||
|
r1 = data[i]
|
||||||
|
r2 = data[i+1]
|
||||||
|
r3 = data[i+2]
|
||||||
|
r = ""
|
||||||
|
if len(r1) > len(r2):
|
||||||
|
r = r1
|
||||||
|
else:
|
||||||
|
r = r2
|
||||||
|
if len(r3) > len(r):
|
||||||
|
r = r3
|
||||||
|
# print(r)
|
||||||
|
for j in range(len(r)):
|
||||||
|
if r[j] in r1 and r[j] in r2 and r[j] in r3:
|
||||||
|
badges.append(r[j])
|
||||||
|
break
|
||||||
|
|
||||||
|
print(badges)
|
||||||
|
|
||||||
|
solution = 0
|
||||||
|
for b in badges:
|
||||||
|
if 96 < ord(b) < 123:
|
||||||
|
print(ord(b)-96)
|
||||||
|
solution += ord(b)-96
|
||||||
|
elif 64 < ord(b) < 91:
|
||||||
|
print(ord(b)-64+26)
|
||||||
|
solution += ord(b)-64+26
|
||||||
|
else:
|
||||||
|
print("Fehler")
|
||||||
|
|
||||||
|
print("Lösung 2:", solution)
|
||||||
Reference in New Issue
Block a user