APL Hacking: Project Euler (#20)
I was avoiding this one for a while simply because I wanted to have a better carry algorithm in mind. On the other hand, it does not seem to matter if I have a bad carry algorithm, because the program runs fairly quickly regardless. I was aiming for a CARRY algorithm that worked using encode and decode instead of relying on scanning and concatenating. Alas, I have not been able to succeed, despite having succeeded at applying such a technique to the act of multiplying, itself.
Problem #20:
Problem #20:
∇R←E(B CARRY)S ⍝ Performs a carry operation. R←(E+⌊(↑S)÷B),(B|↑S),1↓S ∇∇R←X BIGMUL Y
R←⊃(10 CARRY)/+⌿(¯1+⌽⍳⍴X)⌽((⍴X),-¯1+(⍴Y)+⍴X)↑X∘.×Y
R←(((1+⌊10⍟1⌈↑R)⍴10)⊤↑R),1↓R
∇∇R←PETWENTY
⍝ Compute sum of the decimaal digits of !100
+/⊃BIGMUL/1⍴¨⍳100
∇