Sum multiples of 3 and 5: Difference between revisions

m
Line 1,879:
NB. Naive method
NB. joins two lists of the multiples of 3 and 5, then uses the ~. operator to remove duplicates.
 
echo 'The sum of the multiples of 3 or 5 < 1000 is ', ": +/ ~. (3*i.334), (5*i.200)
 
NB. slightly less naive: select the numbers which have no remainder when divided by 3 or 5:
echo 'The sum of the multiples of 3 or 5 < 1000 is still ', ": +/I.+./0=3 5|/i.1000
 
 
 
Line 1,891 ⟶ 1,894:
 
echo 'For 10^20 - 1, the sum is ', ": +/ (".(20#'9'),'x') sumdiv 3 5 _15
exit ''
 
</lang>
Line 1,897 ⟶ 1,899:
<pre>
The sum of the multiples of 3 or 5 < 1000 is 233168
The sum of the multiples of 3 or 5 < 1000 is still 233168
For 10^20 - 1, the sum is 2333333333333333333316666666666666666668
</pre>
6,951

edits