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]]
Program:
from itertools import permutations
if __name__ == '__main__': x = int(input()) y = int(input()) z = int(input()) n = int(input()) list2=[] for i in range(0,x+1): for j in range(0,y+1): for k in range(0,z+1): list1=[] list1.append(i) list1.append(j) list1.append(k) if sum(list1)!=n: list2.append(list1) print(list2)
Program 2:x, y, z, n = int(input()), int(input()), int(input()), int(input())
print ([[a,b,c] for a in range(0,x+1) for b in range(0,y+1) for c in range(0,z+1) if a + b + c != n ])
Post a Comment