Weight for weight
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.
Similar Kata:
Stats:
Created | Aug 8, 2015 |
Published | Aug 8, 2015 |
Warriors Trained | 134642 |
Total Skips | 26163 |
Total Code Submissions | 371684 |
Total Times Completed | 55897 |
Ruby Completions | 2035 |
Python Completions | 19680 |
JavaScript Completions | 15955 |
Haskell Completions | 734 |
Java Completions | 5440 |
C# Completions | 3926 |
Clojure Completions | 194 |
CoffeeScript Completions | 29 |
C++ Completions | 2035 |
PHP Completions | 1172 |
Crystal Completions | 16 |
C Completions | 506 |
TypeScript Completions | 1497 |
Rust Completions | 924 |
Swift Completions | 454 |
F# Completions | 94 |
R Completions | 108 |
Shell Completions | 43 |
OCaml Completions | 35 |
Kotlin Completions | 581 |
Objective-C Completions | 6 |
Lua Completions | 120 |
Scala Completions | 360 |
Elixir Completions | 166 |
Julia Completions | 68 |
PowerShell Completions | 51 |
Go Completions | 788 |
Nim Completions | 12 |
Reason Completions | 4 |
Racket Completions | 21 |
Pascal Completions | 7 |
Perl Completions | 21 |
Elm Completions | 9 |
COBOL Completions | 3 |
D Completions | 4 |
Prolog Completions | 8 |
Dart Completions | 26 |
Total Stars | 2804 |
% of votes with a positive feedback rating | 88% of 5429 |
Total "Very Satisfied" Votes | 4327 |
Total "Somewhat Satisfied" Votes | 891 |
Total "Not Satisfied" Votes | 211 |