-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList_Comprehensions.py
59 lines (38 loc) · 1.42 KB
/
List_Comprehensions.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Let's learn about list comprehensions! You are given three integers and representing the dimensions of a cuboid along with an integer . Print a list of all possible coordinates given by on a 3D grid where the sum of is not equal to . Here, . Please use list comprehensions rather than multiple loops, as a learning exercise.
# Example
# All permutations of are:
# .
# Print an array of the elements that do not sum to .
# Input Format
# Four integers and , each on a separate line.
# Constraints
# Print the list in lexicographic increasing order.
# Sample Input 0
# 1
# 1
# 1
# 2
# Sample Output 0
# [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
# Explanation 0
# Each variable and will have values of or . All permutations of lists in the form .
# Remove all arrays that sum to to leave only the valid permutations.
# Sample Input 1
# 2
# 2
# 2
# 2
# Sample Output 1
# [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 2], [0, 2, 1], [0, 2, 2], [1, 0, 0], [1, 0, 2], [1, 1, 1], [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2, 0, 1], [2, 0, 2], [2, 1, 0], [2, 1, 1], [2, 1, 2], [2, 2, 0], [2, 2, 1], [2, 2, 2]]
if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
lst = []
for i in range(0,x+1):
for j in range(0,y+1):
for k in range(0,z+1):
if i+j+k != n:
lst.append([i,j,k])
print(lst)