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

Thoughts on Eternity, God, and lesser endeavors

## APL Hacking: Project Euler Daily (#1)

This is the first of a series of posts as I go through Project Euler in APL to stretch my knowledge of APL. I hope to post one problem a day to this blog.

Problem #1:

```∇R←PEONE;X;⎕IO
⎕IO←1

⍝ Find the sum of all the multiples of 3 or 5 below 1000.
X←⍳999
R←+/((0=3∣X)∨0=5∣X)/X
∇```

Unregistered user Wednesday, March 2, 2011 7:16:33 PM

Phil Last writes: I guess I'm a bit late but I've just seen this. Biggest problem with your solution is generating all those numbers when you can use (n(n+1))/2 for the sum of 1...n. 3 or 5 times this is the sum of the multiples of 3 or 5. where n is floor 1000 divide 3 or 5. Of course if we just add the 2 series we double count the 15s. So... 0.5×+/x×n×1+n←⌊1000÷x←3 5 ¯15 or without APL chars... 0.5 times+/x times n times 1+n is floor 1000 divide x is 3 5,-15 Final point it should actually be 999 not 1000 because 1000 is a multiple of 5 but isn't "below" 1000.

Aaron W. Hsuarcfide Wednesday, March 2, 2011 10:00:30 PM

Hey Phil,

Thank you for your very useful comment. I will have to go through that and see what I can learn.

### 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