From 7ae41852c28f903f5821561705eba50147c9c6e4 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 5 Feb 2024 08:15:45 +0100 Subject: PWC 255 Task 1 Raku done Task 2 Raku done Task 1 PL/Perl done Task 2 PL/perl done Task 1 PL/PgSQL done Task 2 PL/PgSQL done Task 1 Python done Task 2 Python done Task 1 PL/Java done Task 2 PL/Java done --- challenge-255/luca-ferrari/python/ch-1.python | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'challenge-255/luca-ferrari/python/ch-1.python') 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 # 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 -- cgit