fix(curriculum): rework Project Euler 52 (#42434)
* fix: rework challenge to use argument in function * fix: update solution
This commit is contained in:
@ -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.
|
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--
|
# --hints--
|
||||||
|
|
||||||
`permutedMultiples()` should return a number.
|
`permutedMultiples(2)` should return a number.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert(typeof permutedMultiples() === 'number');
|
assert(typeof permutedMultiples(2) === 'number');
|
||||||
```
|
```
|
||||||
|
|
||||||
`permutedMultiples()` should return 142857.
|
`permutedMultiples(2)` should return `125874`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.strictEqual(permutedMultiples(), 142857);
|
assert.strictEqual(permutedMultiples(2), 125874);
|
||||||
|
```
|
||||||
|
|
||||||
|
`permutedMultiples(6)` should return `142857`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.strictEqual(permutedMultiples(6), 142857);
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
@ -31,18 +37,18 @@ assert.strictEqual(permutedMultiples(), 142857);
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function permutedMultiples() {
|
function permutedMultiples(n) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
permutedMultiples();
|
permutedMultiples(2);
|
||||||
```
|
```
|
||||||
|
|
||||||
# --solutions--
|
# --solutions--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function permutedMultiples() {
|
function permutedMultiples(n) {
|
||||||
const isPermutation = (a, b) =>
|
const isPermutation = (a, b) =>
|
||||||
a.length !== b.length
|
a.length !== b.length
|
||||||
? false
|
? false
|
||||||
@ -55,9 +61,9 @@ function permutedMultiples() {
|
|||||||
|
|
||||||
while (!found) {
|
while (!found) {
|
||||||
start *= 10;
|
start *= 10;
|
||||||
for (let i = start; i < start * 10 / 6; i++) {
|
for (let i = start; i < start * 10 / n; i++) {
|
||||||
found = true;
|
found = true;
|
||||||
for (let j = 2; j <= 6; j++) {
|
for (let j = 2; j <= n; j++) {
|
||||||
if (!isPermutation(i + '', j * i + '')) {
|
if (!isPermutation(i + '', j * i + '')) {
|
||||||
found = false;
|
found = false;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user