aboutsummaryrefslogtreecommitdiff
path: root/challenge-260/luca-ferrari/python/ch-2.py
blob: b69ddaa9f499ad5926fbfd53ba924dded0c04899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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: ] ) )