> I agree with the general point.  Project Euler has a number of big
> depth-first searches which I do not know how to program 
> efficiently in J.

Is the following "efficient" according to your criteria?

candidates=: 4 : 0
 (i.x) -. y + ((-i.)#y) */ _1 0 1
)

queens_dfs=: 3 : 0
 if. 1>:y do. i.y return. end.
 stack=. ,&.> y candidates i.0
 while. 0<#stack do.
  c=. y candidates s=. >{.stack
  if. ''-:c        do. stack=. }. stack
  elseif. (#s)=y-1 do. s,{.c return. 
  elseif. 1        do. stack=. ((<s),&.>c),}.stack end.
 end.
)

   6!:2 's=. queens_dfs 20'
7.03129
   '.x' {~ s =/ i.#s
x...................
..x.................
....x...............
.x..................
...x................
............x.......
..............x.....
...........x........
.................x..
...................x
................x...
........x...........
...............x....
..................x.
.......x............
.........x..........
......x.............
.............x......
.....x..............
..........x.........

The program logic is from 
http://www.jsoftware.com/jwiki/Essays/N_Queens_Problem
The program stops after finding the first solution, 
but can be modified readily to find all solutions.



----- Original Message -----
From: John Randall <[EMAIL PROTECTED]>
Date: Wednesday, November 19, 2008 11:12
Subject: Re: [Jprogramming] Project Euler Problem 216
To: Programming forum <[email protected]>

> Mike Day wrote:
> > I confess to finding a slow & exhaustive but correct solution
> > in PARI-GP, with thanks to John for pointing the package
> > out to me a while ago.  I didn't wait to find an elegant method
> > in J or otherwise.
> >
> > FWIW,  I probed the logic of another recent Euler problem
> > (208) in Dyalog APL, but that didn't provide sufficient precision,
> > and I had to go to J for the final solution.
> >
> > J APL etc are great for exploring these problems. Scaling up
> > is sometimes a significant extra problem.
> 
> I think PARI/GP is one of the best special-purpose tools for 
> some of these
> problems, especially since you can also compile it and turn it 
> up to
> eleven.
> 
> I too had a tough time with #208 in J, although I eventually 
> succeeded.  I
> am not sure what you mean by precision: I was doing it entirely 
> in terms
> of small integers.
> 
> I agree with the general point.  Project Euler has a number 
> of big
> depth-first searches which I do not know how to program 
> efficiently in J.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to