Primes whose first and last number is 3: Difference between revisions
Primes whose first and last number is 3 (view source)
Revision as of 16:16, 28 January 2024
, 3 months ago→{{header|Wren}}: Minor tidy
(→J: speedup 20x, add stretch goal) |
m (→{{header|Wren}}: Minor tidy) |
||
Line 1,030:
{{libheader|Wren-math}}
{{libheader|Wren-iterate}}
{{libheader|Wren-fmt}}
===Basic task===
<syntaxhighlight lang="
import "./iterate" for Stepped
import "./
var primes = []
Line 1,044 ⟶ 1,042:
}
System.print("Primes under 4,000 which begin and end in 3:")
System.print("\nFound %(primes.count) such primes.")</syntaxhighlight>
Line 1,059 ⟶ 1,057:
===More general===
This version deals with primes (in base 10) beginning and ending with any specified digit and with up to a given number of digits.
<syntaxhighlight lang="
import "./iterate" for Stepped
import "./
var getQualifyingPrimes = Fn.new { |x, d|
Line 1,084 ⟶ 1,081:
var len = d + ((d-1)/3).floor
Fmt.print("Primes under $,%(len)d which begin and end in $d:", 10.pow(d), x)
System.print("\nFound %(primes.count) such primes.\n")
}
|