initial commit
This commit is contained in:
commit
27fe77bbe1
134 changed files with 21939 additions and 0 deletions
46
2020/Day7/main.py
Normal file
46
2020/Day7/main.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
def getParent(color):
|
||||
for i in raw:
|
||||
primcolor, others = i.split(" contain ")
|
||||
|
||||
others = others.split(", ")
|
||||
for j in range(0, len(others)):
|
||||
others[j] = others[j].replace(others[j][:2], "")
|
||||
if color in others:
|
||||
if primcolor not in containGold:
|
||||
containGold.append(primcolor)
|
||||
getParent(primcolor)
|
||||
|
||||
|
||||
def getChilds(color):
|
||||
result = 0
|
||||
for i in raw:
|
||||
primcolor, others = i.split(" contain ")
|
||||
|
||||
if primcolor == color:
|
||||
others = others.split(", ")
|
||||
for j in range(0, len(others)):
|
||||
times = others[j][:2]
|
||||
if times == "no":
|
||||
result = 1
|
||||
else:
|
||||
others[j] = others[j].replace(times, "")
|
||||
result += int(times) * getChilds(others[j])
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
containGold = []
|
||||
GoldContains = 0
|
||||
with open("input.txt") as f:
|
||||
raw = f.read().split("\n")
|
||||
|
||||
for i in range(0, len(raw)):
|
||||
raw[i] = raw[i].replace(" bags", "").replace(" bag", "").replace(".", "")
|
||||
|
||||
getParent("shiny gold")
|
||||
|
||||
print("Aufgabe 1:", len(containGold))
|
||||
|
||||
GoldContains = getChilds("shiny gold")
|
||||
print("Aufgabe 2:", GoldContains+1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue