diff options
| author | Shimon Bollinger <deoac.bollinger@gmail.com> | 2023-10-01 00:01:15 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-01 00:01:15 -0400 |
| commit | 859530783c2761fd736a0370c8cecb066a33ef3f (patch) | |
| tree | fa294377b1ab81d391e47a6662dea7ca293722ed /challenge-236/deadmarshal/python/ch2.py | |
| parent | 50380dd0fb4f1fd53a25e499544f6c74fd7f6f6c (diff) | |
| parent | 3da619757777db47e5c798f19f47ded9c77f65fe (diff) | |
| download | perlweeklychallenge-club-859530783c2761fd736a0370c8cecb066a33ef3f.tar.gz perlweeklychallenge-club-859530783c2761fd736a0370c8cecb066a33ef3f.tar.bz2 perlweeklychallenge-club-859530783c2761fd736a0370c8cecb066a33ef3f.zip | |
Merge pull request #1 from manwar/master
Added Task 1
Diffstat (limited to 'challenge-236/deadmarshal/python/ch2.py')
| -rw-r--r-- | challenge-236/deadmarshal/python/ch2.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-236/deadmarshal/python/ch2.py b/challenge-236/deadmarshal/python/ch2.py new file mode 100644 index 0000000000..f79c2ea21e --- /dev/null +++ b/challenge-236/deadmarshal/python/ch2.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +def array_loops(arr): + i,count,indices = 0,0,[-1] * len(arr) + while i < len(arr): + if indices[i] == -1: + count += 1 + while indices[i] == -1: + indices[i] = 1 + i = arr[i] + i += 1 + return count + +print(array_loops([4,6,3,8,15,0,13,18,7,16,14,19,17,5,11,1,12,2,9,10])) +print(array_loops([0,1,13,7,6,8,10,11,2,14,16,4,12,9,17,5,3,18,15,19])) +print(array_loops([9,8,3,11,5,7,13,19,12,4,14,10,18,2,16,1,0,15,6,17])) + |
