aboutsummaryrefslogtreecommitdiff
path: root/challenge-086/paulo-custodio/python/ch-1.py
blob: 7f3af4aa6291dd455fbf36c1e208b03154425718 (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
30
31
32
33
34
35
36
37
#!/usr/bin/env python3

# Challenge 086

# TASK #1 > Pair Difference
# Submitted by: Mohammad S Anwar
# You are given an array of integers @N and an integer $A.
#
# Write a script to find find if there exists a pair of elements in the array whose difference is $A.
#
# Print 1 if exists otherwise 0.
#
# Example 1:
# Input: @N = (10, 8, 12, 15, 5) and $A = 7
# Output: 1 as 15 - 8 = 7
# Example 2:
# Input: @N = (1, 5, 2, 9, 7) and $A = 6
# Output: 1 as 7 - 1 = 6
# Example 3:
# Input: @N = (10, 30, 20, 50, 40) and $A = 15
# Output: 0

import sys

def found(dif, nums):
    for i in range(len(nums)-1):
        for j in range(i+1, len(nums)):
            if abs(nums[i]-nums[j])==dif:
                return True
    return False

nums = [int(x) for x in sys.argv[1:]]
dif = nums.pop(-1)
if found(dif, nums):
    print(1)
else:
    print(0)