2018-10-10 18:03:03 -04:00
---
id: 5900f3a01000cf542c50feb3
challengeType: 5
title: 'Problem 52: Permuted multiples'
2019-08-28 16:26:13 +03:00
forumTopicId: 302163
2018-10-10 18:03:03 -04:00
localeTitle: 'Задача 52: Разрешенные множители'
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
Можно видеть, что число 125874 и е г о двойное 251748 содержат точно такие же цифры, но в другом порядке. Найдите наименьшее положительное целое число x, такое, что 2x, 3x, 4x, 5x и 6x содержат одинаковые цифры.
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > permutedMultiples()</ code > should return 142857.
testString: assert.strictEqual(permutedMultiples(), 142857);
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function permutedMultiples() {
// Good luck!
return true;
}
permutedMultiples();
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
function permutedMultiples() {
const isPermutation = (a, b) =>
a.length !== b.length
? false
: a.split('').sort().join() === b.split('').sort().join();
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++) {
if (!isPermutation(i + '', j * i + '')) {
found = false;
break;
}
}
if (found) {
result = i;
break;
}
}
}
return result;
}
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >