Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Re: Re: Sorting characters within a string

by guillaume (Pilgrim)
on Aug 24, 2001 at 05:45 UTC ( #107588=note: print w/replies, xml ) Need Help??

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.

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

    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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://107588]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-05-22 17:16 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (80 votes). Check out past polls.