Skip to content
Permalink
6d5cc671f5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
35 lines (29 sloc) 862 Bytes
from itertools import combinations
with open("rosalind_pdpl.txt","rU") as f:
line=f.readline().strip()
#line='2 2 3 3 4 5 6 7 8 10'
nums=sorted(map(int,line.split()),reverse=True)
def trial_insert(breaks,differences,N):
for i in differences:
answer=True
for j in breaks:
if abs(j-i) not in differences:
answer=False
break
if answer: return i
return None
breaks=[0,nums[0]]
differences=nums[1:]
N=nums[0]
j=0
while len(differences)>0:
j=trial_insert(breaks,differences,N)
print j,len(differences)
if j:
for i in breaks:
s=differences.index(abs(j-i))
del differences[s]
breaks.append(j)
breaks=sorted(breaks,reverse=True)
for x in breaks:
print x,