diff options
| author | Packy Anderson <packy@cpan.org> | 2025-05-24 14:29:33 -0400 |
|---|---|---|
| committer | Packy Anderson <packy@cpan.org> | 2025-05-24 14:29:33 -0400 |
| commit | 0af5f73f09593ee4c911f1eb8ff0733019ddb826 (patch) | |
| tree | 836572749c062223e2b1c17493fe1218f4361a2d /challenge-322/packy-anderson/python/ch-2.py | |
| parent | fe988cb221822fa23bc445bd25fe87682f2927ca (diff) | |
| download | perlweeklychallenge-club-0af5f73f09593ee4c911f1eb8ff0733019ddb826.tar.gz perlweeklychallenge-club-0af5f73f09593ee4c911f1eb8ff0733019ddb826.tar.bz2 perlweeklychallenge-club-0af5f73f09593ee4c911f1eb8ff0733019ddb826.zip | |
Challenge 322 solutions by Packy Anderson
* Raku that maybe looks like Raku, but mostly like Perl
* Perl
* Python that definitely looks like Perl
* Elixir that looks kinda like Elixir
1 blog post
Diffstat (limited to 'challenge-322/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-322/packy-anderson/python/ch-2.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-322/packy-anderson/python/ch-2.py b/challenge-322/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..e0e0157f94 --- /dev/null +++ b/challenge-322/packy-anderson/python/ch-2.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +def rankArray(ints): + rankInt = 0 + rankDict = {} + for i in sorted(ints): + if i in rankDict: continue + rankInt += 1 + rankDict[i] = rankInt + return [ rankDict[i] for i in ints ] + +def int_join(joiner, arr): + return joiner.join(map(lambda i: str(i), arr)) + +def solution(ints): + print(f'Input: @ints = ({int_join(", ", ints)})') + print(f'Output: ({int_join(", ", rankArray(ints))})') + + +print('Example 1:') +solution([55, 22, 44, 33]) + +print('\nExample 2:') +solution([10, 10, 10]) + +print('\nExample 3:') +solution([5, 1, 1, 4, 3]) |
