Back in 2002 and 2004 there was a thread on this topic that I started 
with a request similar to yours. I called my verb "strike" rather 
than sub - but wanted the same thing.

In the two discussions, two years apart, the verbs evolved into (from 
Roger Hui)

    rankx  =: i.~ (] - {) /:@/:    NB. as before

    strikeb2=: 4 : 0
  x#~ (rankx x) >: ((~.y) i. x) { (#/.~y),0
)

NB. renaming to your name

    sub =. strikeb2

    a=: 'thisisaphrasewithlotsofis' [ b=:'phraseitis'
    a sub b
haswithlotsofis

NB. Jose Mario Quintana submitted the following tacit version (one line)

    strikeb3 =: [ #~ ([: (i.~ (] - {) /:@/:) [) >: (([: ~. ]) i. [) { 
([: #/.~ ]) , 0"_

    a strikeb3 b
haswithlotsofis

I'm posting this, even though Roger has already offered another 
alternative - likely as a result of a few more years of wisdom ...

- joey

On Thu, 30 Apr 2009 02:49:24 -0400: [email protected] wrote:
>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

Reply via email to