Sum multiples of 3 and 5: Difference between revisions
Content added Content deleted
No edit summary |
(8TH version) |
||
Line 26: | Line 26: | ||
</pre> |
</pre> |
||
=={{header|8th}}== |
|||
Implements both the naive method and inclusion/exclusion. |
|||
<lang 8th> |
|||
needs combinators/bi |
|||
: mul3or5? ( 3 mod 0 = ) ( 5 mod 0 = ) bi or ; |
|||
"The sum of the multiples of 3 or 5 below 1000 is " . |
|||
0 ( mul3or5? if I n:+ then ) 1 999 loop . cr |
|||
with: n |
|||
: >triangular SED: n -- n |
|||
dup 1+ * 2 / ; |
|||
: sumdiv SED: n n -- n |
|||
dup >r /mod nip >triangular r> * ; |
|||
: sumdiv_3,5 SED: n -- n |
|||
( swap sumdiv ) curry [3, 5, 15] swap a:map a:open neg + + ; |
|||
;with |
|||
"For 10^20 - 1, the sum is " . 10 20 ^ 1- sumdiv_3,5 . cr |
|||
bye |
|||
</lang> |
|||
{{Out}} |
|||
<pre> |
|||
The sum of the multiples of 3 or 5 below 1000 is 233168 |
|||
For 10^20 - 1, the sum is 2333333333333333333316666666666666666668 |
|||
</pre> |
|||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
<lang 360asm>* Sum multiples of 3 and 5 |
<lang 360asm>* Sum multiples of 3 and 5 |