How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Factor 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 Factor 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 Factor programming language
Source code in the factor programming language
USING: kernel math prettyprint ;
: sum-multiples ( m n upto -- sum )
>integer 1 - [ 2dup * ] dip
[ 2dup swap [ mod - + ] [ /i * 2/ ] 2bi ] curry tri@
[ + ] [ - ] bi* ;
3 5 1000 sum-multiples .
3 5 1e20 sum-multiples .
You may also check:How to resolve the algorithm URL encoding step by step in the C# programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the AntLang programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Oberon-2 programming language
You may also check:How to resolve the algorithm Digital root step by step in the Racket programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the AWK programming language