Files
freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-38-pandigital-multiples.md
Oliver Eyton-Williams ee1e8abd87 feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

76 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 5900f3931000cf542c50fea5
title: 问题38Pandigital倍数
challengeType: 5
videoUrl: ''
dashedName: problem-38-pandigital-multiples
---
# --description--
取数字192并乘以1,2和3中的每一个192×1 = 192 192×2 = 384 192×3 = 576通过连接每个产品我们得到1到9 pandigital192384576。我们将调用192384576 192和1,2,3的连接产物。通过从9开始并乘以1,2,3,4和5可以实现相同的目的得到pandigital918273645它是9和1,2,3,4,5的连接产物。什么是最大的1到9 pandigital 9位数字可以形成一个整数与1,2... `n` )的连接乘积,其中`n` > 1
# --hints--
pandigitalMultiples `pandigitalMultiples()`应返回932718654。
```js
assert.strictEqual(pandigitalMultiples(), 932718654);
```
# --seed--
## --seed-contents--
```js
function pandigitalMultiples() {
return true;
}
pandigitalMultiples();
```
# --solutions--
```js
function pandigitalMultiples() {
function get9DigitConcatenatedProduct(num) {
// returns false if concatenated product is not 9 digits
let concatenatedProduct = num.toString();
for (let i = 2; concatenatedProduct.length < 9; i++) {
concatenatedProduct += num * i;
}
return concatenatedProduct.length === 9 ? concatenatedProduct : false;
}
function is1to9Pandigital(num) {
const numStr = num.toString();
// check if length is not 9
if (numStr.length !== 9) {
return false;
}
// check if pandigital
for (let i = 9; i > 0; i--) {
if (numStr.indexOf(i.toString()) === -1) {
return false;
}
}
return true;
}
let largestNum = 0;
for (let i = 9999; i >= 9000; i--) {
const concatenatedProduct = get9DigitConcatenatedProduct(i);
if (is1to9Pandigital(concatenatedProduct) && concatenatedProduct > largestNum) {
largestNum = parseInt(concatenatedProduct);
break;
}
}
return largestNum;
}
```