Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
native_bigger_together solution in Clear category for Bigger Together by Jon_Red
def bigger_together(ints):
'''
Returns difference between the largest and smallest values
that can be obtained by concatenating the integers together.
'''
repeat=1+max(len(str(integer))for integer in ints)
sorted_strs=sorted(map(str,ints),key=lambda string:string*repeat)
large,small=int(''.join(reversed(sorted_strs))),int(''.join(sorted_strs))
return abs(large-small)
if __name__=='__main__':
# self-checks
assert bigger_together([1,2,3,4])==3087,'4321 - 1234'
assert bigger_together([1,2,3,4,11,12])==32099877,'43212111 - 11112234'
assert bigger_together([0,1])==9,'10-01'
assert bigger_together([100])==0,'100-100'
Sept. 15, 2020
Comments: