On topic: The Wednesday Challenge

Aidan Samuel aidan.samuel at gmail.com
Wed Aug 15 15:37:09 BST 2007


On 8/15/07, Andy Armstrong <andy at hexten.net> wrote:
> Given a 64 Mbyte file containing random binary data write a perl
> program such that
>
> $ perl myprog.pl < 64m.bin > 64m.sorted.bin
>
> outputs a file 64m.sorted.bin with all the bytes sorted in ascending
> order. Marks will be given for speed, brevity and parsimonious use of
> memory.
>
> --
> Andy Armstrong, hexten.net
>
>

Terrible I know, but I just wanted to be the first!

perl -e 'my%x=();while (<>){$x{$_}++for unpack("C*",$_)}print
chr($_)x$x{$_}for sort keys%x;' < 64m.bin > 64m.sorted.bin


More information about the london.pm mailing list