daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2. from collections import deque
  3.  
  4. with open('9.txt', 'r') as file:
  5.     data = file.readline()
  6.     m = re.match(r'(\d+)\D+(\d+)', data)
  7.     players, last_marble = int(m[1]), int(m[2])
  8.  
  9.  
  10. PLAYER_NUM = players
  11. LAST_MARBLE = last_marble * 100
  12.  
  13. marbles = deque([0])
  14. scores = [0] * PLAYER_NUM
  15.  
  16. for marble in range(1, LAST_MARBLE+1):
  17.     if marble % 23 == 0:
  18.         marbles.rotate(7)
  19.         scores[marble % PLAYER_NUM] += marble + marbles.pop()
  20.         marbles.rotate(-1)
  21.     else:
  22.         marbles.rotate(-1)
  23.         marbles.append(marble)
  24.  
  25. # print(marbles)
  26. # print(players)
  27. print(max(scores))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top