Primes whose first and last number is 3: Difference between revisions
Primes whose first and last number is 3 (view source)
Revision as of 22:01, 24 May 2024
, 1 month ago→{{header|EasyLang}}
(add RPL) |
|||
(6 intermediate revisions by 4 users not shown) | |||
Line 379:
</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
i += 1
.
return 1
.
fastfunc nextprim prim .
repeat
prim += 1
until isprim prim = 1
.
return prim
.
func digok n .
f = n mod 10
while n > 0
l = n mod 10
n = n div 10
.
return if f = 3 and l = 3
.
p = 2
repeat
if digok p = 1
write p & " "
.
p = nextprim p
until p >= 4000
.
</syntaxhighlight>
{{out}}
<pre>
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
</pre>
=={{header|F_Sharp|F#}}==
Line 594 ⟶ 635:
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 950 ⟶ 1,000:
Uses a candidate numbers generator to speed up execution.
{{works with|HP|49}}
▲ ≪ 1 SF ""
▲ digits DUP
'''IF''' DUP NOT '''THEN''' DROP digits SIZE '''ELSE''' 1 CF '''END'''▼
▲ ≪ { 3 } 303
'''WHILE''' DUP 4000 < '''REPEAT'''
'''IF''' DUP ISPRIME? '''THEN''' SWAP OVER + SWAP '''END'''
10 +
'''END''' DROP
≫ '<span style="color:blue">33PRIMES</span>' STO
Line 1,032 ⟶ 1,071:
{{libheader|Wren-math}}
{{libheader|Wren-iterate}}
{{libheader|Wren-fmt}}
===Basic task===
<syntaxhighlight lang="
import "./iterate" for Stepped
import "./
var primes = []
Line 1,046 ⟶ 1,083:
}
System.print("Primes under 4,000 which begin and end in 3:")
System.print("\nFound %(primes.count) such primes.")</syntaxhighlight>
Line 1,061 ⟶ 1,098:
===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,086 ⟶ 1,122:
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")
}
|