Hi Raul,

Thanks for the idea, particularly on the use of asserts. I've know of
them but for some reason never used them. I have an idea on where to put
them in my code. thanks.

One of my source of J optimization was Chapter 35 of J for C
Programmer ... specifically the topic Tips For Coding. There he said,
"Avoid Boxing, Especially Small Boxes". :)

I believe your solution would be faster, unfortunately I can't use it. I
need the numeric equivalent as a single number. I'll explain more in my
reply to Dan Bron's post. 

Thanks again.

r/Alex
 
On Tue, 2008-10-07 at 09:42 -0400, Raul Miller wrote:
> On Tue, Oct 7, 2008 at 5:19 AM, Alex Rufon <[EMAIL PROTECTED]> wrote:
> > Playing with this we get:
> > NB. converting from string to numbers
> >   searchLOOKUP ;: 'The quick brown fox jumped'
> > 12 13 14 15 16
> >   searchLOOKUP 'fox'
> > 15
> >   searchLOOKUP 'Fox'
> > 17
> > NB. converting from numbers to string
> >   4 14 15 { LOOKUP
> > +-+-----+---+
> > |3|brown|fox|
> > +-+-----+---+
> >
> > Any ideas how to do this better?
> 
> You could improve the space efficiency of this system, by
> using a flat string representation of your lookup variable.
> 
> 3 :0 'safely initialize LOOK_up_'
>   if. 0 ~: 4!:0<'LOOK_up_' do.
>     LOOK_up_=:''
>   end.
> )
> 
> searchLOOKUP=: 3 :0
>   assert (2 131072 e.~3!:0)S:0 y NB. is character type
>   assert ([EMAIL PROTECTED])S:0 y            NB. rank
>   assert 1 >: L.y                NB. depth
>   values=. boxopen y
>   r=.values (E.i.1:)S:0 LOOK_up_
>   if. (#LOOK_up_) e. r=.values (E.i.1:)S:0 LOOK_up_ do.
>     b=. r = #LOOK_up_
>     newvals=. }:+/\(#LOOK_up_),#@>b#values
>     LOOK_up_=:LOOK_up_,;b#values
>     r=. newvals (I.b)} r
>   end.
>   r,.#@>values
> )
> 
> LOOKUP=: ".bind'LOOK_up_' (<@:{~ (+i.)/)"1 ]
> 
>    searchLOOKUP ;:'the quick brown fox'
>  0 3
>  3 5
>  8 5
> 13 3
>    LOOKUP searchLOOKUP ;:'the quick brown fox'
> +---+-----+-----+---+
> |the|quick|brown|fox|
> +---+-----+-----+---+
>    LOOKUP searchLOOKUP ;:'the quick brown fox jumps'
> +---+-----+-----+---+-----+
> |the|quick|brown|fox|jumps|
> +---+-----+-----+---+-----+
> 
> I do not know if this would be an improvement for your
> situation.
> 
-- 
"The right questions are more important than the right answers to the
wrong questions."
-Dr. John Romagna
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to