if you noticed I intentionally put dorf into dictionary,@words = qw/toyota dorf honda audi ford/; %hash=('adduhifoorndatoyota' => ''); $unique = 0; foreach $word (@words){ foreach $key (sort keys %hash){ $length = 0; if($key=~m/\#/){$_ = $'} else {$_= $key} foreach $l (split //, $word){if(/$l/){$_ = "$`$'"; $length++;}} if($length == length($word)){ $newKey = '#'.$_; if($key=~m/\#/){ if($newKey eq '#'){$newKey .= $unique++} $hash{$newKey} = $hash{$key}; $hash{$newKey}.= ' '.$word; } else { $hash{$newKey} = $word; } } } } foreach (sort keys %hash){ print $hash{$_},"\n" if /\#\d+/; } -----OUTPUT----- toyota dorf honda audi toyota honda audi ford
Update:
@words = qw/toyota dorf honda audi ford/; %hash=('adduhifoorndatoyota' => ''); $unique = 0; foreach $word (@words){ foreach $key (sort keys %hash){ $length = 0; if($key=~m/\#/){$_ = $'} else {$_= $key} foreach $l (split //, $word){if(/$l/){$_ = "$`$'"; $length++;}} if($length == length($word)){ $newKey = '#'.$_; if($key=~m/\#/){ if($newKey eq '#'){$newKey .= $unique++} $hash{$newKey} = $hash{$key}; $hash{$newKey}.= ' '.$word; } else { $hash{$newKey} = $word; } } } } foreach (sort keys %hash){ print $hash{$_},"\n" if /\#\d+/; } -----OUTPUT----- toyota dorf honda audi toyota honda audi ford
In reply to Re: Another word puzzle with too many permutations
by Lennotoecom
in thread Another word puzzle with too many permutations
by sarchasm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |