Files
freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/project-euler/problem-52-permuted-multiples.english.md
Kristofer Koishigawa 6cfd0fc503 fix: improve Project Euler descriptions, challenge seeds, and test cases (#38016)
* fix: improve Project Euler descriptions and test case

Improve formatting of Project Euler test descriptions. Also add poker hands array and new test case for problem 54

* feat: add typeof tests and gave functions proper names for first 100 challenges

* fix: continue fixing test descriptions and adding "before test" sections

* fix: address review comments

* fix: adjust grids in 18 and 67 and fix some text that reference files rather than the given arrays

* fix: implement bug fixes and improvements from review

* fix: remove console.log statements from seed and solution
2020-02-28 06:39:47 -06:00

94 lines
1.7 KiB
Markdown

---
id: 5900f3a01000cf542c50feb3
challengeType: 5
title: 'Problem 52: Permuted multiples'
forumTopicId: 302163
---
## Description
<section id='description'>
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
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.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>permutedMultiples()</code> should return a number.
testString: assert(typeof permutedMultiples() === 'number');
- text: <code>permutedMultiples()</code> should return 142857.
testString: assert.strictEqual(permutedMultiples(), 142857);
```
</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
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;
}
```
</section>