aboutsummaryrefslogtreecommitdiff
path: root/challenge-056/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2024-09-16 09:41:35 +0200
committerLubos Kolouch <lubos@kolouch.net>2024-09-16 09:41:35 +0200
commit65b9d6b25e0a823ca7ab6d15744ff98eb3697471 (patch)
treefcbcdebd50e3e146dfecf519701ec04b191053eb /challenge-056/paulo-custodio/python/ch-1.py
parentbd1fe7ae50ca42bda58c134b9edfdc287fb3f386 (diff)
parent68e321dd32a834f54b55d5e8924f04358e41cf1f (diff)
downloadperlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.tar.gz
perlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.tar.bz2
perlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-056/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-056/paulo-custodio/python/ch-1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-056/paulo-custodio/python/ch-1.py b/challenge-056/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..38a1c8f8b8
--- /dev/null
+++ b/challenge-056/paulo-custodio/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+# Challenge 056
+#
+# TASK #1
+# Diff-K
+# You are given an array @N of positive integers (sorted) and another non
+# negative integer k.
+#
+# Write a script to find if there exists 2 indices i and j such that
+# A[i] - A[j] = k and i != j.
+#
+# It should print the pairs of indices, if any such pairs exist.
+#
+# Example:
+#
+# @N = (2, 7, 9)
+# $k = 2
+# Output : 2,1
+
+import sys
+
+k = int(sys.argv[1])
+n = [int(x) for x in sys.argv[2:]]
+
+for i in range(0, len(n)-1):
+ for j in range(i+1, len(n)):
+ if abs(n[i]-n[j]) == k:
+ print(str(i)+","+str(j))