in reply to Anagrams & Letter Banks
I am interested in finding groups of words not that are all anagrams of each other, but rather which all share a common “letter bank,” which is a word (in the list) with no duplicate letters.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1202179 use strict; use warnings; chomp( my @words = <DATA> ); # find the "banks" in the word list my %banks = map { $_, [ ] } grep !/(.).*\1/, @words; # find what a word "banks" to and save if "bank" exists for ( @words ) { my $banksto = tr///csr; exists $banks{$banksto} and push @{ $banks{$banksto} }, $_; } print "@$_\n" for values %banks; __DATA__ ab aabb aaabbb xxyy xxxyyy
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Anagrams & Letter Banks
by johngg (Canon) on Oct 28, 2017 at 11:26 UTC |