2018-09-30 22:01:58 +00:00
---
id: 5900f3911000cf542c50fea4
title: 'Problem 37: Truncatable primes'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 302031
2021-01-13 02:31:00 +00:00
dashedName: problem-37-truncatable-primes
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2020-02-28 12:39:47 +00:00
2018-09-30 22:01:58 +00:00
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.
2020-02-28 12:39:47 +00:00
Find the sum of the only `n` (8 ≤ `n` ≤ 11) primes that are both truncatable from left to right and right to left.
2018-09-30 22:01:58 +00:00
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.
2020-02-28 12:39:47 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
`truncatablePrimes(8)` should return a number.
```js
assert(typeof truncatablePrimes(8) === 'number');
```
`truncatablePrimes(8)` should return 1986.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(truncatablePrimes(8) == 1986);
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`truncatablePrimes(9)` should return 5123.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(truncatablePrimes(9) == 5123);
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`truncatablePrimes(10)` should return 8920.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(truncatablePrimes(10) == 8920);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
`truncatablePrimes(11)` should return 748317.
```js
assert(truncatablePrimes(11) == 748317);
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
function truncatablePrimes(n) {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return n;
}
truncatablePrimes(11);
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
// solution required
```