From 3e655a098886fc8d97d1bb333236e989e892616c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 27 Dec 2023 10:59:10 +0100 Subject: 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 --- challenge-249/luca-ferrari/python/ch-2.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 challenge-249/luca-ferrari/python/ch-2.py (limited to 'challenge-249/luca-ferrari/python/ch-2.py') 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 +# + +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: ] ) + + -- cgit