Primes whose first and last number is 3: Difference between revisions

m
(→‎J: speedup 20x, add stretch goal)
m (→‎{{header|Wren}}: Minor tidy)
 
Line 1,030:
{{libheader|Wren-math}}
{{libheader|Wren-iterate}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
 
===Basic task===
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./iterate" for Stepped
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
var primes = []
Line 1,044 ⟶ 1,042:
}
System.print("Primes under 4,000 which begin and end in 3:")
for (chunk in Lst.chunks(primes, 11)) Fmt.printtprint("$,5d", chunkprimes, 11)
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="ecmascriptwren">import "./math" for Int
import "./iterate" for Stepped
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
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)
for (chunk in Lst.chunks(primes, 10)) Fmt.printtprint("$,%(len)d", chunkprimes, 10)
System.print("\nFound %(primes.count) such primes.\n")
}
9,476

edits