See http://www.jsoftware.com/pipermail/general/2004-May/017503.html for the
evolution of strikeb2

Comparing performances 

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

for

   a=: 'thisisaphrasewithlotsofis'
   b=:'phraseitis'

we get:

   ts'a strikeb2&(1000 ,@:# ,:) b'
0.001690735 844032

   ts'a strsub&(1000 ,@:# ,:) b'
0.0059314179 1230656

   0.0059314179 1230656 % 0.001690735 844032
3.508189 1.4580679

   a (strikeb2&(1000 ,@:# ,:)-:strsub&(1000 ,@:# ,:)) b
1


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Joey K Tuttle
> Verzonden: donderdag 30 april 2009 9:29
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] string subtract
> 
> 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

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to