Jump to content

Sum multiples of 3 and 5: Difference between revisions

added autohotkey implementation
(Add a Limbo version)
(added autohotkey implementation)
Line 8:
{{out}}
<pre>233168</pre>
 
=={{header|AutoHotkey}}==
 
<lang AutoHotkey>n := 1000
 
msgbox % "Sum is " . Sum3_5(n) . " for n = " . n
msgbox % "Sum is " . Sum3_5_b(n) . " for n = " . n
 
;Standard simple Implentation.
Sum3_5(n) {
sum := 0
loop % n-1 {
if (!Mod(a_index,3) || !Mod(a_index,5))
sum:=sum+A_index
}
return sum
}
 
;Translated from the C++ version.
Sum3_5_b( i ) {
sum := 0, a := 0
while (a < 28)
{
if (!Mod(a,3) || !Mod(a,5))
{
sum += a
s := 30
while (s < i)
{
if (a+s < i)
sum += (a+s)
s+=30
}
}
a+=1
}
return sum
}</lang>
'''Output:''' <pre>Sum is 233168 for n = 1000
Sum is 233168 for n = 1000</pre>
 
=={{header|AWK}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.