day 13 p1

This commit is contained in:
2022-12-13 18:18:39 +02:00
parent f288097f2b
commit 279e82054e

64
13/m.py Normal file
View File

@@ -0,0 +1,64 @@
import os
import ast
input = open(os.path.dirname(__file__) +
"/input.txt", "r").read().split('\n\n')
correct = []
def compare(a, b):
compa = a
compb = b
typea = type(a)
typeb = type(b)
print(">> compare", a, b)
res = 0
if typea == int and typeb == int:
print("int comparison", a, b)
if a < b:
res = 1
elif a == b:
res = 0
else:
res = -1
if typea == list and typeb == list:
while res == 0:
if len(a) == 0 and len(b) == 0:
print("both lists are empty, continue")
res = 0
break
elif len(a) == 0:
print("left out, TRUE")
res = 1
break
elif len(b) == 0:
print("right out, FALSE")
res = -1
break
print("res", res, "len a", len(a), "len b", len(b))
res = compare(a.pop(0), b.pop(0))
if (typea == int and typeb == list):
res = compare([a], b)
if (typeb == int and typea == list):
res = compare(a, [b])
return res
for idx, i in enumerate(input):
print(">>> IDX:", idx+1)
a, b = i.split('\n')
a = ast.literal_eval(a)
b = ast.literal_eval(b)
print("a:", a, "b:", b)
if compare(a, b) == 1:
correct.append(idx+1)
print(correct)
print(sum(correct))