17_spinlock.py 371 B

1234567891011121314151617
  1. #!/usr/bin/env python3
  2. from collections import deque
  3. def spin(inserts, steps):
  4. buf = deque([0])
  5. for i in range(1, inserts + 1):
  6. buf.rotate(-(steps % len(buf) + 1))
  7. buf.appendleft(i)
  8. return buf
  9. def after_zero(buf):
  10. while buf.popleft() != 0:
  11. pass
  12. return buf[0]
  13. print(spin(2017, 386)[1])
  14. print(after_zero(spin(50000000, 386)))