From dbe495712e34674a941fb1c17e0cd5bca5c55ae4 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 11 Mar 2024 11:11:03 +0100 Subject: PWC 260 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-260/luca-ferrari/python/ch-1.py | 33 +++++++++++++++++++++++++++++++ challenge-260/luca-ferrari/python/ch-2.py | 31 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 challenge-260/luca-ferrari/python/ch-1.py create mode 100644 challenge-260/luca-ferrari/python/ch-2.py (limited to 'challenge-260/luca-ferrari/python') diff --git a/challenge-260/luca-ferrari/python/ch-1.py b/challenge-260/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..8f70bb0494 --- /dev/null +++ b/challenge-260/luca-ferrari/python/ch-1.py @@ -0,0 +1,33 @@ +#!python + +# +# Perl Weekly Challenge 260 +# Task 1 +# +# See +# + +import sys + +# task implementation +# the return value will be printed +def task_1( args ): + nums = list( map( int, args ) ) + bag = {} + + for n in nums: + occurrencies = len( list( filter( lambda x: x == n, nums ) ) ) + if not n in bag: + bag[ n ] = occurrencies + + + for o in bag.values(): + if len( list( filter( lambda x: x == o, bag.values() ) ) ) > 1: + return 0 + + return 1 + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) diff --git a/challenge-260/luca-ferrari/python/ch-2.py b/challenge-260/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..b69ddaa9f4 --- /dev/null +++ b/challenge-260/luca-ferrari/python/ch-2.py @@ -0,0 +1,31 @@ +#!python + +# +# Perl Weekly Challenge 260 +# Task 2 +# +# See +# + +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: ] ) ) -- cgit