Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
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,
You can’t perform that action at this time.