# Sort small positive integers without comparing them.
@unsorted = (111,3,1,4,1,59,2,6);
# Simple copy into @sorted
for $element (@unsorted) {
$sorted[$element]++;
}
# Print unsorted list. you can comment out these 3 lines, they have no side effect except printing the original list:
print "Unsorted: ";
for($unsortedi = 0; $unsortedi<@unsorted; $unsortedi++){
print $unsorted[$unsortedi], " ";
}
# and print the sorted list - still no comparisons
print "\nSorted: ";
for($sortedi = 0; $sortedi<@sorted; $sortedi++){
print "$sortedi " x $sorted[$sortedi];
}
# magic :)