daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Dec 15th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### For part 1, remove while loops in genA() and genB()
  2. ### and change the for loop to 40 million
  3.  
  4. def genA(seed1):
  5.     seed1 *= 16807
  6.     seed1 = seed1 % 2147483647
  7.     while(seed1 % 4):
  8.         seed1 *= 16807
  9.         seed1 = seed1 % 2147483647
  10.     return seed1
  11.  
  12. def genB(seed2):
  13.     seed2 *= 48271
  14.     seed2 = seed2 % 2147483647
  15.     while(seed2 % 8):
  16.         seed2 *= 48271
  17.         seed2 = seed2 % 2147483647
  18.     return seed2
  19.  
  20. def bitgen(seed1,seed2):
  21.     while True:
  22.         seed1 = genA(seed1)
  23.         seed2 = genB(seed2)
  24.         mseed1 = seed1 & 0xFFFF
  25.         mseed2 = seed2 & 0xFFFF
  26.         yield mseed1 ^ mseed2
  27. #g = bitgen(65,8921)
  28. g = bitgen(516,190)
  29. print(sum([not next(g) for x in range(5000000)]))
RAW Paste Data
Top