aboutsummaryrefslogtreecommitdiff
path: root/challenge-247/luca-ferrari/python/ch-2.py
blob: fd59761ecfc0d385d365a034a91bbc055a159aca (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
#!python

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

import sys

# task implementation
def main( argv ):
    string = argv[ 0 ]
    score = {}
    for i in range( 0, len( string ) - 1 ):
        needle = string[ i ] + string[ i + 1 ]
        counting = string.count( needle )
        if not counting in score:
            score[ counting ] = []

        if not needle in score[ counting ]:
            score[ counting ].append( needle )

    # get the highest key and extract the min value
    print( min( score[ max( score.keys() ) ] ) )

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