aboutsummaryrefslogtreecommitdiff
path: root/challenge-257
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-22 21:12:58 +0000
committerGitHub <noreply@github.com>2024-02-22 21:12:58 +0000
commitda664c025eeb01397e74c61b2af119f1fe1e68e7 (patch)
tree47f26132992422184964a3ca29dc1f7ad2341fe2 /challenge-257
parent6fecd884eddb471402d911c59ea7b12aad9541f5 (diff)
parent14b9385d24f2e8992da29a1f51096426b23bb06b (diff)
downloadperlweeklychallenge-club-da664c025eeb01397e74c61b2af119f1fe1e68e7.tar.gz
perlweeklychallenge-club-da664c025eeb01397e74c61b2af119f1fe1e68e7.tar.bz2
perlweeklychallenge-club-da664c025eeb01397e74c61b2af119f1fe1e68e7.zip
Merge pull request #9629 from oWnOIzRi/week257
improve for large minimum values
Diffstat (limited to 'challenge-257')
-rw-r--r--challenge-257/steven-wilson/python/ch-1.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/challenge-257/steven-wilson/python/ch-1.py b/challenge-257/steven-wilson/python/ch-1.py
index 82296444ec..962111137e 100644
--- a/challenge-257/steven-wilson/python/ch-1.py
+++ b/challenge-257/steven-wilson/python/ch-1.py
@@ -21,15 +21,16 @@ def smaller_than_current(*integers):
if not integers:
return ()
+ min_i = min(integers)
max_i = max(integers)
- count = [0] * (max_i + 1)
+ count = [0] * (max_i - min_i + 1)
for i in integers:
- count[i] += 1
+ count[i - min_i] += 1
- for pos in range(1, max_i):
+ for pos in range(1, max_i - min_i):
count[pos] += count[pos-1]
- return tuple(count[i - 1] if i != 0 else 0 for i in integers)
+ return tuple(count[i - min_i - 1] if i != min_i else 0 for i in integers)
if __name__ == "__main__":