Solution to problem 10 part 1 in Python
This commit is contained in:
parent
8bc6366c5a
commit
e6043bf326
|
@ -82,9 +82,10 @@ with open("files/P10.txt") as f:
|
|||
def simulated_hash(circle: Deque[int], sequence: list) -> Deque[int]:
|
||||
curr_pos, skip = 0, 0
|
||||
for length in sequence:
|
||||
# reverse the order of the partial list starting from curr_pos
|
||||
circle.rotate(-curr_pos)
|
||||
# creates a copy of the list
|
||||
rotated_l = list(circle)
|
||||
# reverse the order of the partial list
|
||||
rotated_l[:length] = reversed(rotated_l[:length])
|
||||
# as the list is circular, it wraps around when it has to
|
||||
circle = deque(rotated_l)
|
||||
|
@ -97,9 +98,9 @@ def simulated_hash(circle: Deque[int], sequence: list) -> Deque[int]:
|
|||
|
||||
def part_1() -> None:
|
||||
list_of_numbers = deque(list(range(256)))
|
||||
|
||||
simulated_hash_res = simulated_hash(list_of_numbers, lengths)
|
||||
res = simulated_hash_res[0] * simulated_hash_res[1]
|
||||
|
||||
print(f"The result is {res}")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue