# ((λ (x) (x x)) (λ (x) (x x)))

Thoughts on Eternity, God, and lesser endeavors

## APL Hacking: Project Euler (#18)

You notice that these are not daily anymore.

For this one, I took advantage of the ability to rotate vectors to get the job done. I am confused about the use of the bracket indexing though, and I do not quite understand why I needed to use ⊃ and ⊂ as much as I did.

Problem #18:

```∇R←PEEIGHTEEN M;F;N;BEST;⎕IO
⎕IO←1

⍝ Find the greatest total through a triangle M

N←⊂[2]⊃⎕FI¨(F/(1++\~F))⊂F/M⊣F←⎕R≠M

⊣⎕FX 'R←X BEST Y' 'R←(X+Y)⌈1⌽Y+-1⌽X'

R←(⊃BEST/N)[1]
∇```

Simon MarsdenSimonMarsden Thursday, March 24, 2011 10:03:49 AM

I like the approach you used.

I think there's a small error in "R←(X+Y)⌈1⌽Y+-1⌽X", which should probably read "R←(X+Y)⌈X+1⌽Y".

Here's a slightly simpler version using the same algorithm:

```R←PEEIGHTEEN M;F;N;BEST;⎕IO
⎕IO←1

⍝ Find the greatest total through a triangle M

N←⊂[2]⊃⎕FI¨(⎕R≠M)⊂M

⊣⎕FX 'R←X BEST Y' 'R←(X+Y)⌈X+1⌽Y'

R←↑⊃BEST/N
```

Aaron W. Hsuarcfide Saturday, March 26, 2011 1:21:58 AM

Ah, yes, that simpler version does make things nicer. Thanks! I think you are right about my overly complicated function.

### Write a comment

New comments have been disabled for this post.

December 2013
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31