adding to git what I have

This commit is contained in:
Aris
2024-12-09 10:59:37 +01:00
parent d2d7b76638
commit 6dace2f0c1
4 changed files with 131 additions and 0 deletions

41
2024/09/09.py Normal file
View File

@@ -0,0 +1,41 @@
import copy
def checksum(diskdump):
out = 0
for i in range(0,len(diskdump)):
if diskdump[i] == ".":
return out
else:
out += diskdump[i]*i
def abstToDump(abst):
dump = []
flag = True
i = 0
for a in abst:
for j in range(0,int(a)):
dump.append(i if flag else -1)
flag = not flag
i += 1 if not flag else 0
return dump
def orderDump(dump):
arr = ["."]*len(dump)
i = 0
for a in dump:
if a == -1:
if dump[-1] != -1:
arr[i] = dump[-1]
i += 1
else:
pass
dump.pop(-1)
else:
arr[i] = a
i += 1
return arr
with open("input09.txt","r") as f:
dump = abstToDump(f.read())
order = orderDump(copy.deepcopy(dump))
print(checksum(order))

1
2024/09/input09.txt Normal file

File diff suppressed because one or more lines are too long