Sum multiples of 3 and 5: Difference between revisions

m
Adding the immediate (and slower) solution
m (Adding the immediate (and slower) solution)
Line 3,967:
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
===Simple solution===
Just counting...
≪ 0 1 DO
1 +
IF DUP 3 MOD NOT OVER 5 MOD NOT OR THEN SWAP OVER + SWAP END
UNTIL DUP 4 PICK == END
ROT DROP2
===Efficient solution===
This is a straightforward way to calculate the sum for higher values of n, taking into account that the sum of multiples of 3 and 5 is the sum of multiples of 3 and the sum of multiples of 5, minus the sum of multiples of 15 to remove double counting.
≪ → n
≪ 0 1 3 FOR j
Line 3,975 ⟶ 3,985:
≫ ≫
‘SUM35’ STO
 
999 SUM35
{{out}}
Line 3,980 ⟶ 3,991:
1: 233168
</pre>
 
=={{header|Ruby}}==
Simple Version (Slow):
1,150

edits