1 min read

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]