A simple solution obtains with "progressive index of" as a utility.
http://www.jsoftware.com/jwiki/Essays/Progressive%20Index-Of

   oc=: i.~ (] - {) /:@/:
   pi=: #...@[ ({. i.&(,.oc) }.) [ i. ,

   a=: 'thisisaphrasewithlotsofis'
   b=:'phraseitis'
   (-.(i.#a) e. a pi b)#a
haswithlotsofis

   strsub=: [ #~ i...@#@[ -...@e. pi
   a strsub b
haswithlotsofis
   (10$'a') strsub 7$'a'
aaa
   (10$'a') strsub 13$'a'



----- Original Message -----
From: Doug Carroll <[email protected]>
Date: Wednesday, April 29, 2009 23:54
Subject: [Jprogramming] string subtract
To: 'Programming forum' <[email protected]>

> 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