Sum multiples of 3 and 5: Difference between revisions

Content added Content deleted
m (→‎{{header|360 Assembly}}: Superfluous blanks suppressed)
(added Factor)
Line 1,008: Line 1,008:
2333333333333333333333333333316666666666666666666666666668
2333333333333333333333333333316666666666666666666666666668
233333333333333333333333333333166666666666666666666666666668</pre>
233333333333333333333333333333166666666666666666666666666668</pre>

=={{header|Factor}}==
<lang factor>USING: formatting kernel math math.functions sequences
tools.time ;
IN: rosetta-code.sum35

: {x+y-z} ( {x,y,z} -- x+y-z ) first3 [ + ] dip - ;

: range-length ( limit multiple -- len ) [ 1 - ] dip / floor ;

: triangular ( limit multiple -- sum )
[ range-length ] [ nip over 1 + ] 2bi * * 2 / ;

: sum35 ( limit -- sum )
{ 3 5 15 } [ triangular ] with map {x+y-z} ;
: msg ( limit sum -- )
"The sum of multiples of 3 or 5 below %d is %d.\n" printf ;
: output ( limit -- ) dup sum35 msg ;
: main ( -- ) [ 1000 10 20 ^ [ output ] bi@ ] time ;

MAIN: main</lang>
{{out}}
<pre>
The sum of multiples of 3 or 5 below 1000 is 233168.
The sum of multiples of 3 or 5 below 100000000000000000000 is 2333333333333333333316666666666666666668.
Running time: 0.000923753 seconds
</pre>


=={{header|FBSL}}==
=={{header|FBSL}}==