Truncatable primes: Difference between revisions

Content deleted Content added
CoffeeScript
Line 337:
 
=={{header|CoffeeScript}}==
<lang coffeescript># You could have symmetric algorithms for max right and left
# You could have symmetric algorithms for max right and left
# truncatable numbers, but they lend themselves to slightly
# different optimizations.
Line 349 ⟶ 348:
# the 10 possibilities for the last digit.
if n < 10
max_digitcandidate = n, f
while candidate > 0
return candidate if f(candidate)
candidate -= 1
else
left = Math.floor n / 10
Line 361 ⟶ 363:
left -= 1
right = 9
throw Error "none found"
max_left_truncatable_number = (max, f) ->
Line 383 ⟶ 386:
n -= 1
throw Error "none found"
 
max_digit = (n, f) ->
# return max digit <= n where fn(fn) is true
candidate = n
while candidate > 0
return candidate if f(candidate)
candidate -= 1
is_prime = (n) ->