Truncatable primes: Difference between revisions

Added Uiua solution
No edit summary
(Added Uiua solution)
 
(4 intermediate revisions by 4 users not shown)
Line 996:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
if num < 2
return 0
.
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func isright h .
while h > 0
if isprim h = 0
return 0
.
h = h div 10
.
return 1
.
func isleft h .
d = pow 10 (floor log10 h)
while h > 0
if isprim h = 0
return 0
.
if h div d = 0
return 0
.
h = h mod d
d /= 10
.
return 1
.
p = 999999
while isleft p = 0
p -= 2
.
print p
p = 999999
while isright p = 0
p -= 2
.
print p
</syntaxhighlight>
 
{{out}}
<pre>
998443
739399
</pre>
 
=={{header|EchoLisp}}==
Line 1,184 ⟶ 1,240:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
 
Line 1,197 ⟶ 1,253:
if (n < 2) { ^ false };
if (n < 4) { ^ true };
if (n.mod:(2) == 0) { ^ false };
if (n < 9) { ^ true };
if (n.mod:(3) == 0) { ^ false };
int r := n.sqrt();
Line 3,270 ⟶ 3,326:
Largest left truncatable prime : 998443
Largest right truncatable prime : 739399
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ → trunc
≪ <span style="color:red">1000000</span>
'''DO'''
'''DO''' PREVPRIME '''UNTIL''' DUP →STR <span style="color:red">"0"</span> POS NOT '''END'''
DUP <span style="color:red">1</span> SF
'''DO'''
trunc EVAL
'''IF''' DUP ISPRIME? NOT '''THEN''' <span style="color:red">1</span> CF '''END'''
'''UNTIL''' DUP <span style="color:red">9</span> ≤ <span style="color:red">1</span> FC? OR '''END'''
DROP
'''UNTIL''' <span style="color:red">1</span> FS? '''END'''
≫ ≫ '<span style="color:blue">XTRUNC</span>' STO
 
≪ →STR TAIL STR→ ≫ <span style="color:blue">XTRUNC</span>
≪ <span style="color:red">10</span> / IP ≫ <span style="color:blue">XTRUNC</span>
{{out}}
<pre>
2: 998443
1: 739399
</pre>
 
Line 3,584 ⟶ 3,663:
searching for largest right-truncatable prime
FOUND:739399
</pre>
 
=={{header|Uiua}}==
<syntaxhighlight lang="uiua">
Mag ← 6
MaxP ← ⁿ:10⌊÷2Mag
# Pre-calculate primes up to root of largest n
Primes ← ⇌◌⍢(▽≠0◿⊢..⟜(⊂⊢)|>0⧻.):[]⊂2↘1+1×2⇡⌊÷2 MaxP # Build primes
IsPrime ← ⨬(/↧≡(≠0◿)|1)∊:,,Primes
RAdd ← ♭⊞(+×10):1_3_7_9 # Add suffixes
LAdd ← ♭⊞+×ⁿ:10⌈ₙ10⊢,+1⇡9 # Add prefixes
LastTP! ← ⊡¯1⍥(▽⊸≡IsPrime^!)-1Mag 2_3_5_7 # Build and filter
$"Right truncating: _"LastTP!RAdd
$"Left truncating: _"LastTP!LAdd
</syntaxhighlight>
{{out}}
<pre>
"Right truncating: 739399"
"Left truncating: 998443"
</pre>
 
Line 3,668 ⟶ 3,766:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./math" for Int
 
var limit = 999999
159

edits