Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,69 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Containers.Ordered_Sets;
|
||||
|
||||
procedure Truncatable_Primes is
|
||||
package Natural_Set is new Ada.Containers.Ordered_Sets (Natural);
|
||||
use Natural_Set;
|
||||
|
||||
Primes : Set;
|
||||
|
||||
function Is_Prime (N : Natural) return Boolean is
|
||||
Position : Cursor := First (Primes);
|
||||
begin
|
||||
while Has_Element (Position) loop
|
||||
if N mod Element (Position) = 0 then
|
||||
return False;
|
||||
end if;
|
||||
Position := Next (Position);
|
||||
end loop;
|
||||
return True;
|
||||
end Is_Prime;
|
||||
|
||||
function Is_Left_Trucatable_Prime (N : Positive) return Boolean is
|
||||
M : Natural := 1;
|
||||
begin
|
||||
while Contains (Primes, N mod (M * 10)) and (N / M) mod 10 > 0 loop
|
||||
M := M * 10;
|
||||
if N <= M then
|
||||
return True;
|
||||
end if;
|
||||
end loop;
|
||||
return False;
|
||||
end Is_Left_Trucatable_Prime;
|
||||
|
||||
function Is_Right_Trucatable_Prime (N : Positive) return Boolean is
|
||||
M : Natural := N;
|
||||
begin
|
||||
while Contains (Primes, M) and M mod 10 > 0 loop
|
||||
M := M / 10;
|
||||
if M <= 1 then
|
||||
return True;
|
||||
end if;
|
||||
end loop;
|
||||
return False;
|
||||
end Is_Right_Trucatable_Prime;
|
||||
|
||||
Position : Cursor;
|
||||
begin
|
||||
for N in 2..1_000_000 loop
|
||||
if Is_Prime (N) then
|
||||
Insert (Primes, N);
|
||||
end if;
|
||||
end loop;
|
||||
Position := Last (Primes);
|
||||
while Has_Element (Position) loop
|
||||
if Is_Left_Trucatable_Prime (Element (Position)) then
|
||||
Put_Line ("Largest LTP from 1..1000000:" & Integer'Image (Element (Position)));
|
||||
exit;
|
||||
end if;
|
||||
Previous (Position);
|
||||
end loop;
|
||||
Position := Last (Primes);
|
||||
while Has_Element (Position) loop
|
||||
if Is_Right_Trucatable_Prime (Element (Position)) then
|
||||
Put_Line ("Largest RTP from 1..1000000:" & Integer'Image (Element (Position)));
|
||||
exit;
|
||||
end if;
|
||||
Previous (Position);
|
||||
end loop;
|
||||
end Truncatable_Primes;
|
||||
|
|
@ -1,46 +1,32 @@
|
|||
fastfunc isprim num .
|
||||
if num < 2
|
||||
return 0
|
||||
.
|
||||
if num < 2 : return 0
|
||||
i = 2
|
||||
while i <= sqrt num
|
||||
if num mod i = 0
|
||||
return 0
|
||||
.
|
||||
if num mod i = 0 : return 0
|
||||
i += 1
|
||||
.
|
||||
return 1
|
||||
.
|
||||
func isright h .
|
||||
while h > 0
|
||||
if isprim h = 0
|
||||
return 0
|
||||
.
|
||||
if isprim h = 0 : return 0
|
||||
h = h div 10
|
||||
.
|
||||
return 1
|
||||
.
|
||||
func isleft h .
|
||||
d = pow 10 (floor log10 h)
|
||||
d = pow 10 (floor log h 10)
|
||||
while h > 0
|
||||
if isprim h = 0
|
||||
return 0
|
||||
.
|
||||
if h div d = 0
|
||||
return 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
|
||||
.
|
||||
while isleft p = 0 : p -= 2
|
||||
print p
|
||||
p = 999999
|
||||
while isright p = 0
|
||||
p -= 2
|
||||
.
|
||||
while isright p = 0 : p -= 2
|
||||
print p
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ extension mathOp
|
|||
|
||||
while (n != 0)
|
||||
{
|
||||
ifnot (n.isPrime())
|
||||
if:not (n.isPrime())
|
||||
{ ^ false };
|
||||
|
||||
n := n / 10
|
||||
|
|
@ -52,7 +52,7 @@ extension mathOp
|
|||
|
||||
while (n != 0)
|
||||
{
|
||||
ifnot (n.isPrime())
|
||||
if:not (n.isPrime())
|
||||
{ ^ false };
|
||||
|
||||
tens := tens / 10;
|
||||
|
|
@ -63,7 +63,7 @@ extension mathOp
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var n := MAXN;
|
||||
var max_lt := 0;
|
||||
|
|
@ -87,8 +87,8 @@ public program()
|
|||
n := n - 1
|
||||
};
|
||||
|
||||
console.printLine("Largest truncable left is ",max_lt);
|
||||
console.printLine("Largest truncable right is ",max_rt);
|
||||
Console.printLine("Largest truncable left is ",max_lt);
|
||||
Console.printLine("Largest truncable right is ",max_rt);
|
||||
|
||||
console.readChar()
|
||||
Console.readChar()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
function IsPrime ( [int] $num )
|
||||
{
|
||||
$isprime = @{}
|
||||
2..[math]::sqrt($num) | Where-Object {
|
||||
$isprime[$_] -eq $null } | ForEach-Object {
|
||||
$_
|
||||
$isprime[$_] = $true
|
||||
for ( $i=$_*$_ ; $i -le $num; $i += $_ )
|
||||
{ $isprime[$i] = $false }
|
||||
}
|
||||
2..$num | Where-Object { $isprime[$_] -eq $null }
|
||||
}
|
||||
|
||||
function Truncatable ( [int] $num )
|
||||
{
|
||||
$declen = [math]::abs($num).ToString().Length
|
||||
$primes = @()
|
||||
$ltprimes = @{}
|
||||
$rtprimes = @{}
|
||||
1..$declen | ForEach-Object { $ltprimes[$_]=@{}; $rtprimes[$_]=@{} }
|
||||
IsPrime $num | ForEach-Object {
|
||||
$lastltprime = 2
|
||||
$lastrtprime = 2
|
||||
} {
|
||||
$curprim = $_
|
||||
$curdeclen = $curprim.ToString().Length
|
||||
$primes += $curprim
|
||||
if( $curdeclen -eq 1 ) {
|
||||
$ltprimes[1][$curprim] = $true
|
||||
$rtprimes[1][$curprim] = $true
|
||||
$lastltprime = $curprim
|
||||
$lastrtprime = $curprim
|
||||
} else {
|
||||
$curmod = $curprim % [math]::pow(10,$curdeclen - 1)
|
||||
$curdiv = [math]::floor($curprim / 10)
|
||||
if( $ltprimes[$curdeclen - 1][[int]$curmod] ) {
|
||||
$ltprimes[$curdeclen][$curprim] = $true
|
||||
$lastltprime = $curprim
|
||||
}
|
||||
if( $rtprimes[$curdeclen - 1][[int]$curdiv] ) {
|
||||
$rtprimes[$curdeclen][$curprim] = $true
|
||||
$lastrtprime = $curprim
|
||||
}
|
||||
}
|
||||
if( ( $ltprimes[$curdeclen - 2].Keys.count -gt 0 ) -and ( $ltprimes[$curdeclen - 1].Keys.count -gt 0 ) ) { $ltprimes[$curdeclen -2] = @{} }
|
||||
if( ( $rtprimes[$curdeclen - 2].Keys.count -gt 0 ) -and ( $rtprimes[$curdeclen - 1].Keys.count -gt 0 ) ) { $rtprimes[$curdeclen -2] = @{} }
|
||||
} {
|
||||
"Largest Left Truncatable Prime: $lastltprime"
|
||||
"Largest Right Truncatable Prime: $lastrtprime"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
-- 25 Apr 2025
|
||||
include Settings
|
||||
-- 24 Aug 2025
|
||||
include Setting
|
||||
arg xx
|
||||
say 'TRUNCATABLE PRIMES'
|
||||
say version
|
||||
|
|
@ -42,9 +42,4 @@ say 'Right' r1
|
|||
say
|
||||
return
|
||||
|
||||
include Sequences
|
||||
include Helper
|
||||
include Numbers
|
||||
include Functions
|
||||
include Constants
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
Mag ← 6
|
||||
Mag ← 6
|
||||
IsPrime ← =1⧻°/×
|
||||
RAdd ← ♭⊞(+×10):1_3_7_9 # Add suffixes
|
||||
LAdd ← ♭⊞+×⍜(ₙ10|⌈)⊢,+1⇡9 # Add prefixes
|
||||
LastTP! ← ⊡¯1⍥(▽⊸≡IsPrime^!)-1Mag 2_3_5_7 # Build and filter
|
||||
RAdd ← ♭⊞(+×10):1_3_7_9 # Add suffixes
|
||||
LAdd ← ♭⊞+×⍜(⌝˜ⁿ10|⌈)⊢:⊙.+1⇡9 # Add prefixes
|
||||
LastTP! ← ⊡¯1⍥(▽⊸≡IsPrime^0)-1Mag 2_3_5_7 # Build and filter
|
||||
|
||||
$"Right truncating: _"LastTP!RAdd
|
||||
$"Left truncating: _"LastTP!LAdd
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
start_time = Now
|
||||
|
||||
lt = 0
|
||||
rt = 0
|
||||
|
||||
For h = 1 To 1000000
|
||||
If IsLeftTruncatable(h) And h > lt Then
|
||||
lt = h
|
||||
End If
|
||||
If IsRightTruncatable(h) And h > rt Then
|
||||
rt = h
|
||||
End If
|
||||
Next
|
||||
|
||||
end_time = now
|
||||
|
||||
WScript.StdOut.WriteLine "Largest LTP from 1..1000000: " & lt
|
||||
WScript.StdOut.WriteLine "Largest RTP from 1..1000000: " & rt
|
||||
WScript.StdOut.WriteLine "Elapse Time(seconds) : " & DateDiff("s",start_time,end_time)
|
||||
|
||||
'------------
|
||||
Function IsLeftTruncatable(n)
|
||||
IsLeftTruncatable = False
|
||||
c = 0
|
||||
For i = Len(n) To 1 Step -1
|
||||
If InStr(1,n,"0") > 0 Then
|
||||
Exit For
|
||||
End If
|
||||
If IsPrime(Right(n,i)) Then
|
||||
c = c + 1
|
||||
End If
|
||||
Next
|
||||
If c = Len(n) Then
|
||||
IsLeftTruncatable = True
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function IsRightTruncatable(n)
|
||||
IsRightTruncatable = False
|
||||
c = 0
|
||||
For i = Len(n) To 1 Step -1
|
||||
If InStr(1,n,"0") > 0 Then
|
||||
Exit For
|
||||
End If
|
||||
If IsPrime(Left(n,i)) Then
|
||||
c = c + 1
|
||||
End If
|
||||
Next
|
||||
If c = Len(n) Then
|
||||
IsRightTruncatable = True
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function IsPrime(n)
|
||||
If n = 2 Then
|
||||
IsPrime = True
|
||||
ElseIf n <= 1 Or n Mod 2 = 0 Then
|
||||
IsPrime = False
|
||||
Else
|
||||
IsPrime = True
|
||||
For i = 3 To Int(Sqr(n)) Step 2
|
||||
If n Mod i = 0 Then
|
||||
IsPrime = False
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue