aboutsummaryrefslogtreecommitdiff
path: root/challenge-056/paulo-custodio/python/ch-1.py
blob: 38a1c8f8b82a90c5700c0d172495bfbb502d548c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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))