Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Additive-primes/Wren/additive-primes.wren
Normal file
23
Task/Additive-primes/Wren/additive-primes.wren
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import "/math" for Int
|
||||
import "/fmt" for Fmt
|
||||
|
||||
var sumDigits = Fn.new { |n|
|
||||
var sum = 0
|
||||
while (n > 0) {
|
||||
sum = sum + (n % 10)
|
||||
n = (n/10).floor
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
System.print("Additive primes less than 500:")
|
||||
var primes = Int.primeSieve(499)
|
||||
var count = 0
|
||||
for (p in primes) {
|
||||
if (Int.isPrime(sumDigits.call(p))) {
|
||||
count = count + 1
|
||||
Fmt.write("$3d ", p)
|
||||
if (count % 10 == 0) System.print()
|
||||
}
|
||||
}
|
||||
System.print("\n\n%(count) additive primes found.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue