On topic: The Wednesday Challenge

Andy Armstrong andy at hexten.net
Wed Aug 15 16:27:57 BST 2007


On 15 Aug 2007, at 16:10, Simon Wistow wrote:

> On Wed, Aug 15, 2007 at 03:01:00PM +0100, Andy Armstrong said:
>> $ perl myprog.pl < 64m.bin > 64m.sorted.bin
>
> What's the format of 64.bin - just a sequence of bytes?

dd if=/dev/random of=64m.bin bs=1024 count=65536

>
> In which case it can only be a sequence of bytes representing 0..255.
>
> Worst case scenario for this is 64Mb of FF
>
> my @bytes;
> while (read STDIN, my $scalar, 1) {
>     $bytes[unpack("C", $scalar)]++;
> }
>
> for (0..$#bytes) {
>     if (defined $bytes[$_]) {
>         print pack("C",$_)x$bytes[$_];
>     }
> }
>
>
> It's possible that %bytes and sort keys %bytes might be better.

I think the challenge was far too easy :)

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list