diff options
Diffstat (limited to 'challenge-255/luca-ferrari/python')
| -rw-r--r-- | challenge-255/luca-ferrari/python/ch-1.python | 26 | ||||
| -rw-r--r-- | challenge-255/luca-ferrari/python/ch-2.python | 21 |
2 files changed, 29 insertions, 18 deletions
diff --git a/challenge-255/luca-ferrari/python/ch-1.python b/challenge-255/luca-ferrari/python/ch-1.python index a0533551d8..d5e0960574 100644 --- a/challenge-255/luca-ferrari/python/ch-1.python +++ b/challenge-255/luca-ferrari/python/ch-1.python @@ -1,24 +1,36 @@ #!python # -# Perl Weekly Challenge 254 +# Perl Weekly Challenge 255 # Task 1 # # See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-254> # import sys -import math # task implementation # the return value will be printed def task_1( args ): - num = int( args[ 0 ] ) - for i in range( 2, int( math.sqrt( num ) ) ): - if ( i ** 3 ) == num: - return True + origin = args[ 0 ] + shuffled = args[ 1 ] + if len( shuffled ) != len( origin ) + 1: + return "Shuffled string must be one character longer than original string" - return False + classification = {} + + for needle in shuffled: + if not needle in classification: + classification[ needle ] = 0 + + classification[ needle ] += 1 + + for needle in origin: + classification[ needle ] -= 1 + if classification[ needle ] <= 0: + del classification[ needle ] + + return list( classification.keys() )[ 0 ] # invoke the main without the command itself diff --git a/challenge-255/luca-ferrari/python/ch-2.python b/challenge-255/luca-ferrari/python/ch-2.python index dc37e2ad93..6493199950 100644 --- a/challenge-255/luca-ferrari/python/ch-2.python +++ b/challenge-255/luca-ferrari/python/ch-2.python @@ -1,7 +1,7 @@ #!python # -# Perl Weekly Challenge 254 +# Perl Weekly Challenge 255 # Task 2 # # See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-254> @@ -12,17 +12,16 @@ import sys # task implementation # the return value will be printed def task_2( args ): - word = args[ 0 ].lower() - vowels = list( reversed( list( filter( lambda x: x in ('a','e','i','o','u'), word ) ) ) ) - output = '' - for letter in word: - if letter not in ( 'a', 'e', 'i', 'o', 'u' ) or len( vowels ) == 0 - output += letter - else: - output += vowels.pop( 0 ) - - return output + paragraph = args[ 0 ] + banned = args[ 1 ] + classification = {} + for w in paragraph.split(): + if w != banned: + if not w in classification: + classification[ w ] = 0 + classification[ w ] += 1 + return sorted( classification.items() )[ -1 ][ 0 ] # invoke the main without the command itself if __name__ == '__main__': |
