Skip to content

Instantly share code, notes, and snippets.

@maintainer64
Created June 23, 2019 08:10
Show Gist options
  • Save maintainer64/8db5c48d805f8f8bc0970383adc81157 to your computer and use it in GitHub Desktop.
Save maintainer64/8db5c48d805f8f8bc0970383adc81157 to your computer and use it in GitHub Desktop.
"""
Maximum number from array
Task number of 78 Unilecs (https://vk.com/unilecs)
This function solve task from https://vk.com/@unilecs-task-77-proveryaem-chislo-na-prostotu-bez-ciklov
"""
def function(array: list):
def biggest(a:int, b:int):
a = str(a)
b = str(b)
return int(a + b) > int(b + a)
def w_print(array: list):
return ''.join(list(map(str, array)))
# selection* sort
for i in range(len(array) - 1):
# fixed array[i]
for j in range(i + 1, len(array)):
if biggest(array[j], array[i]): # reverse order
# swap a[i] <=> a[j]
(array[i], array[j]) = (array[j], array[i])
return w_print(array)
assert function([819, 6, 89, 402, 4023, 54, 5]) == '8981965544024023', 'Task one not solved'
assert function([89, 899]) == '89989', 'Task two not solved'
assert function([10, 159, 865, 74, 3, 25, 4589, 23, 52]) == '865745245893252315910', 'Task three not solved'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment