2007/11/12, Oleg Kobchenko <[EMAIL PROTECTED]>:
>
> --- danil osipchuk <[EMAIL PROTECTED]> wrote:
>
> > Not all of the tasks can be expressed without the use of temp variables
> (at
> > least efficiently or naturally). To put an example, write a tacit
> version of
> > verb which checks if parenthesises in a string are balanced. My best
> version
> > (*) in the case of a longs string (1M) involve a lot of array copying
> and
> > are slow. Algorithmically effective explicit code (using a list as a
> stack)
> > is intolerantly slow.
> >
> > (*)
> > br=: 0=[:#[:,`([:}.])@.(3=[-[:{.])/ '])}[({'&([i.e.~#])
> > br '{}()'
> > 1
> > br ' 9({}()'
> > 0
> >
>
> That's the idea of J: to find a *functional* tacit
> solution, where state is accumulative and passed
> around between calls.
Yes, but the question is if the *pure functional solution* is always the
best or just efficient enough
br1=: 0=[:#( (3 2$[) (] #~ [:-.@(+._1&|.) +./ . (E."1))^:_ e.~#])
> br2=: '()[]{}'&br1
>
> br2 'a[()]c'
> 1
> br2 'a[()c'
> 0
> _10{. 1e6$'a[()]c'
> a[()]ca[()
> 3 ts'br2 A1' [ A1=: 1e6$'a[()]c'
> 0.0736727 7.3447e6
> 3 ts'br2 A2' [ A2=: A1,']'
> 0.0742985 7.3447e6
>
> 3 ts'br A1'
> 1.56664 5.24371e6
> br 'a[()]ca[()' NB. false positive
> 1
> br2 'a[()]ca[()'
dbr=: 9,~'])}[({'&([i.e.~#])
dbr=: 9,~'])}[({'&([i.e.~#])
dbr '{} '
5 2 9
br=: 1=[:#[:,`([:}.])@.(3=[-[:{.])/ dbr
br '{}'
1
br '{0}'
1
br 'a[()]ca[()'
0
wc=: $&'{([' , [:|.$&'})]'
wc 2
{()}
wc 3
{([])}
data =: wc 50000
#data
100000
6!:2 'br data'
6.51555
6!:2 'br2 data'
122.663
br2
^^^ not so good
For fast procedural approach, what's wrong with plain C?
C is an overkill for this kind of tasks and I would like to avoid its use
__________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm