aboutsummaryrefslogtreecommitdiff
path: root/challenge-329/luca-ferrari/python/ch-2.py
blob: bdfc275a82f9db2b967556dc677f6622c7ff04b7 (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
32
33
34
35
36
37
38
#!python

#
# Perl Weekly Challenge 329
# Task 2
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-329>
#

import sys

# task implementation
# the return value will be printed
def task_2( args ):
    string = args[ 0 ]

    begin = 0
    end   = 0

    for i in range( 0, len( string ) - 1 ) :
        current = string[ i ]
        needle = current.upper()
        if current.isupper() :
            needle = current.lower()

        for j in range( i + 1, len( string ) ) :
            print( " => ", string[ j ] )
            if string[ j ] == needle :
                if ( end - begin ) < ( j - i ) :
                    begin = i
                    end   = j

    return string[ begin : end + 1 ]


# invoke the main without the command itself
if __name__ == '__main__':
    print( task_2( sys.argv[ 1: ] ) )