2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: 5900f3901000cf542c50fea3
|
|
|
|
title: 'Problem 36: Double-base palindromes'
|
2020-11-27 18:02:05 +00:00
|
|
|
challengeType: 5
|
2019-08-05 16:17:33 +00:00
|
|
|
forumTopicId: 302020
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: problem-36-double-base-palindromes
|
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
|
|
|
|
|
|
|
The decimal number, 585 = 1001001001<sub>2</sub> (binary), is palindromic in both bases.
|
|
|
|
|
|
|
|
Find the sum of all numbers, less than `n`, whereas 1000 ≤ `n` ≤ 1000000, which are palindromic in base 10 and base 2.
|
|
|
|
|
2018-09-30 22:01:58 +00:00
|
|
|
(Please note that the palindromic number, in either base, may not include leading zeros.)
|
2020-02-28 12:39:47 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --hints--
|
|
|
|
|
|
|
|
`doubleBasePalindromes(1000)` should return a number.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(typeof doubleBasePalindromes(1000) === 'number');
|
|
|
|
```
|
|
|
|
|
|
|
|
`doubleBasePalindromes(1000)` should return 1772.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(doubleBasePalindromes(1000) == 1772);
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`doubleBasePalindromes(50000)` should return 105795.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(doubleBasePalindromes(50000) == 105795);
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`doubleBasePalindromes(500000)` should return 286602.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(doubleBasePalindromes(500000) == 286602);
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`doubleBasePalindromes(1000000)` should return 872187.
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(doubleBasePalindromes(1000000) == 872187);
|
|
|
|
```
|
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 doubleBasePalindromes(n) {
|
2020-09-15 16:57:40 +00:00
|
|
|
|
2018-09-30 22:01:58 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
doubleBasePalindromes(1000000);
|
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --solutions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|