Challenges

Reddit challenges in python language.

Files Code and Result

challenge51_easy

```''' Write a program that given an array A and a number N,
generates all combinations of items in A of length N.

That is, if you are given the array [1,2,3,4,5]
and 3, you're supposed to generate

[1,2,3]
[1,2,4]
[1,2,5]
[1,3,4]
[1,3,5]
[1,4,5]
[2,3,4]
[2,3,5]
[2,4,5]
[3,4,5]

Note that order doesn't matter when counting combinations,
both [1,2,3] and [3,2,1] are considered the same. Order also
doesn't matter in the output of the combinations, as long as you
generate all of them, you don't have to worry about what order
they pop out. You can also assume that every element of the array is distinct.

'''

stuff = [1, 2, 3, 4, 5]

lst = []
for x in range(0, len(stuff)-1):
for y in range(x + 1, len(stuff)):
for z in range(y + 1, len(stuff)):
lst.append(stuff[x])
lst.append(stuff[y])
lst.append(stuff[z])
print(lst)
lst =[]
```

Result

```[1, 2, 3]
[1, 2, 4]
[1, 2, 5]
[1, 3, 4]
[1, 3, 5]
[1, 4, 5]
[2, 3, 4]
[2, 3, 5]
[2, 4, 5]
[3, 4, 5]
```