diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-02-13 15:26:44 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-02-13 15:26:44 +0800 |
| commit | 1d7da338f23a3842739e903bfd4e06a04f341c11 (patch) | |
| tree | 1b896c54af3cc17ab0db3c1ce1c181fbd57c1ad2 /challenge-203/spadacciniweb/python/ch-1.py | |
| parent | 9d964b9bb2fc6df2fcaa6018fa6369f582996dab (diff) | |
| parent | 5ccac734c46826df9dedf843701fb1514175c2a6 (diff) | |
| download | perlweeklychallenge-club-1d7da338f23a3842739e903bfd4e06a04f341c11.tar.gz perlweeklychallenge-club-1d7da338f23a3842739e903bfd4e06a04f341c11.tar.bz2 perlweeklychallenge-club-1d7da338f23a3842739e903bfd4e06a04f341c11.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-203/spadacciniweb/python/ch-1.py')
| -rw-r--r-- | challenge-203/spadacciniweb/python/ch-1.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-203/spadacciniweb/python/ch-1.py b/challenge-203/spadacciniweb/python/ch-1.py new file mode 100644 index 0000000000..bd7860c779 --- /dev/null +++ b/challenge-203/spadacciniweb/python/ch-1.py @@ -0,0 +1,51 @@ +# Task 1: Special Quadruplets +# Submitted by: Mohammad S Anwar +# +# You are given an array of integers. +# Write a script to find out the total special quadruplets for the given array. +# +# Special Quadruplets are such that satisfies the following 2 rules. +# 1) nums[a] + nums[b] + nums[c] == nums[d] +# 2) a < b < c < d +# +# +# Example 1 +# Input: @nums = (1,2,3,6) +# Output: 1 +# +# Since the only special quadruplets found is $nums[0] + $nums[1] + $nums[2] == $nums[3]. +# +# Example 2 +# Input: @nums = (1,1,1,3,5) +# Output: 4 +# +# $nums[0] + $nums[1] + $nums[2] == $nums[3] +# $nums[0] + $nums[1] + $nums[3] == $nums[4] +# $nums[0] + $nums[2] + $nums[3] == $nums[4] +# $nums[1] + $nums[2] + $nums[3] == $nums[4] +# +# Example 3 +# Input: @nums = (3,3,6,4,5) +# Output: 0 + +import re +import sys + +if __name__ == "__main__": + input = sys.argv[1:] + if (len(input) < 4 or + len(list(filter(lambda x: re.search(r'\D', x), input))) > 0 ): + sys.exit("Input error\n") + + input = list(map(int, input)) + output = 0 + + quadruplets = [] + for i in range(0, len(input)-3): + for j in range(i+1, len(input)-2): + for k in range(j+1, len(input)-1): + for z in range(k+1, len(input)): + if input[i] + input[j] + input[k] == input[z]: + quadruplets.append([i,j,k,z]) + + print(len(quadruplets)); |
