1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-22 08:33:48 +01:00
CodeWars/5kyu/weight_for_weight/solution.py
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

22 lines
585 B
Python

def digit_sum(n):
total = 0
while n > 0:
total += n % 10
n //= 10
return total
class Weight:
def __init__(self, weight):
self.weight = weight
self.digit_sum = digit_sum(weight)
def __lt__(self, other):
if self.digit_sum == other.digit_sum:
return str(self.weight) < str(other.weight)
return self.digit_sum < other.digit_sum
def __str__(self):
return str(self.weight)
def order_weight(strng):
return ' '.join(map(lambda e: str(e), sorted(map(lambda e: Weight(int(e)), strng.split()))))