aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-31 13:39:00 +0100
committerGitHub <noreply@github.com>2024-03-31 13:39:00 +0100
commit92e9a75b20d0063cc04a8dfd3af244f64f861bd4 (patch)
tree9c3a60c452b0525bef9adb99fafbea09d94dbf1b /challenge-262/sgreen/python/ch-2.py
parentffdfa5d6eb16e02e9b37eb4bd977e2e00ba800eb (diff)
parent4c42510de23a775a8cd514185d2d4cf319f9f10a (diff)
downloadperlweeklychallenge-club-92e9a75b20d0063cc04a8dfd3af244f64f861bd4.tar.gz
perlweeklychallenge-club-92e9a75b20d0063cc04a8dfd3af244f64f861bd4.tar.bz2
perlweeklychallenge-club-92e9a75b20d0063cc04a8dfd3af244f64f861bd4.zip
Merge pull request #9838 from simongreen-net/master
sgreen solutions to challenge 262
Diffstat (limited to 'challenge-262/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-262/sgreen/python/ch-2.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-262/sgreen/python/ch-2.py b/challenge-262/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..a375afe037
--- /dev/null
+++ b/challenge-262/sgreen/python/ch-2.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def equal_div(ints: list, k: int) -> int:
+ """Count the number of occurrences where two values are equal and the
+ product of their position is divisible by k
+
+ Args:
+ ints (list): The input list
+ k (int): An integer
+
+ Returns:
+ int: The number of occurrences
+ """
+
+ count = sum(1
+ for i in range(len(ints)-1)
+ for j in range(i+1, len(ints))
+ if ints[i] == ints[j] and i * j % k == 0
+ )
+
+ return count
+
+
+def main():
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ k = array.pop()
+ result = equal_div(array, k)
+ print(result)
+
+
+if __name__ == '__main__':
+ main()