2024(9): WIP part2
This commit is contained in:
@ -23,31 +23,61 @@ def move_files_ltr_to_empty_space(files: list) -> str:
|
||||
|
||||
while left < right:
|
||||
if not "." in files[left]:
|
||||
#print("if ", end=" ")
|
||||
left += 1
|
||||
# TODO: Shouldn't we take care of this in the partial block?
|
||||
elif len(files[right]) == 0:
|
||||
del(files[right])
|
||||
elif "." in files[right] \
|
||||
or files[left].count(".") < len(files[right]):
|
||||
right -= 1
|
||||
#print("elif", end=" ")
|
||||
# fully swap
|
||||
elif files[left].count(".") == len(files[right]):
|
||||
#print("part", end=" ")
|
||||
tmp = files[left]
|
||||
files[left] = files[right]
|
||||
files[right] = tmp
|
||||
|
||||
# Restart trying from the right
|
||||
right = len(files) - 1
|
||||
|
||||
# TODO: Concatenate empty space
|
||||
# partially swap
|
||||
else:
|
||||
#print("part", end=" ")
|
||||
#print(left, right)
|
||||
#print(files[left], files[right])
|
||||
#print("." in files[right])
|
||||
#print(files[right])
|
||||
tmp = files[left]
|
||||
files[left] = files[right]
|
||||
files.insert(left + 1, tmp[:-len(files[right])])
|
||||
files[right] = tmp[len(files[right])]
|
||||
idx_right_after_insertion = right + 1
|
||||
files[idx_right_after_insertion] = tmp[:len(files[idx_right_after_insertion])]
|
||||
if len(files[idx_right_after_insertion]) == 0:
|
||||
#print("deleting")
|
||||
del(files[idx_right_after_insertion])
|
||||
#print("RIGHT: ", files[right])
|
||||
|
||||
# Restart trying from the right
|
||||
right = len(files) - 1
|
||||
|
||||
if verbose:
|
||||
print(files)
|
||||
print(files_to_blocks(files))
|
||||
#print(files)
|
||||
|
||||
return files
|
||||
|
||||
def files_to_blocks(files: list) -> str:
|
||||
ret = ""
|
||||
for f in files:
|
||||
print(f)
|
||||
return sum(files)
|
||||
ret += "".join(f)
|
||||
#print(f)
|
||||
return ret
|
||||
# return ["".join(file) for file in files]
|
||||
|
||||
#def blocks_to_str
|
||||
|
||||
if __name__ == "__main__":
|
||||
disk_map = load_disk_map("testinput")
|
||||
@ -59,7 +89,8 @@ if __name__ == "__main__":
|
||||
files = disk_map_to_files(disk_map)
|
||||
if verbose:
|
||||
print("Files:")
|
||||
print(files)
|
||||
#print(files)
|
||||
print(files_to_blocks(files))
|
||||
|
||||
result = move_files_ltr_to_empty_space(files)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user