I also wrote a path tracer and would welcome any comments, it seems pretty
long.
NB. Simpler data for easy visualization
] x =. 1 ; 1 3 ; 3 2 1 ; 1 1 3 1
+-+---+-----+-------+
|1|1 3|3 2 1|1 1 3 1|
+-+---+-----+-------+
NB. Displays boxed data as a triangle
display=. > @ (((<@(#&' '))"0 @|.@i.@#) ,&.>"0 (":&.>))
display x
1
1 3
3 2 1
1 1 3 1
NB. Solve the problem bottom up
solve =. (+ 2>./\])&.>/
solve x
+-+
|9|
+-+
NB. What is the best index to choose at each level?
] bestIx =. }. ((i.@#)+])@(2 ({.@\:)\ ])&.>"1 solve\. x
+-+---+-----+
|1|1 1|0 2 2|
+-+---+-----+
NB. Choose one of the best indices
choices=. , @: > @: ({~&.>/\.&.|.)
choices bestIx
1 1 2
NB. Growing indices
ixs=. < @ i."0 @ (2+i.) @ #
ixs bestIx
+---+-----+-------+
|0 1|0 1 2|0 1 2 3|
+---+-----+-------+
] z =. 1 ; (choices bestIx) (=&.> ) ixs bestIx
+-+---+-----+-------+
|1|0 1|0 1 0|0 0 1 0|
+-+---+-----+-------+
display z
1
0 1
0 1 0
0 0 1 0
Cheers,
Mike
On Sat, Jan 10, 2015 at 10:06 AM, Roger Hui <[email protected]>
wrote:
> Hmm, I bet you a Java solution would be longer, eh? :-)
>
> It's been years since I solve Project Euler 67, and I am busy with other
> things on the weekend, so there'll be a delay in a detailed description.
> Probably others will chime in meanwhile.
>
>
>
> On Sat, Jan 10, 2015 at 9:58 AM, oventarb oventarb <[email protected]>
> wrote:
>
> >
> > Dear Roger Hui!
> > I solved problem 67 using Java.
> > What does this code mean:
> >
> > {. (+ 0: ,~ 2: >./\ ])/ m
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm