aboutsummaryrefslogtreecommitdiff
path: root/challenge-249/luca-ferrari/python/ch-2.py
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2023-12-27 14:57:27 -0600
committerLuis Mochan <mochan@fis.unam.mx>2023-12-27 14:57:27 -0600
commitf9c88dbbb1e13bfb63f40d0dd3b8630850655d7b (patch)
treecb922fb2f44a7ec7bd10cd13b3db9eb2d4fd14b5 /challenge-249/luca-ferrari/python/ch-2.py
parent23f378718ed93b9b8d9e51fe18f07a55f61dc9c1 (diff)
parent4ece120b2f4c7b25b00eaad66524fb5d99fa58c3 (diff)
downloadperlweeklychallenge-club-f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b.tar.gz
perlweeklychallenge-club-f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b.tar.bz2
perlweeklychallenge-club-f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b.zip
Merge branch 'master' of github.com:manwar/perlweeklychallenge-club into challenges
Diffstat (limited to 'challenge-249/luca-ferrari/python/ch-2.py')
-rw-r--r--challenge-249/luca-ferrari/python/ch-2.py37
1 files changed, 37 insertions, 0 deletions
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: ] )
+
+