Hi folks,
I'm writing an anagram phrase utility, as in 'Talking Heads' = 'Kings Lead
Hat'.
Anagrams were worked on in Programming threads
Words of Equal Characters (2008-9-25) and
Generating words from a set of letters (2008-12-20).
I'm trying to subtract exactly the characters in y (a matching word)
from x (the input), so letters left over can be tested for the next
matching word, if any.
So far, I've got two verbs:
NB. number each occurrence of each char, and pair that with y, boxed.
seq=: 3 : '(<"0 y),. <"0 +/ |: (* +/\)(=/ ~.) y'
NB. Now that each char+seq nbr is unique, use -.
sub=: 4 : ';0{"1 (seq x) -. seq y'
a=: 'thisisaphrasewithlotsofis' [ b=:'phraseitis'
a sub b
haswithlotsofis
It works but seems clunky - is there a better way? Thanks.
-- Doug Carroll
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm