diff options
Diffstat (limited to 'challenge-262/luca-ferrari/python/ch-2.py')
| -rw-r--r-- | challenge-262/luca-ferrari/python/ch-2.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-262/luca-ferrari/python/ch-2.py b/challenge-262/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..2fae3dfa1f --- /dev/null +++ b/challenge-262/luca-ferrari/python/ch-2.py @@ -0,0 +1,30 @@ +#!python + +# +# Perl Weekly Challenge 262 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-262> +# + +import sys + +# task implementation +# the return value will be printed +def task_2( args ): + k = int( args[ 0 ] ) + nums = list( map( int, args[ 1: ] ) ) + pairs = [] + + for i in range( 0, len( nums ) ): + for j in range( i + 1, len( nums ) ): + if nums[ i ] != nums[ j ] or ( i * j ) % k != 0: + continue + else: + pairs.append( [ i, j ] ) + + return len( pairs ) + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_2( sys.argv[ 1: ] ) ) |
