Anonymous user
Sum multiples of 3 and 5: Difference between revisions
m
→{{header|J}}
(added APL) |
m (→{{header|J}}) |
||
Line 208:
=={{header|J}}==
<lang J>
mp =: $:~ :(+/ .*) NB. matrix product
f =: (mp 0 = [: */ 3 5 |/ ])@:i.
assert 233168 -: f 1000 NB. ****************** THIS IS THE ANSWER FOR 1000
</lang>
For the efficient computation with large n, we start with observation that the sum of these multiples with the reversed list follows a pattern.
Line 224:
NB. continue...
</lang>
Stealing the
<lang J>
first =: 0&{
|