adding to git what I have
This commit is contained in:
41
2024/09/09.py
Normal file
41
2024/09/09.py
Normal 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
1
2024/09/input09.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user