aboutsummaryrefslogtreecommitdiff
path: root/challenge-260/luca-ferrari/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-260/luca-ferrari/python/ch-2.py')
-rw-r--r--challenge-260/luca-ferrari/python/ch-2.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-260/luca-ferrari/python/ch-2.py b/challenge-260/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..b69ddaa9f4
--- /dev/null
+++ b/challenge-260/luca-ferrari/python/ch-2.py
@@ -0,0 +1,31 @@
+#!python
+
+#
+# Perl Weekly Challenge 260
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-260>
+#
+
+import sys
+import array
+from itertools import permutations
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ word = args[ 0 ]
+ words = []
+ engine = permutations( list( word ) )
+ for p in list( engine ):
+ words.append( ''.join( p ) )
+
+ words = sorted( words )
+ for i in range( 0, len( words ) ):
+ if words[ i ] == word:
+ return i + 1
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )