incomplete state of day 9 - step 2
This commit is contained in:
parent
11848d268b
commit
b7ea34fd2b
1 changed files with 23 additions and 9 deletions
|
|
@ -12,30 +12,44 @@ def get_lines(filename: str) -> list:
|
|||
|
||||
def get_disk(disk_map: str) -> tuple:
|
||||
disk = []
|
||||
free_blocks = deque()
|
||||
full_blocks = deque()
|
||||
free_blocks = deque()
|
||||
file_id = 0
|
||||
head_pos = 0
|
||||
for pos, count_str in enumerate(disk_map):
|
||||
count = int(count_str)
|
||||
for i in range(count):
|
||||
if pos % 2 == 0:
|
||||
if pos % 2 == 0:
|
||||
for i in range(count):
|
||||
disk.append(file_id)
|
||||
else:
|
||||
full_blocks.append(head_pos)
|
||||
head_pos += 1
|
||||
file_id += 1
|
||||
else:
|
||||
for i in range(count):
|
||||
disk.append(None)
|
||||
free_blocks.append(head_pos)
|
||||
head_pos += 1
|
||||
return disk, free_blocks, full_blocks
|
||||
|
||||
|
||||
def print_disk(disk: list) -> None:
|
||||
pass
|
||||
for pos in disk:
|
||||
if pos is None:
|
||||
print(".", end="")
|
||||
else:
|
||||
print(pos, end="")
|
||||
print()
|
||||
|
||||
def main():
|
||||
# disk_map = get_lines("sample-input.txt")[0]
|
||||
disk_map = get_lines("sample-input2.txt")[0]
|
||||
disk_map = get_lines("sample-input.txt")[0]
|
||||
# disk_map = get_lines("sample-input2.txt")[0]
|
||||
# disk_map = get_lines("input.txt")[0]
|
||||
|
||||
disk, free_blocks, full_blocks = get_disk(disk_map)
|
||||
print(disk)
|
||||
|
||||
print_disk(disk)
|
||||
print(free_blocks)
|
||||
print(full_blocks)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue