diff options
| author | Matthew Neleigh <87619159+mattneleigh@users.noreply.github.com> | 2024-02-21 14:09:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-21 14:09:23 -0500 |
| commit | 759a8bd8507e025cda6142c6bbbfb652d0af290e (patch) | |
| tree | 3b6394cc27af6a6a6e953c82b0ce1f38806dda82 /challenge-257/steven-wilson/python | |
| parent | 3ecf6e18c27266645a96ab6523ebe85344df922d (diff) | |
| parent | 558acc41d8b3b5e564b5ddd9f5b46572a236f61f (diff) | |
| download | perlweeklychallenge-club-759a8bd8507e025cda6142c6bbbfb652d0af290e.tar.gz perlweeklychallenge-club-759a8bd8507e025cda6142c6bbbfb652d0af290e.tar.bz2 perlweeklychallenge-club-759a8bd8507e025cda6142c6bbbfb652d0af290e.zip | |
Merge branch 'manwar:master' into pwc257
Diffstat (limited to 'challenge-257/steven-wilson/python')
| -rw-r--r-- | challenge-257/steven-wilson/python/ch-1.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-257/steven-wilson/python/ch-1.py b/challenge-257/steven-wilson/python/ch-1.py new file mode 100644 index 0000000000..9ceaaf849f --- /dev/null +++ b/challenge-257/steven-wilson/python/ch-1.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +from collections import Counter + + +def smaller_than_current(*integers): + ''' Given an array of integers, find out how many integers are smaller than + current i.e. foreach ints[i], count ints[j] < ints[i] where i != j + >>> smaller_than_current(5, 2, 1, 6) + (2, 1, 0, 3) + >>> smaller_than_current(1, 2, 0, 3) + (1, 2, 0, 3) + >>> smaller_than_current(0, 1) + (0, 1) + >>> smaller_than_current(9, 4, 9, 2) + (2, 1, 2, 0) + ''' + integer_counter = Counter(integers) + results = [] + for i in integers: + results.append(sum(count for key, count in integer_counter.items() + if key < i)) + return tuple(results) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() |
