Sum multiples of 3 and 5: Difference between revisions

jq
(add PicoLisp)
(jq)
Line 875:
<pre>233168</pre>
 
=={{header|jq}}==
<lang jq>
# The sum of all positive multiples of d up to (./d)|floor
def sum_multiples(d):
((./d) | floor) | (d * . * (.+1))/2 ;
 
# Sum of multiples of a or b (less than the input)
def task(a;b):
. - 1
| sum_multiples(a) + sum_multiples(b) - sum_multiples(a*b);</lang>Examples:
 
jq does not (yet) support arbitrary-precision integer arithmetic but converts large integers to floats, so:
<lang jq>
1000 | task(3;5) # => 233168
 
10e20 | task(3;5) # => 2.333333333333333e+41</lang>
=={{header|Julia}}==
sum multiples of each, minus multiples of the least common multiple (lcm). Similar to MATLAB's version.
2,479

edits