diff options
Diffstat (limited to 'challenge-203/spadacciniweb/python')
| -rw-r--r-- | challenge-203/spadacciniweb/python/ch-1.py | 51 | ||||
| -rw-r--r-- | challenge-203/spadacciniweb/python/ch-2.py | 63 |
2 files changed, 114 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)); diff --git a/challenge-203/spadacciniweb/python/ch-2.py b/challenge-203/spadacciniweb/python/ch-2.py new file mode 100644 index 0000000000..52ffb23269 --- /dev/null +++ b/challenge-203/spadacciniweb/python/ch-2.py @@ -0,0 +1,63 @@ +# Task 2: Copy Directory +# Submitted by: Julien Fiegehenn +# +# You are given path to two folders, $source and $target. +# Write a script that recursively copy the directory from $source to $target except any files. +# +# Example +# Input: $source = '/a/b/c' and $target = '/x/y' +# +# Source directory structure: +# +# ├── a +# │ └── b +# │ └── c +# │ ├── 1 +# │ │ └── 1.txt +# │ ├── 2 +# │ │ └── 2.txt +# │ ├── 3 +# │ │ └── 3.txt +# │ ├── 4 +# │ └── 5 +# │ └── 5.txt +# +# Target directory structure: +# +# ├── x +# │ └── y +# +# Expected Result: +# +# ├── x +# │ └── y +# | ├── 1 +# │ ├── 2 +# │ ├── 3 +# │ ├── 4 +# │ └── 5 + +import os +import re +import sys + +source = input("path source: ") +if not(os.path.exists(source)): + sys.exit("{0} directory does not exist.\n".format(source)) + +target = input("path target: ") +if not(os.path.exists(target)): + sys.exit("{0} directory does not exist.\n".format(target)) + +dirs = [] + +for path, subdirs, files in os.walk(source): + for subdir in subdirs: + if len(path) == len(source): + dirs.append(subdir) + else: + dirs.append( os.path.join(path[len(source)+1:], subdir)) + +for dir in dirs: + path = os.path.join(target, dir) + os.mkdir(path) |
