in reply to Matching words based on letter content

This is anagrams done sideways. Sounds like homework to me.

Something to consider - are "stoop" and "stop" considered the same? If they are, then the solutions by holli and friedo won't work.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

  • Comment on Re: Matching words based on letter content

Replies are listed 'Best First'.
Re^2: Matching words based on letter content
by holli (Abbot) on Jan 28, 2005 at 15:15 UTC
    @_ = qw (opt pot top stoop stop pit ipt);
    it will print
    opst counted 1 times oopst counted 1 times opt counted 3 times ipt counted 2 times
    Update: you´re right, i misread that. But this does it:

    use strict; my %h; @_ = qw (opt pot top stoop stop pit ipt); for ( @_ ) { my $last; $h{join "", grep { if ( $_ eq $last ) { "" } else { $last = $_; $_ } } sort split "", $_}++; } for ( keys %h ) { print "$_ counted $h{$_} times\n"; }
    prints:
    opst counted 2 times opt counted 3 times ipt counted 2 times

    holli, regexed monk
Re^2: Matching words based on letter content
by knirirr (Scribe) on Jan 28, 2005 at 15:17 UTC
    I is most definitely not homework. It is in order to list total base count in a load of amino acids I've got - it's too long unless I compress them by content and forget about the order of bases within the string. 'Stoop' and 'stop' are therefore different.