How to resolve the algorithm Summarize primes step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Summarize primes step by step in the Wren programming language
Table of Contents
Problem Statement
Considering in order of length, n, all sequences of consecutive primes, p, from 2 onwards, where p < 1000 and n>0, select those sequences whose sum is prime, and for these display the length of the sequence, the last item in the sequence, and the sum.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Summarize primes step by step in the Wren programming language
Source code in the wren programming language
import "/math" for Int
import "/fmt" for Fmt
var primes = Int.primeSieve(999)
var sum = 0
var n = 0
var c = 0
System.print("Summing the first n primes (<1,000) where the sum is itself prime:")
System.print(" n cumulative sum")
for (p in primes) {
n = n + 1
sum = sum + p
if (Int.isPrime(sum)) {
c = c + 1
Fmt.print("$3d $,6d", n, sum)
}
}
System.print("\n%(c) such prime sums found")
You may also check:How to resolve the algorithm Empty program step by step in the Racket programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the Clojure programming language
You may also check:How to resolve the algorithm Soloway's recurring rainfall step by step in the Arturo programming language
You may also check:How to resolve the algorithm File size step by step in the Oforth programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the FunL programming language