fix(curriculum): rework Project Euler 52 (#42434)

* fix: rework challenge to use argument in function

* fix: update solution
pull/42469/head
gikf 2021-06-13 13:30:32 +02:00 committed by GitHub
parent 53f6a28ad9
commit d14008b32c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 10 deletions

View File

@ -10,20 +10,26 @@ dashedName: problem-52-permuted-multiples
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, `x`, such that `2x`, `3x`, `4x`, `5x`, and `6x`, contain the same digits.
Find the smallest positive integer, such that multiplied by integers $\\{2, 3, \ldots, n\\}$, contain the same digits.
# --hints--
`permutedMultiples()` should return a number.
`permutedMultiples(2)` should return a number.
```js
assert(typeof permutedMultiples() === 'number');
assert(typeof permutedMultiples(2) === 'number');
```
`permutedMultiples()` should return 142857.
`permutedMultiples(2)` should return `125874`.
```js
assert.strictEqual(permutedMultiples(), 142857);
assert.strictEqual(permutedMultiples(2), 125874);
```
`permutedMultiples(6)` should return `142857`.
```js
assert.strictEqual(permutedMultiples(6), 142857);
```
# --seed--
@ -31,18 +37,18 @@ assert.strictEqual(permutedMultiples(), 142857);
## --seed-contents--
```js
function permutedMultiples() {
function permutedMultiples(n) {
return true;
}
permutedMultiples();
permutedMultiples(2);
```
# --solutions--
```js
function permutedMultiples() {
function permutedMultiples(n) {
const isPermutation = (a, b) =>
a.length !== b.length
? false
@ -55,9 +61,9 @@ function permutedMultiples() {
while (!found) {
start *= 10;
for (let i = start; i < start * 10 / 6; i++) {
for (let i = start; i < start * 10 / n; i++) {
found = true;
for (let j = 2; j <= 6; j++) {
for (let j = 2; j <= n; j++) {
if (!isPermutation(i + '', j * i + '')) {
found = false;
break;