Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Truncatable-primes/Ring/truncatable-primes.ring
Normal file
53
Task/Truncatable-primes/Ring/truncatable-primes.ring
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# Project : Truncatable primes
|
||||
|
||||
for n = 1000000 to 1 step -1
|
||||
flag = 1
|
||||
flag2 = 1
|
||||
strn = string(n)
|
||||
for nr = 1 to len(strn)
|
||||
if strn[nr] = "0"
|
||||
flag2 = 0
|
||||
ok
|
||||
next
|
||||
if flag2 = 1
|
||||
for m = 1 to len(strn)
|
||||
strp = right(strn, m)
|
||||
if isprime(number(strp))
|
||||
else
|
||||
flag = 0
|
||||
exit
|
||||
ok
|
||||
next
|
||||
if flag = 1
|
||||
nend = n
|
||||
exit
|
||||
ok
|
||||
ok
|
||||
next
|
||||
see "Largest left truncatable prime : " + nend + nl
|
||||
|
||||
for n = 1000000 to 1 step -1
|
||||
flag = 1
|
||||
strn = string(n)
|
||||
for m = 1 to len(strn)
|
||||
strp = left(strn, len(strn) - m + 1)
|
||||
if isprime(number(strp))
|
||||
else
|
||||
flag = 0
|
||||
exit
|
||||
ok
|
||||
next
|
||||
if flag = 1
|
||||
nend = n
|
||||
exit
|
||||
ok
|
||||
next
|
||||
see "Largest right truncatable prime : " + nend + nl
|
||||
|
||||
func isprime num
|
||||
if (num <= 1) return 0 ok
|
||||
if (num % 2 = 0 and num != 2) return 0 ok
|
||||
for i = 3 to floor(num / 2) -1 step 2
|
||||
if (num % i = 0) return 0 ok
|
||||
next
|
||||
return 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue