2018-09-30 23:01:58 +01:00
---
id: 5900f3a01000cf542c50feb3
challengeType: 5
title: 'Problem 52: Permuted multiples'
2019-08-05 09:17:33 -07:00
forumTopicId: 302163
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
2020-02-28 21:39:47 +09:00
2018-09-30 23:01:58 +01:00
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
2020-02-28 21:39:47 +09:00
Find the smallest positive integer, < var > x< / var > , such that < var > 2x< / var > , < var > 3x< / var > , < var > 4x< / var > , < var > 5x< / var > , and < var > 6x< / var > , contain the same digits.
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
2020-02-28 21:39:47 +09:00
- text: < code > permutedMultiples()</ code > should return a number.
testString: assert(typeof permutedMultiples() === 'number');
2018-10-04 14:37:37 +01:00
- text: < code > permutedMultiples()</ code > should return 142857.
2019-07-26 19:45:56 -07:00
testString: assert.strictEqual(permutedMultiples(), 142857);
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function permutedMultiples() {
2020-09-15 09:57:40 -07:00
2018-09-30 23:01:58 +01:00
return true;
}
permutedMultiples();
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
function permutedMultiples() {
2018-10-08 01:01:53 +01:00
const isPermutation = (a, b) =>
a.length !== b.length
2018-09-30 23:01:58 +01:00
? false
2018-10-02 15:02:53 +01:00
: a.split('').sort().join() === b.split('').sort().join();
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
let start = 1;
let found = false;
let result = 0;
while (!found) {
start *= 10;
for (let i = start; i < start * 10 / 6 ; i + + ) {
found = true;
for (let j = 2; j < = 6; j++) {
2018-10-20 21:02:47 +03:00
if (!isPermutation(i + '', j * i + '')) {
2018-09-30 23:01:58 +01:00
found = false;
break;
}
}
if (found) {
result = i;
break;
}
}
}
return result;
}
```
< / section >