AdventOfCode/2017/17/solution.py

78 lines
1.6 KiB
Python
Raw Normal View History

2024-11-26 19:42:34 +01:00
#!/bin/python3
import sys,re
from pprint import pprint
sys.path.insert(0, '../../')
from fred import list2int
input_f = 'input'
part = 2
#########################################
# #
# Part 1 #
# #
#########################################
if part == 1:
jump = 0
arr = [0]
pos = 0
with open(input_f) as file:
jump = int(file.read().rstrip())
for i in range(1,2017+1):
#print(arr)
#print(len(arr),i)
pos = (pos+jump)%len(arr)
loc = (pos)+1
#print(loc)
pos += 1
arr.insert(loc,i)
#input()
f_pos = arr.index(2017)
print(arr[f_pos-1],arr[f_pos],arr[f_pos+1])
#########################################
# #
# Part 2 #
# #
#########################################
if part == 2:
jump = 0
arr = [0]
pos = 0
loc = 0
with open(input_f) as file:
jump = int(file.read().rstrip())
prev = 0
for i in range(1,50000000+1):
#print(arr)
#print(len(arr),i)
pos = (pos+jump)%i
loc = (pos)+1
#print(loc)
pos += 1
#arr.insert(loc,i)
#input()
if i%1000000 == 0:
print(i)
if pos == 1:
#print('INSERT')
prev = i
#print(i-1)
#print(pos,loc)
print(prev)
#f_pos = arr.index(0)
#print(arr[f_pos-1],arr[f_pos],arr[f_pos+1])