diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2023-12-27 10:59:10 +0100 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2023-12-27 12:22:43 +0100 |
| commit | 3e655a098886fc8d97d1bb333236e989e892616c (patch) | |
| tree | b4e628c2406a1cf2a4cc61f51ee06e620f74965a /challenge-249/luca-ferrari/python | |
| parent | e056520665a1179416e001742a7c11a504548c51 (diff) | |
| download | perlweeklychallenge-club-3e655a098886fc8d97d1bb333236e989e892616c.tar.gz perlweeklychallenge-club-3e655a098886fc8d97d1bb333236e989e892616c.tar.bz2 perlweeklychallenge-club-3e655a098886fc8d97d1bb333236e989e892616c.zip | |
PWC 249
Task 1 Raku done
Task 2 Raku done
Task 1 PL/Perl done
Task 2 PL/perl done
Task 1 PL/PgSQL done
Task 2 PL/PgSQL done
Task 1 Python done
Task 2 Python done
Diffstat (limited to 'challenge-249/luca-ferrari/python')
| -rw-r--r-- | challenge-249/luca-ferrari/python/ch-1.py | 34 | ||||
| -rw-r--r-- | challenge-249/luca-ferrari/python/ch-2.py | 37 |
2 files changed, 71 insertions, 0 deletions
diff --git a/challenge-249/luca-ferrari/python/ch-1.py b/challenge-249/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..229e3e2a00 --- /dev/null +++ b/challenge-249/luca-ferrari/python/ch-1.py @@ -0,0 +1,34 @@ +#!python + +# +# Perl Weekly Challenge 249 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-249/> +# + +import sys + +# task implementation +def main( argv ): + classification = {} + for i in argv: + if not i in classification: + classification[ i ] = 0 + classification[ i ] += 1 + + pairs = [] + for k in classification: + while classification[ k ] >= 2: + pairs.append( [ k, k ] ) + classification[ k ] -= 2 + + for p in pairs: + print( ", ".join( p ) ) + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + diff --git a/challenge-249/luca-ferrari/python/ch-2.py b/challenge-249/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..50c8088458 --- /dev/null +++ b/challenge-249/luca-ferrari/python/ch-2.py @@ -0,0 +1,37 @@ +#!python + +# +# Perl Weekly Challenge 249 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-249/> +# + +import sys +from itertools import permutations + +# task implementation +def main( argv ): + nums = range( 0, len( argv[ 0 ] ) ) + + + for perm in permutations( nums ): + ok = True + for i in range( 0, len( perm ) - 1 ): + if argv[ 0 ][ i ] == 'D' and perm[ i ] > perm[ i + 1 ]: + ok = False + break + elif argv[ 0 ][ i ] == 'I' and perm[ i ] < perm[ i + 1 ]: + ok = False + break + + if ok: + print( ",".join( map( str, perm ) ) ) + return + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + |
