diff options
| author | Simon Green <mail@simon.green> | 2025-09-07 21:12:46 +1000 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2025-09-07 21:12:46 +1000 |
| commit | a044dc87aa5e75e5510f78ad13e643b04ed4713b (patch) | |
| tree | e3e966a1072d453807f51d34cb79ff7692a36501 /challenge-337/sgreen/python/ch-1.py | |
| parent | e80c93c27044ee16a834a9ee64a0087c1c7d0b1d (diff) | |
| download | perlweeklychallenge-club-a044dc87aa5e75e5510f78ad13e643b04ed4713b.tar.gz perlweeklychallenge-club-a044dc87aa5e75e5510f78ad13e643b04ed4713b.tar.bz2 perlweeklychallenge-club-a044dc87aa5e75e5510f78ad13e643b04ed4713b.zip | |
sgreen solutions to challenge 337
Diffstat (limited to 'challenge-337/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-337/sgreen/python/ch-1.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-337/sgreen/python/ch-1.py b/challenge-337/sgreen/python/ch-1.py new file mode 100755 index 0000000000..565e8bfd00 --- /dev/null +++ b/challenge-337/sgreen/python/ch-1.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import sys + + +def smaller_than_current(numbers: list) -> list: + """For each number in the list, count how many numbers are smaller than it. + + Args: + numbers: List of numbers. + + Returns: + A list of counts, where each count corresponds to how many numbers in the + input list are smaller than or equal to the number at that index. + """ + solution = [] + + for number in numbers: + # Count how many numbers are smaller or equal than the current number. + # Subtract one to exclude the current number itself. + solution.append(sum(1 for n in numbers if n <= number) - 1) + + return solution + + +def main(): + # Convert input into numbers + array = [float(n) for n in sys.argv[1:]] + result = smaller_than_current(array) + print(result) + + +if __name__ == '__main__': + main() |
