Truncatable primes: Difference between revisions
Content deleted Content added
CoffeeScript |
→{{header|CoffeeScript}}: refactor |
||
Line 337:
=={{header|CoffeeScript}}==
<lang coffeescript># 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
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"
▲ while candidate > 0
▲ return candidate if f(candidate)
▲ candidate -= 1
is_prime = (n) ->
|