Skip to content

Commit f86b6a6

Browse files
committed
Day 22: use tuples instead of lists, allow usage of sets in tests
1 parent e866f42 commit f86b6a6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

day22/permutations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ def permutations(arr):
22
allPermutations = list()
33

44
if len(arr) < 1:
5-
return [[]]
5+
return [()]
66
else:
77
for i in xrange(len(arr)):
88
for permutation in permutations(arr[1:]):
9-
allPermutations.append(permutation[:i] + arr[0:1] + permutation[i:])
9+
allPermutations.append(permutation[:i] + (arr[0],) + permutation[i:])
1010

1111
return allPermutations
1212

1313
def main():
14-
assert permutations([1]) == [[1]]
15-
assert permutations([1,2]) == [[1, 2], [2, 1]]
16-
assert permutations([1,2,3]) == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [3, 1, 2], [2, 3, 1], [3, 2, 1]]
14+
assert set(permutations([])) == set([()])
15+
assert set(permutations([1])) == set([(1,)])
16+
assert set(permutations([1,2])) == set([(1, 2), (2, 1)])
17+
assert set(permutations([1,2,3])) == set([(1, 2, 3), (1, 3, 2), (2, 1, 3), (3, 1, 2), (2, 3, 1), (3, 2, 1)])
1718

1819
if __name__ == "__main__":
1920
main()

0 commit comments

Comments
 (0)