PHP, 44 bytes
requires PHP 5.4 or later for short array syntax.
sort($a=&$argv);print_r([array_pop($a)]+$a);
sort arguments, replace 0-th argument with removed last argument, print.
Run with -nr
or try it online.
The 0-th argument is the script file name, "-"
if you call PHP with -r
. "-"
is compared to the other arguments as a string, and since ord("-")==45
, it is smaller than any number. The numbers themselves, although strings, are compared as numbers: "12" > "2"
.
php -nr '<code>' 3 4 2 5 1
and sort($a=&$argv)
lead to $a=["-","1","2","3","4","5"]
→
[array_pop($a)]+$a
is [0=>"5"]+[0=>"-",1=>"1",2=>"2",3=>"3",4=>"4"]
,
which results in [0=>"5",1=>"1",2=>"2",3=>"3",4=>"4"]
.