PBT 2021 の到来 - 17 日目 - 解決策
7793 ワード
私たちのアルゴリズムは: isHumbleNumber です.
付属している可能性のある一連のプロパティを含む CodeSandbox: https://codesandbox.io/s/advent-of-pbt-day-17-solution-75tuu?file=/src/index.spec.ts&previewwindow=tests
高速チェックで書かれています:
高速チェックで書かれています:
他の日に取り上げられたトピックとその解決策を確認するには.
このシリーズの詳細については、ハッシュタグ .
付属している可能性のある一連のプロパティを含む CodeSandbox: https://codesandbox.io/s/advent-of-pbt-day-17-solution-75tuu?file=/src/index.spec.ts&previewwindow=tests
プロパティ 1: 素数 <=7 の任意の合成を謙虚と見なす必要があります
for any number n product of factors <=7
it should consider n as an humble number
高速チェックで書かれています:
it("should consider any composite of primes <=7 as humble", () => {
fc.assert(
fc.property(
fc.array(fc.integer({ min: 2, max: 7 }), { minLength: 1 }),
(factors) => {
// Arrange
let n = 1;
for (const f of factors) {
if (n * f > 2 ** 31 - 1) break;
n = n * f;
}
// Act / Assert
expect(isHumbleNumber(n)).toBe(true);
}
)
);
});
プロパティ 2: 1 つの素因数が 7 を超える合成は非謙虚と見なす必要があります
for any number n with at least one factor not divisible by any number in [2, 7]
it should consider n as a non-humble number
高速チェックで書かれています:
it("should consider any composite with one prime factor >7 as non-humble", () => {
fc.assert(
fc.property(
fc
.integer({ min: 11 }) // 8,9,10 would be filtered
.filter((v) => v % 2 !== 0)
.filter((v) => v % 3 !== 0)
.filter((v) => v % 5 !== 0)
.filter((v) => v % 7 !== 0),
fc.array(fc.integer({ min: 1, max: 195225786 })),
(tooLarge, factors) => {
// Arrange
let n = tooLarge;
for (const f of factors) {
if (n * f > 2 ** 31 - 1) break;
n = n * f;
}
// Act / Assert
expect(isHumbleNumber(n)).toBe(false);
}
)
);
});
他の日に取り上げられたトピックとその解決策を確認するには.
このシリーズの詳細については、ハッシュタグ .
Reference
この問題について(PBT 2021 の到来 - 17 日目 - 解決策), 我々は、より多くの情報をここで見つけました https://dev.to/dubzzz/advent-of-pbt-2021-day-17-solution-3gfeテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol