Given a number, return the maximum value by rearranging it's digits.
Examples:
(123) => 321
(786) => 876
("001") => 100
(999) => 999
(10543) => 54310
^Note the number may be given as a string
Given a number, return the maximum value by rearranging it's digits.
Examples:
(123) => 321
(786) => 876
("001") => 100
(999) => 999
(10543) => 54310
^Note the number may be given as a string
I'm not taking credit for this as it is a direct copy of @achanda 's above attempt. Converting the function def to lambda reduces it to 36 chars.
Language: Python
Length: 36
Solution:
x=lambda y:`sorted(`y`)[::-1]`[2::5]
Language: Perl 6
Length: 33
Solution:
sub r{$^a.comb.sort.reverse.join}
Demo:
perl6 -e 'say "$_ : {a($_)}" for 123, 786, "001", 999, 10543; sub a($a){$a.comb.sort.reverse.join}'
123 : 321
786 : 876
001 : 100
999 : 999
10543 : 54310
Language: Python
Length: 45
Solution
Length: 42
Length: 40