#advent of code 2018 #day 09 #part 1 and part 2 from collections import deque import time #parsing input is hardcoded for 1st and 7th word in text f = open("input.txt", 'r'); inputline = f.readline().split(); playercount = int(inputline[0]); #input1 lastmarble = int(inputline[6]); #input2 testinput = False; if testinput: playercount = 30; # 09 / 10 / 13 / 17 / 21 / 30 lastmarble = 5807; # 25 / 1618 / 7999 / 1104 / 6111 / 5807 # 32 / 8317 / 146373 / 2764 / 54718 / 37305 def MarbleGame(playercount, lastmarble): playerlist = []; player = 1; for p in range(playercount+1): playerlist.append(0); marblelist = deque([0]); for m in range(1, lastmarble+1): if(m%23==0): playerlist[player] += m; marblelist.rotate(7); playerlist[player] += marblelist.pop(); marblelist.rotate(-1); else: marblelist.rotate(-1); marblelist.append(m); player +=1; if (player > playercount): player = 1; p1 = max(playerlist); return p1; t1 = time.time(); part1 = MarbleGame(playercount, lastmarble); part2 = MarbleGame(playercount, lastmarble*100); t2 = time.time(); print("part 1 = ", part1); print("part 2 = ", part2); print("runtime ", round(t2-t1,3), " sec");