How to resolve the algorithm Sum multiples of 3 and 5 step by step in the AutoHotkey programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sum multiples of 3 and 5 step by step in the AutoHotkey programming language
Table of Contents
Problem Statement
The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sum multiples of 3 and 5 step by step in the AutoHotkey programming language
Source code in the autohotkey programming language
n := 1000
msgbox % "Sum is " . Sum3_5(n) . " for n = " . n
msgbox % "Sum is " . Sum3_5_b(n) . " for n = " . n
;Standard simple Implementation.
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
}
You may also check:How to resolve the algorithm Partial function application step by step in the Scala programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Undefined values step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the make programming language
You may also check:How to resolve the algorithm Range consolidation step by step in the Ada programming language