Skip to content

Commit

Permalink
Optimized code, faster
Browse files Browse the repository at this point in the history
If we store in memory len(list) we can run this algorithm too much faster.
  • Loading branch information
mondeja authored Nov 2, 2017
1 parent bf2b096 commit 93eab61
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion array/circular_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
def josepheus(int_list, skip):
skip = skip - 1 #list starts with 0 index
idx = 0
while len(int_list)>0:
len_list(len(int_list))
while len_list>0:
idx = (skip+idx)%len(int_list) #hashing to keep changing the index to every 3rd
print(int_list.pop(idx))
len_list -= 1


josepheus(a,3)
Expand Down

0 comments on commit 93eab61

Please sign in to comment.