Skip to content

Instantly share code, notes, and snippets.

@CodeGolfScotland
Last active January 25, 2017 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeGolfScotland/4f930b87e84b80326c8ec5266c526945 to your computer and use it in GitHub Desktop.
Save CodeGolfScotland/4f930b87e84b80326c8ec5266c526945 to your computer and use it in GitHub Desktop.
Code Golf August 2016

August 2016 - Rotate to the max

Task

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

About Code Golf Scotland

@joaquinferrero
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment