Skip to content

Commit 93eab61

Browse files
authored
Optimized code, faster
If we store in memory len(list) we can run this algorithm too much faster.
1 parent bf2b096 commit 93eab61

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

array/circular_counter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
def josepheus(int_list, skip):
1515
skip = skip - 1 #list starts with 0 index
1616
idx = 0
17-
while len(int_list)>0:
17+
len_list(len(int_list))
18+
while len_list>0:
1819
idx = (skip+idx)%len(int_list) #hashing to keep changing the index to every 3rd
1920
print(int_list.pop(idx))
21+
len_list -= 1
2022

2123

2224
josepheus(a,3)

0 commit comments

Comments
 (0)