5 kyu

Weight for weight

2,035 of 55,897g964

Description:

My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.

I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.

For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99.

Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?

Example:

"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes: 

"100 180 90 56 65 74 68 86 99"

When two numbers have the same "weight", let us class them as if they were strings (alphabetical ordering) and not numbers:

180 is before 90 since, having the same "weight" (9), it comes before as a string.

All numbers in the list are positive numbers and the list can be empty.

Notes

  • it may happen that the input string have leading, trailing whitespaces and more than a unique whitespace between two consecutive numbers
  • For C: The result is freed.
Algorithms

Similar Kata:

More By Author:

Check out these other kata created by g964

Stats:

CreatedAug 8, 2015
PublishedAug 8, 2015
Warriors Trained134642
Total Skips26163
Total Code Submissions371684
Total Times Completed55897
Ruby Completions2035
Python Completions19680
JavaScript Completions15955
Haskell Completions734
Java Completions5440
C# Completions3926
Clojure Completions194
CoffeeScript Completions29
C++ Completions2035
PHP Completions1172
Crystal Completions16
C Completions506
TypeScript Completions1497
Rust Completions924
Swift Completions454
F# Completions94
R Completions108
Shell Completions43
OCaml Completions35
Kotlin Completions581
Objective-C Completions6
Lua Completions120
Scala Completions360
Elixir Completions166
Julia Completions68
PowerShell Completions51
Go Completions788
Nim Completions12
Reason Completions4
Racket Completions21
Pascal Completions7
Perl Completions21
Elm Completions9
COBOL Completions3
D Completions4
Prolog Completions8
Dart Completions26
Total Stars2804
% of votes with a positive feedback rating88% of 5429
Total "Very Satisfied" Votes4327
Total "Somewhat Satisfied" Votes891
Total "Not Satisfied" Votes211
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • OverZealous Avatar
  • dnolan Avatar
  • donaldsebleung Avatar
  • kazk Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • BobtheLantern Avatar
  • Wikilift Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad