Jump to content

Sum multiples of 3 and 5: Difference between revisions

m
(added APL)
Line 208:
 
=={{header|J}}==
 
{{incomplete|J|Needs answer for 1000}}
<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 simplificationidea from the python implementation to use 3 simple patterns rather than 1 complicated pattern,
<lang J>
first =: 0&{
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.