Strong and weak primes: Difference between revisions

Added Wren
m (C++ - renamed class)
(Added Wren)
Line 1,721:
Count of balanced primes <= 1,000,000: 2,994
Count of balanced primes <= 10,000,000: 21,837
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
import "/fmt" for Fmt
 
var primes = Int.primeSieve(1e7 + 19) // next prime above 10 million
var strong = []
var weak = []
for (p in 1...primes.count-1) {
if (primes[p] > (primes[p-1] + primes[p+1]) / 2) {
strong.add(primes[p])
} else if (primes[p] < (primes[p-1] + primes[p+1]) / 2) {
weak.add(primes[p])
}
}
 
System.print("The first 36 strong primes are:")
Fmt.print("$d", strong.take(36).toList)
Fmt.print("\nThe count of the strong primes below $,d is $,d.", 1e6, strong.count{ |n| n < 1e6 })
Fmt.print("\nThe count of the strong primes below $,d is $,d.", 1e7, strong.count{ |n| n < 1e7 })
 
System.print("\nThe first 37 weak primes are:")
Fmt.print("$d", weak.take(37).toList)
Fmt.print("\nThe count of the weak primes below $,d is $,d.", 1e6, weak.count{ |n| n < 1e6 })
Fmt.print("\nThe count of the weak primes below $,d is $,d.", 1e7, weak.count{ |n| n < 1e7 })</lang>
 
{{out}}
<pre>
The first 36 strong primes are:
11 17 29 37 41 59 67 71 79 97 101 107 127 137 149 163 179 191 197 223 227 239 251 269 277 281 307 311 331 347 367 379 397 419 431 439
 
The count of the strong primes below 1,000,000 is 37,723.
 
The count of the strong primes below 10,000,000 is 320,991.
 
The first 37 weak primes are:
3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131 139 151 167 181 193 199 229 233 241 271 283 293 313 317 337 349 353 359 383 389 401
 
The count of the weak primes below 1,000,000 is 37,780.
 
The count of the weak primes below 10,000,000 is 321,750.
</pre>
 
9,485

edits