diff options
| author | Michael Manring <michael@manring> | 2024-05-21 03:32:18 +1000 |
|---|---|---|
| committer | Michael Manring <michael@manring> | 2024-05-21 18:33:44 +1000 |
| commit | ace71e8a98451b9fecb6e0a2d0efb6f04476f018 (patch) | |
| tree | 191b6d77b6916378947aa6e8eae77c5901a9a320 /challenge-270/pokgopun/python | |
| parent | 8909a2f4d1fa2e2b9d2f52e68ff8283be4985d3e (diff) | |
| download | perlweeklychallenge-club-ace71e8a98451b9fecb6e0a2d0efb6f04476f018.tar.gz perlweeklychallenge-club-ace71e8a98451b9fecb6e0a2d0efb6f04476f018.tar.bz2 perlweeklychallenge-club-ace71e8a98451b9fecb6e0a2d0efb6f04476f018.zip | |
pwc270 - improvement on ch-2
Diffstat (limited to 'challenge-270/pokgopun/python')
| -rw-r--r-- | challenge-270/pokgopun/python/ch-2.py | 19 |
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 |
