forked from Shivi91/Rosalind-1
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path019_PERM.py
33 lines (25 loc) · 839 Bytes
/
019_PERM.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
#!/usr/bin/env python
'''
A solution to a ROSALIND bioinformatics problem.
Problem Title: Enumerating Gene Orders
Rosalind ID: PERM
Rosalind #: 019
URL: http://rosalind.info/problems/perm/
'''
from itertools import permutations
def factorial(n):
'''Returns the value of n!'''
if n < 2:
return 1
else:
return n*factorial(n-1)
with open('data/rosalind_perm.txt') as input_data:
perm_set = range(1, int(input_data.read())+1)
# Create a list containing ordered lists of all permutations.
perm_list = map(list,list(permutations(perm_set)))
with open('output/019_PERM.txt', 'w') as output_data:
# Write the total number of permutations, n!
output_data.write(str(factorial(len(perm_set))))
# Write the permuations in the desired format.
for permutation in perm_list:
output_data.write('\n'+' '.join(map(str,permutation)))