fork(3) download
  1. def f(L,k=1,i=0):
  2. P=[0]*k
  3. for x in L:x=P[i]=P[i]or x;i=(i+x)%k
  4. return P[i]and f(L,k+1)or P
  5.  
  6. for T in [[5,6],[5,7],[5,6,7],[5,6,8],[1,2,3,4],[1,2,1,2],[1,3,5,7],[1,3,5,4]]:
  7. print(T,f(T))
Success #stdin #stdout 0.02s 9936KB
stdin
Standard input is empty
stdout
[5, 6] [5, 6, 0, 0]
[5, 7] [5, 0, 0, 0, 0, 7, 0, 0]
[5, 6, 7] [5, 6, 0, 7]
[5, 6, 8] [5, 0, 8, 0, 0, 6, 0, 0, 0]
[1, 2, 3, 4] [1, 2, 0, 3, 0, 0, 4, 0]
[1, 2, 1, 2] [1, 2, 0, 1, 2, 0, 0]
[1, 3, 5, 7] [1, 3, 0, 0, 5, 0, 0, 0, 0, 7]
[1, 3, 5, 4] [1, 3, 4, 0, 5, 0, 0]