159 tokens in Python for part 2 by Abbas Moosajee
Download solution
importsys
fresh_range=[tuple(map(int,id_range.split("-")))forid_rangeinsys.stdin.read().split("\n\n")[0].split("\n")]
sorted_range=sorted(fresh_range,key=lambdax:x[0])
merged_range=[]
current_start,current_end=sorted_range[0]
forstart,endinsorted_range[1:]:
ifstart<=current_end+1:
current_end=max(current_end,end)
else:
merged_range.append((current_start,current_end))
current_start,current_end=start,end
merged_range.append((current_start,current_end))
total=0
forstart,endinmerged_range:
total+=(end-start)+1
print(total)