-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (42 loc) · 1.78 KB
/
main.py
File metadata and controls
57 lines (42 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
import argparse
def state(coordinates, sorted_coordinates):
for coord in sorted_coordinates:
print(coordinates[coord], end=" ")
print()
def main(input_file, stage=1):
decryption_key = 1 if stage == 1 else 811589153
with open(input_file) as file:
coordinates = {idx: int(coordinate.strip()) * decryption_key for idx, coordinate in enumerate(file.readlines())}
coords = list(coordinates.keys())
for _ in range(1 if stage == 1 else 10):
for coord in coordinates.keys():
curr = coords.index(coord)
new_pos = (curr + coordinates[coord]) % (len(coords)-1)
coords.pop(curr)
coords.insert(new_pos, coord)
for i in range(len(coords)):
coords[i] = coordinates[coords[i]]
#print(coords)
grove_coordinates = 0
zero = coords.index(0)
for i in [1000, 2000, 3000]:
grove_coordinates += coords[(zero + i) % len(coords)]
print(grove_coordinates)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog='main',
description='AdventOfCode main skeleton',
)
parser.add_argument("-e", "--example", action=argparse.BooleanOptionalAction, default=False, help="Set if you want to run the example")
parser.add_argument("-s", "--stage", action='store', default=0, help="Pass the stage you want to run", type=int)
args = parser.parse_args()
file_name = "example" if args.example else "input"
if args.stage == 1 or args.stage == 0:
start_time = time.time()
main(file_name, 1)
print(f"Stage 1 time: {time.time()-start_time:.10f}")
if args.stage == 2 or args.stage == 0:
start_time = time.time()
main(file_name, 2)
print(f"Stage 2 time: {time.time()-start_time:.10f}")