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

m
m (→‎{{header|RPL}}: compact code)
m (→‎{{header|Wren}}: Minor tidy)
 
(2 intermediate revisions by one other user not shown)
Line 594:
There are 2251 3 x 3 primes below 1000000!
</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> primes3x3=. 3 ;@; 10 <@(#~ 1&p:)@(30&* + 3 + 10 * i.)@^ i.
 
primes3x3 3
3 313 353 373 383 3023 3083 3163 3203 3253 3313 3323 3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 3643 3673 3733 3793 3803 3823 3833 3853 3863 3923 3943
 
# primes3x3 5
2251</syntaxhighlight>
 
=={{header|jq}}==
Line 1,021 ⟶ 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,035 ⟶ 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,050 ⟶ 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,075 ⟶ 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