in reply to Re: Re: Sorting characters within a string
in thread Sorting characters within a string

Building the hash programmatically would be ani nteresting brain teaser.

Here is the worst way to do it:
my @strings = (grep /[acgmt]{2}/, ('aa' .. 'tt'), grep /[acgmt]{3}/, ('aaa' .. 'ttt'), grep /[acgmt]{4}/, ('aaaa' .. 'tttt')); my %sort_cache; for my $key (@strings) { $sort_cache{$key} = join '',sort split('',$key); }

Hey, don't take this seriously ;-) it does the job but it's so inefficient it's scary.
Guillaume

Replies are listed 'Best First'.
Re: Re: Re: Re: Sorting characters within a string
by jlongino (Parson) on Aug 24, 2001 at 05:55 UTC
    Guillaume,

    I think one of the assumptions (although not clearly stated) is that no string has repeated characters in it.

    Very inventive code though!

    Update: Maybe a regexp to eliminate any string with duplicate letters. As though things weren't bad enough :)

    If the code and the comments disagree, then both are probably wrong. -- Norm Schryer