aboutsummaryrefslogtreecommitdiff
path: root/challenge-270/pokgopun/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-05-21 13:44:11 +0100
committerGitHub <noreply@github.com>2024-05-21 13:44:11 +0100
commit6ce76558f353f26bf6228db9092b2d8fd4f1c4f5 (patch)
tree276d13f691795ed241c36e239c8b67def1d77420 /challenge-270/pokgopun/python/ch-2.py
parentc4ae6428a67c4844df2844a8cb39a8bcf705a8aa (diff)
parentace71e8a98451b9fecb6e0a2d0efb6f04476f018 (diff)
downloadperlweeklychallenge-club-6ce76558f353f26bf6228db9092b2d8fd4f1c4f5.tar.gz
perlweeklychallenge-club-6ce76558f353f26bf6228db9092b2d8fd4f1c4f5.tar.bz2
perlweeklychallenge-club-6ce76558f353f26bf6228db9092b2d8fd4f1c4f5.zip
Merge pull request #10125 from pokgopun/pwc270
pwc270 - improvement on ch-2
Diffstat (limited to 'challenge-270/pokgopun/python/ch-2.py')
-rw-r--r--challenge-270/pokgopun/python/ch-2.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/challenge-270/pokgopun/python/ch-2.py b/challenge-270/pokgopun/python/ch-2.py
index ac6e3bbcb0..ad5035105a 100644
--- a/challenge-270/pokgopun/python/ch-2.py
+++ b/challenge-270/pokgopun/python/ch-2.py
@@ -76,20 +76,19 @@ def distElem(ints: list, x: int, y: int):
mx = ints[-1]
c = 0
while True:
- ints = ints[:ints.index(mx)]
- l = len(ints)
+ l = ints.index(mx)
if l == 0:
break
+ d = mx - ints[l-1]
if l == 1 or 2*x < y:
- while ints[-1] < mx:
- for i in range(l):
- ints[i] += 1
- c += x
+ for i in range(l):
+ ints[i] += d
+ c += x * d
else:
- while ints[-1] < mx:
- for i in range(-2,0):
- ints[i] += 1
- c += y
+ p = l // 2
+ for i in range(2*p):
+ ints[l-1-i] += d
+ c += y * p * d
return c
import unittest