Find largest left truncatable prime in a given base: Difference between revisions
Content added Content deleted
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
(Added Maple Code) |
||
Line 1,032: | Line 1,032: | ||
17 13563641583101</pre> |
17 13563641583101</pre> |
||
=={{header|Maple}}== |
|||
<lang maple>MaxLeftTruncatablePrime := proc(b, $) |
|||
local i, j, c, p, sdprimes; |
|||
local tprimes := table(); |
|||
sdprimes := select(isprime, [seq(1..b-1)]); |
|||
for p in sdprimes do |
|||
if assigned(tprimes[p]) then |
|||
next; |
|||
end if; |
|||
i := ilog[b](p)+1; |
|||
j := 1; |
|||
do |
|||
c := j*b^i + p; |
|||
if j >= b then |
|||
# we have tried all 1 digit extensions of p, add p to tprimes and move back 1 digit |
|||
tprimes[p] := p; |
|||
if i = 1 then |
|||
# if we are at the first digit, go to the next 1 digit prime |
|||
break; |
|||
end if; |
|||
i := i - 1; |
|||
j := 1; |
|||
p := p - iquo(p, b^i)*b^i; |
|||
elif assigned(tprimes[c]) then |
|||
j := j + 1; |
|||
elif isprime(c) then |
|||
p := c; |
|||
i := i + 1; |
|||
j := 1; |
|||
else |
|||
j := j+1; |
|||
end if; |
|||
end do; |
|||
end do; |
|||
return max(indices(tprimes, 'nolist')); |
|||
end proc;</lang> |
|||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |