chore(i18n,learn): processed translations (#44866)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339acb
|
||||
title: 100 doors
|
||||
title: 100個のドア
|
||||
challengeType: 5
|
||||
forumTopicId: 302217
|
||||
dashedName: 100-doors
|
||||
@ -8,27 +8,27 @@ dashedName: 100-doors
|
||||
|
||||
# --description--
|
||||
|
||||
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and 'toggle' the door (if the door is closed, open it; if it is open, close it). The second time, only visit every 2nd door (i.e., door #2, #4, #6, ...) and toggle it. The third time, visit every 3rd door (i.e., door #3, #6, #9, ...), etc., until you only visit the 100th door.
|
||||
100個のドアが連続してあり、最初はすべてのドアは閉じています。 100個のドア全てを対象とします。 1回目はすべてのドアを訪問し、ドアを「切り替え」(ドアが閉じられている場合は、開き、開いている場合は、閉じる)ます。 2回目は、2の倍数のドア(#2のドア、#4のドア、#6のドア...)に訪問し、それぞれの開閉を「切り替え」ます。 3回目は、3の倍数のドア(#3のドア、#6のドア、#9のドア...)を訪問して「切替」を行い、100番目のドアまで続けます。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function to determine the state of the doors after the last pass. Return the final result in an array, with only the door number included in the array if it is open.
|
||||
3回の訪問が終了した時点でのドアの状態を示す関数を作成します。 配列形式で最終的な結果を返します。開いている状態のドアの番号を配列形式で返します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`getFinalOpenedDoors` should be a function.
|
||||
`getFinalOpenedDoors` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof getFinalOpenedDoors === 'function');
|
||||
```
|
||||
|
||||
`getFinalOpenedDoors` should return an array.
|
||||
`getFinalOpenedDoors` は配列を返します。
|
||||
|
||||
```js
|
||||
assert(Array.isArray(getFinalOpenedDoors(100)));
|
||||
```
|
||||
|
||||
`getFinalOpenedDoors` should produce the correct result.
|
||||
`getFinalOpenedDoors` は正確な結果を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getFinalOpenedDoors(100), solution);
|
||||
|
@ -8,23 +8,23 @@ dashedName: 24-game
|
||||
|
||||
# --description--
|
||||
|
||||
The [24 Game](https://en.wikipedia.org/wiki/24_Game) tests a person's mental arithmetic.
|
||||
[24 Game](https://en.wikipedia.org/wiki/24_Game) では、人の暗算能力をテストします。
|
||||
|
||||
The aim of the game is to arrange four numbers in a way that when evaluated, the result is 24
|
||||
ゲームの目的は、算出結果が24になるように4つの数字を配置することです。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function that takes a string of four digits as its argument, with each digit from 1 to 9 (inclusive) with repetitions allowed, and returns an arithmetic expression that evaluates to the number 24. If no such solution exists, return "no solution exists".
|
||||
4桁の文字列を引数とする関数を作成します。 各桁は、1 から 9 までの数字で、繰り返しも可能です。この関数は、算出結果が数値 24 になる算術式を返します。 そのような解が存在しない場合は、「解が存在しません」を返します。
|
||||
|
||||
**Rules:**
|
||||
**ルール:**
|
||||
<ul>
|
||||
<li> Only the following operators/functions are allowed: multiplication, division, addition, subtraction. </li>
|
||||
<li> Division should use floating point or rational arithmetic, etc, to preserve remainders. </li>
|
||||
<li> Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong). </li>
|
||||
<li> The order of the digits when given does not have to be preserved. </li>
|
||||
<li> 以下の演算子/関数のみが使用できます: 乗算、除算、加算、減算。 </li>
|
||||
<li> 除算では、余りを保持するために浮動小数点や有理数演算などを使用します。 </li>
|
||||
<li> 与えられた数字から複数の桁数を作成することはできません。 (つまり、1、2、2、1が与えられた場合、12+12という答えは間違っています)。 </li>
|
||||
<li> 与えられた数字の順序は保持する必要がありません。 </li>
|
||||
</ul>
|
||||
|
||||
| Example input | Example output |
|
||||
| 入力例 | 出力例 |
|
||||
| ------------------------- | ------------------------- |
|
||||
| <code>solve24("4878");</code> | <code>(7-8/8)\*4</code> |
|
||||
| <code>solve24("1234");</code> | <code>3\*1\*4\*2</code> |
|
||||
@ -33,31 +33,31 @@ Implement a function that takes a string of four digits as its argument, with ea
|
||||
|
||||
# --hints--
|
||||
|
||||
`solve24` should be a function.
|
||||
`solve24` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof solve24 === 'function');
|
||||
```
|
||||
|
||||
`solve24("4878")` should return `(7-8/8)*4` or `4*(7-8/8)`
|
||||
`solve24("4878")` は `(7-8/8)*4` または `4*(7-8/8)` を返します。
|
||||
|
||||
```js
|
||||
assert(include(answers[0], removeParentheses(solve24(testCases[0]))));
|
||||
```
|
||||
|
||||
`solve24("1234")` should return any arrangement of `1*2*3*4`
|
||||
`solve24("1234")` は任意の配列で `1*2*3*4` を返します。
|
||||
|
||||
```js
|
||||
assert(include(answers[1], removeParentheses(solve24(testCases[1]))));
|
||||
```
|
||||
|
||||
`solve24("6789")` should return `(6*8)/(9-7)` or `(8*6)/(9-7)`
|
||||
`solve24("6789")` は `(6*8)/(9-7)` または `(8*6)/(9-7)` を返します。
|
||||
|
||||
```js
|
||||
assert(include(answers[2], removeParentheses(solve24(testCases[2]))));
|
||||
```
|
||||
|
||||
`solve24("1127")` should return a permutation of `(1+7)*(1+2)`
|
||||
`solve24("1127")` は `(1+7)*(1+2)` の順列を返します。
|
||||
|
||||
```js
|
||||
assert(include(answers[3], removeParentheses(solve24(testCases[3]))));
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5949b579404977fbaefcd736
|
||||
title: 9 billion names of God the integer
|
||||
title: 90億の神の御名 整数
|
||||
challengeType: 5
|
||||
forumTopicId: 302219
|
||||
dashedName: 9-billion-names-of-god-the-integer
|
||||
@ -8,77 +8,77 @@ dashedName: 9-billion-names-of-god-the-integer
|
||||
|
||||
# --description--
|
||||
|
||||
This task is a variation of the [short story by Arthur C. Clarke](https://en.wikipedia.org/wiki/The Nine Billion Names of God#Plot_summary "wp: The Nine Billion Names of God#Plot_summary").
|
||||
このタスクは、[アーサー・C・クラークの短編](https://en.wikipedia.org/wiki/The Nine Billion Names of God#Plot_summary "wp: The Nine Billion Names of God#Plot_summary")のバリエーションです。
|
||||
|
||||
(Solvers should be aware of the consequences of completing this task.)
|
||||
(ソルバーは、このタスクの完了結果を認識している必要があります。)
|
||||
|
||||
In detail, to specify what is meant by a "name":
|
||||
「名前」が意味するものを詳細に示します。
|
||||
|
||||
<ul>
|
||||
<li>The integer 1 has 1 name "1".</li>
|
||||
<li>The integer 2 has 2 names "1+1" and "2".</li>
|
||||
<li>The integer 3 has 3 names "1+1+1", "2+1", and "3".</li>
|
||||
<li>The integer 4 has 5 names "1+1+1+1", "2+1+1", "2+2", "3+1", "4".</li>
|
||||
<li>The integer 5 has 7 names "1+1+1+1+1", "2+1+1+1", "2+2+1", "3+1+1", "3+2", "4+1", "5".</li>
|
||||
<li>整数1には、「1」という名前があります。</li>
|
||||
<li>整数2には、「1+1」と「2」という2つの名前があります。</li>
|
||||
<li>整数3には、「1+1+ 1」と「2+1」と「3」という3つの名前があります。</li>
|
||||
<li>整数4には、「1+1+1+1」と「2+1」と「2+2」と「3+1」と「4」という5つの名前があります。</li>
|
||||
<li>整数 5 には、「1+1+1+1+1」と「2+1+1+ 1」と「2+2+1」と「3+1+1」と「3+2」と「4+1」と「5」という7つの名前があります。</li>
|
||||
</ul>
|
||||
|
||||
This can be visualized in the following form:
|
||||
これは以下の形式で表すことができます。
|
||||
|
||||
<pre> 1
|
||||
1 1
|
||||
1 1 1
|
||||
1 2 1 1
|
||||
1 2 2 1 1
|
||||
1 3 3 2 1 1
|
||||
1 1
|
||||
1 1 1
|
||||
1 2 1 1
|
||||
1 2 1 1 1
|
||||
1 3 3 2 1 1
|
||||
</pre>
|
||||
|
||||
Where row $n$ corresponds to integer $n$, and each column $C$ in row $m$ from left to right corresponds to the number of names beginning with $C$.
|
||||
$n$ 行は、整数 $n$に相当し、左から右への $m$行内の$C$の各列は、$C$で始まる名前の数に相当します。
|
||||
|
||||
Optionally note that the sum of the $n$-th row $P(n)$ is the integer partition function.
|
||||
また、$n$番目の $P(n)$ 行の合計は、整数パーティション関数であることに注意してください。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function that returns the sum of the $n$-th row.
|
||||
$n$番目の行の合計を返す関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`numberOfNames` should be function.
|
||||
`numberOfNames` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof numberOfNames === 'function');
|
||||
```
|
||||
|
||||
`numberOfNames(5)` should equal 7.
|
||||
`numberOfNames(5)` は7に等しいです。
|
||||
|
||||
```js
|
||||
assert.equal(numberOfNames(5), 7);
|
||||
```
|
||||
|
||||
`numberOfNames(12)` should equal 77.
|
||||
`numberOfNames(12)` は77に等しいです。
|
||||
|
||||
```js
|
||||
assert.equal(numberOfNames(12), 77);
|
||||
```
|
||||
|
||||
`numberOfNames(18)` should equal 385.
|
||||
`numberOfNames(18)` は385に等しいです。
|
||||
|
||||
```js
|
||||
assert.equal(numberOfNames(18), 385);
|
||||
```
|
||||
|
||||
`numberOfNames(23)` should equal 1255.
|
||||
`numberOfNames(23)` は1255に等しいです。
|
||||
|
||||
```js
|
||||
assert.equal(numberOfNames(23), 1255);
|
||||
```
|
||||
|
||||
`numberOfNames(42)` should equal 53174.
|
||||
`numberOfNames(42)` は53174に等しいです。
|
||||
|
||||
```js
|
||||
assert.equal(numberOfNames(42), 53174);
|
||||
```
|
||||
|
||||
`numberOfNames(123)` should equal 2552338241.
|
||||
`numberOfNames(123)` は2552338241に等しいです。
|
||||
|
||||
```js
|
||||
assert.equal(numberOfNames(123), 2552338241);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339acc
|
||||
title: ABC Problem
|
||||
title: ABC問題
|
||||
challengeType: 5
|
||||
forumTopicId: 302220
|
||||
dashedName: abc-problem
|
||||
@ -8,7 +8,7 @@ dashedName: abc-problem
|
||||
|
||||
# --description--
|
||||
|
||||
You are given a collection of ABC blocks (e.g., childhood alphabet blocks). There are 20 blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks:
|
||||
ABCブロック一式が与えられます (例えば、子供用のアルファベットブロック)。 20個のブロックがあり、各ブロックに2文字入っています。 ブロックの全側面を見れば、すべてのアルファベットが必ずあります。 ブロックのサンプル一式:
|
||||
|
||||
<pre>(B O)
|
||||
(X K)
|
||||
@ -34,60 +34,60 @@ You are given a collection of ABC blocks (e.g., childhood alphabet blocks). Ther
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks.
|
||||
文字列(単語)を取って、与えられたブロック一式で単語が作れるかを判定する関数を作成します。
|
||||
|
||||
Some rules to keep in mind:
|
||||
留意すべきルール:
|
||||
|
||||
<ul>
|
||||
<li>Once a letter on a block is used, that block cannot be used again.</li>
|
||||
<li>The function should be case-insensitive.</li>
|
||||
<li>ブロック上の文字を使用すると、そのブロックは再度使用することはできません。</li>
|
||||
<li>関数は大文字小文字を区別しません。</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`canMakeWord` should be a function.
|
||||
`canMakeWord` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof canMakeWord === 'function');
|
||||
```
|
||||
|
||||
`canMakeWord` should return a boolean.
|
||||
`canMakeWord` はブール値を返します。
|
||||
|
||||
```js
|
||||
assert(typeof canMakeWord('hi') === 'boolean');
|
||||
```
|
||||
|
||||
`canMakeWord("bark")` should return true.
|
||||
`canMakeWord("bark")`は真を返します。
|
||||
|
||||
```js
|
||||
assert(canMakeWord(words[0]));
|
||||
```
|
||||
|
||||
`canMakeWord("BooK")` should return false.
|
||||
`canMakeWord("BooK")`は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!canMakeWord(words[1]));
|
||||
```
|
||||
|
||||
`canMakeWord("TReAT")` should return true.
|
||||
`canMakeWord("TReAT")`は真を返します。
|
||||
|
||||
```js
|
||||
assert(canMakeWord(words[2]));
|
||||
```
|
||||
|
||||
`canMakeWord("COMMON")` should return false.
|
||||
`canMakeWord("COMMON")`は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!canMakeWord(words[3]));
|
||||
```
|
||||
|
||||
`canMakeWord("squAD")` should return true.
|
||||
`canMakeWord("squAD")`は真を返します。
|
||||
|
||||
```js
|
||||
assert(canMakeWord(words[4]));
|
||||
```
|
||||
|
||||
`canMakeWord("conFUSE")` should return true.
|
||||
`canMakeWord("conFUSE")`は真を返します。
|
||||
|
||||
```js
|
||||
assert(canMakeWord(words[5]));
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339acd
|
||||
title: 'Abundant, deficient and perfect number classifications'
|
||||
title: '余剰数、不足数、完全数の分類'
|
||||
challengeType: 5
|
||||
forumTopicId: 302221
|
||||
dashedName: abundant-deficient-and-perfect-number-classifications
|
||||
@ -8,55 +8,55 @@ dashedName: abundant-deficient-and-perfect-number-classifications
|
||||
|
||||
# --description--
|
||||
|
||||
These define three classifications of positive integers based on their proper divisors.
|
||||
真の約数に基づいて、正の整数を3つに分類します。
|
||||
|
||||
Let $P(n)$ be the sum of the proper divisors of `n` where proper divisors are all positive integers `n` other than `n` itself.
|
||||
$P(n)$ は、真の約数が `n` 自身以外の正の整数 `n` である場合の `n` の真の約数の総和です。
|
||||
|
||||
If `P(n) < n` then `n` is classed as `deficient`
|
||||
`P(n) < n` の場合、`n` は `deficient` に分類されます。
|
||||
|
||||
If `P(n) === n` then `n` is classed as `perfect`
|
||||
`P(n) === n` の場合、`n` は `perfect` に分類されます。
|
||||
|
||||
If `P(n) > n` then `n` is classed as `abundant`
|
||||
`P(n) > n` の場合 `n` は `abundant`に分類されます。
|
||||
|
||||
**Example**: `6` has proper divisors of `1`, `2`, and `3`. `1 + 2 + 3 = 6`, so `6` is classed as a perfect number.
|
||||
**例**: `6` の真の約数は、`1`, `2`, `3`です。 `1 + 2 + 3 = 6` なので、`6` は完全数に分類されます。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function that calculates how many of the integers from `1` to `num` (inclusive) are in each of the three classes. Output the result as an array in the following format `[deficient, perfect, abundant]`.
|
||||
3つの分類に、`1` から `num` までの整数が、それぞれいくつ含まれるかを計算する関数を作成します。 `[deficient, perfect, abundant]` の形式で、結果を配列として出力します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`getDPA` should be a function.
|
||||
`getDPA` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof getDPA === 'function');
|
||||
```
|
||||
|
||||
`getDPA(5000)` should return an array.
|
||||
`getDPA(5000)` は配列を返します。
|
||||
|
||||
```js
|
||||
assert(Array.isArray(getDPA(5000)));
|
||||
```
|
||||
|
||||
`getDPA(5000)` return array should have a length of `3`.
|
||||
`getDPA(5000)` は長さ`3`の配列を返します。
|
||||
|
||||
```js
|
||||
assert(getDPA(5000).length === 3);
|
||||
```
|
||||
|
||||
`getDPA(5000)` should return `[3758, 3, 1239]`.
|
||||
`getDPA(5000)` は`[3758, 3, 1239]`を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getDPA(5000), [3758, 3, 1239]);
|
||||
```
|
||||
|
||||
`getDPA(10000)` should return `[7508, 4, 2488]`.
|
||||
`getDPA(10000)` は`[7508, 4, 2488]`を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getDPA(10000), [7508, 4, 2488]);
|
||||
```
|
||||
|
||||
`getDPA(20000)` should return `[15043, 4, 4953]`.
|
||||
`getDPA(20000)` は`[15043, 4, 4953]`を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getDPA(20000), [15043, 4, 4953]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ace
|
||||
title: Accumulator factory
|
||||
title: アキュムレータ・ファクトリ
|
||||
challengeType: 5
|
||||
forumTopicId: 302222
|
||||
dashedName: accumulator-factory
|
||||
@ -8,41 +8,41 @@ dashedName: accumulator-factory
|
||||
|
||||
# --description--
|
||||
|
||||
A problem posed by [Paul Graham](https://en.wikipedia.org/wiki/Paul_Graham_(programmer)) is that of creating a function that takes a single (numeric) argument and which returns another function that is an accumulator. The returned accumulator function in turn also takes a single numeric argument, and returns the sum of all the numeric values passed in so far to that accumulator (including the initial value passed when the accumulator was created).
|
||||
[ポール・グレアム](https://en.wikipedia.org/wiki/Paul_Graham_(programmer)) は、1 つの数値引数を取り、アキュムレータである別の関数を返す関数を作成する問題を考え出しました。 返されたアキュムレータ関数は、1つの数値引数を取り、これまでにアキュムレータに渡されたすべての数値の合計 (アキュムレータが作成されたときに渡された初期値を含む) を返します。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Create a function that takes a number $n$ and generates accumulator functions that return the sum of every number ever passed to them.
|
||||
数 $n$ を取って、渡されたすべての数値の合計を返すアキュムレータ関数を生成する関数を作成します。
|
||||
|
||||
**Rules:**
|
||||
**ルール:**
|
||||
|
||||
Do not use global variables.
|
||||
グローバル変数を使用しないでください。
|
||||
|
||||
**Hint:**
|
||||
**ヒント:**
|
||||
|
||||
Closures save outer state.
|
||||
クロージャは外的な状態を保存します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`accumulator` should be a function.
|
||||
`accumulator` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof accumulator === 'function');
|
||||
```
|
||||
|
||||
`accumulator(0)` should return a function.
|
||||
`accumulator(0)` は関数を返します。
|
||||
|
||||
```js
|
||||
assert(typeof accumulator(0) === 'function');
|
||||
```
|
||||
|
||||
`accumulator(0)(2)` should return a number.
|
||||
`accumulator(0)(2)` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof accumulator(0)(2) === 'number');
|
||||
```
|
||||
|
||||
Passing in the values 3, -4, 1.5, and 5 should return 5.5.
|
||||
3、-4、1.5、5の値が渡されると、5.5を返します。
|
||||
|
||||
```js
|
||||
assert(testFn(5) === 5.5);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339acf
|
||||
title: Ackermann function
|
||||
title: アッカーマン関数
|
||||
challengeType: 5
|
||||
forumTopicId: 302223
|
||||
dashedName: ackermann-function
|
||||
@ -8,45 +8,45 @@ dashedName: ackermann-function
|
||||
|
||||
# --description--
|
||||
|
||||
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.
|
||||
アッカーマン関数は、再帰関数の典型的な例です。原始再帰関数ではないため、特に注目に値します。 コールツリーの大きさと同様に、値が爆発的に増加します。
|
||||
|
||||
The Ackermann function is usually defined as follows:
|
||||
アッカーマン関数は通常、以下のように定義されます。
|
||||
|
||||
$A(m, n) = \\begin{cases} n+1 & \\mbox{if } m = 0 \\\\ A(m-1, 1) & \\mbox{if } m > 0 \\mbox{ and } n = 0 \\\\ A(m-1, A(m, n-1)) & \\mbox{if } m > 0 \\mbox{ and } n > 0. \\end{cases}$
|
||||
|
||||
Its arguments are never negative and it always terminates.
|
||||
引数が負になることはなく、必ず完了します。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function which returns the value of $A(m, n)$. Arbitrary precision is preferred (since the function grows so quickly), but not required.
|
||||
$A(m, n)$ の値を返す関数を書きます。 (関数の数値が爆発的に増加するため)任意精度が好まれますが、必然性はありません。
|
||||
|
||||
# --hints--
|
||||
|
||||
`ack` should be a function.
|
||||
`ack` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof ack === 'function');
|
||||
```
|
||||
|
||||
`ack(0, 0)` should return 1.
|
||||
`ack(0, 0)` は1を返します。
|
||||
|
||||
```js
|
||||
assert(ack(0, 0) === 1);
|
||||
```
|
||||
|
||||
`ack(1, 1)` should return 3.
|
||||
`ack(1, 1)` は3を返します。
|
||||
|
||||
```js
|
||||
assert(ack(1, 1) === 3);
|
||||
```
|
||||
|
||||
`ack(2, 5)` should return 13.
|
||||
`ack(2, 5)` は13を返します。
|
||||
|
||||
```js
|
||||
assert(ack(2, 5) === 13);
|
||||
```
|
||||
|
||||
`ack(3, 3)` should return 61.
|
||||
`ack(3, 3)` は61を返します。
|
||||
|
||||
```js
|
||||
assert(ack(3, 3) === 61);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594810f028c0303b75339ad0
|
||||
title: Align columns
|
||||
title: 列を揃える
|
||||
challengeType: 5
|
||||
forumTopicId: 302224
|
||||
dashedName: align-columns
|
||||
@ -8,11 +8,11 @@ dashedName: align-columns
|
||||
|
||||
# --description--
|
||||
|
||||
Given an array of many lines, where fields within a line are delineated by a single `$` character, write a program that aligns each column of fields by ensuring that words in each column are separated by at least one space. Further, allow for each word in a column to be either left justified, right justified, or center justified within its column.
|
||||
たくさんの行を持つ配列で、行内のフィールドが単一の `$` 文字で区切られます。 各列の単語が少なくとも1つのスペースで区切られることで、フィールドの各列を揃えるプログラムを作成します。 さらに、各単語をその列内で左揃え、右揃え、または中央揃えにします。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use the following text to test your programs:
|
||||
次のコードを使用して、プログラムをテストします。
|
||||
|
||||
```js
|
||||
const testText = [
|
||||
@ -29,16 +29,16 @@ const testText = [
|
||||
];
|
||||
```
|
||||
|
||||
**Note that:**
|
||||
**注記:**
|
||||
|
||||
- The example input texts lines may, or may not, have trailing dollar characters.
|
||||
- All columns should share the same alignment.
|
||||
- Consecutive space characters produced adjacent to the end of lines are insignificant for the purposes of the task.
|
||||
- Output text will be viewed in a mono-spaced font on a plain text editor or basic terminal. Lines in it should be joined using new line character (`\n`).
|
||||
- The minimum space between columns should be computed from the text and not hard-coded.
|
||||
- It is not a requirement to add separating characters between or around columns.
|
||||
- 入力コードの例では、ドル文字を末尾に含めることもできますが、そうでない場合もあります。
|
||||
- すべての列を同じように配列する必要があります。
|
||||
- 行末に隣接して生成された連続空白文字は、タスクの目的において重要なものではありません。
|
||||
- 出力テキストは、プレーンテキストエディタまたは基本端末に等幅フォントで表示されます。 その行は、改行文字 (`\n`) を使って結合します。
|
||||
- 列間の最小スペースは、ハードコーディングせずに、テキストから計算します。
|
||||
- 列間または列の周りに区切り文字を追加する必要はありません。
|
||||
|
||||
For example, one of the lines from the `testText`, after jusitifing to the right, left and center respectivelly:
|
||||
次の例は、 `testText`の行を右揃え、左揃え、中央揃えしたものです。
|
||||
|
||||
```js
|
||||
' column are separated by at least one space.\n'
|
||||
@ -48,25 +48,25 @@ For example, one of the lines from the `testText`, after jusitifing to the right
|
||||
|
||||
# --hints--
|
||||
|
||||
`formatText` should be a function.
|
||||
`formatText` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof formatText === 'function');
|
||||
```
|
||||
|
||||
`formatText(testText, 'right')` should produce text with columns justified to the right.
|
||||
`formatText(testText, 'right')` で、列が右揃えされたテキストが生成されます。
|
||||
|
||||
```js
|
||||
assert.strictEqual(formatText(_testText, 'right'), rightAligned);
|
||||
```
|
||||
|
||||
`formatText(testText, 'left')` should produce text with columns justified to the left.
|
||||
`formatText(testText, 'left')` で、列が左揃えされたテキストが生成されます。
|
||||
|
||||
```js
|
||||
assert.strictEqual(formatText(_testText, 'left'), leftAligned);
|
||||
```
|
||||
|
||||
`formatText(testText, 'center')` should produce text with columns justified to the center.
|
||||
`formatText(testText, 'center')` で、列が中央揃えされたテキストが生成されます。
|
||||
|
||||
```js
|
||||
assert.strictEqual(formatText(_testText, 'center'), centerAligned);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5949b579404977fbaefcd737
|
||||
title: Amicable pairs
|
||||
title: 友愛数
|
||||
challengeType: 5
|
||||
forumTopicId: 302225
|
||||
dashedName: amicable-pairs
|
||||
@ -8,42 +8,42 @@ dashedName: amicable-pairs
|
||||
|
||||
# --description--
|
||||
|
||||
Two integers $N$ and $M$ are said to be [amicable pairs](https://en.wikipedia.org/wiki/Amicable numbers "wp: Amicable numbers") if $N \\neq M$ and the sum of the [proper divisors](https://rosettacode.org/wiki/Proper divisors "Proper divisors") of $N$ ($\\mathrm{sum}(\\mathrm{propDivs}(N))$) $= M$ as well as $\\mathrm{sum}(\\mathrm{propDivs}(M)) = N$.
|
||||
2つの整数、$N$と$M$は、 $N \\neq M$であり、[真の約数](https://rosettacode.org/wiki/Proper divisors "Proper divisors") の合計に関して、$N$ ($\\mathrm{sum}(\\mathrm{propDivs}(N))$) $= M$ かつ $\\mathrm{sum}(\\mathrm{propDivs}(M)) = N$である場合に、[友愛数](https://en.wikipedia.org/wiki/Amicable numbers "wp: Amicable numbers")です。
|
||||
|
||||
**Example:**
|
||||
**例:**
|
||||
|
||||
**1184** and **1210** are an amicable pair, with proper divisors:
|
||||
**1184** と **1210** は、真の約数の和から友愛数だと分かります。
|
||||
|
||||
<ul>
|
||||
<li>1, 2, 4, 8, 16, 32, 37, 74, 148, 296, 592 and</li>
|
||||
<li>1, 2, 5, 10, 11, 22, 55, 110, 121, 242, 605 respectively.</li>
|
||||
<li>1、2、4、8、16、32、37、74、148、296、592</li>
|
||||
<li>1、2、5、10、11、22、55、110、121、242、605</li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Calculate and show here the Amicable pairs below 20,000 (there are eight).
|
||||
計算して、20,000 以下の 友愛数を表示します (8 つあります)。
|
||||
|
||||
# --hints--
|
||||
|
||||
`amicablePairsUpTo` should be a function.
|
||||
`amicablePairsUpTo` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof amicablePairsUpTo === 'function');
|
||||
```
|
||||
|
||||
`amicablePairsUpTo(300)` should return `[[220,284]]`.
|
||||
`amicablePairsUpTo(300)` は `[[220,284]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(amicablePairsUpTo(300), answer300);
|
||||
```
|
||||
|
||||
`amicablePairsUpTo(3000)` should return `[[220,284],[1184,1210],[2620,2924]]`.
|
||||
`amicablePairsUpTo(3000)` は `[[220,284],[1184,1210],[2620,2924]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(amicablePairsUpTo(3000), answer3000);
|
||||
```
|
||||
|
||||
`amicablePairsUpTo(20000)` should return `[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]`.
|
||||
`amicablePairsUpTo(20000)` は `[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(amicablePairsUpTo(20000), answer20000);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594d8d0ab97724821379b1e6
|
||||
title: Averages/Mode
|
||||
title: 平均/最頻値
|
||||
challengeType: 5
|
||||
forumTopicId: 302226
|
||||
dashedName: averagesmode
|
||||
@ -8,27 +8,27 @@ dashedName: averagesmode
|
||||
|
||||
# --description--
|
||||
|
||||
Write a program to find the [mode](https://en.wikipedia.org/wiki/Mode (statistics) "wp: Mode (statistics)") value of a collection.
|
||||
データ全体の [最頻値](https://en.wikipedia.org/wiki/Mode (statistics) "wp: Mode (statistics)") を見つけるためのプログラムを作成します。
|
||||
|
||||
The case where the collection is empty may be ignored. Care must be taken to handle the case where the mode is non-unique.
|
||||
データが空の場合は無視します。 最頻値が1つではない場合には注意が必要です。
|
||||
|
||||
If it is not appropriate or possible to support a general collection, use a vector (array), if possible. If it is not appropriate or possible to support an unspecified value type, use integers.
|
||||
一般的なデータの使用が不適切または不可能な場合は、可能であればベクトル(配列)を使用します。 指定されていない値型の使用が不適切または不可能な場合は、整数を使用します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`mode` should be a function.
|
||||
`mode` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof mode === 'function');
|
||||
```
|
||||
|
||||
`mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])` should equal `[6]`
|
||||
`mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])` は `[6]`になります。
|
||||
|
||||
```js
|
||||
assert.deepEqual(mode(arr1), [6]);
|
||||
```
|
||||
|
||||
`mode([1, 2, 4, 4, 1])` should equal `[1, 4]`.
|
||||
`mode([1, 2, 4, 4, 1])` は `[1, 4]`になります。
|
||||
|
||||
```js
|
||||
assert.deepEqual(mode(arr2).sort(), [1, 4]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594d966a1467eb84194f0086
|
||||
title: Averages/Pythagorean means
|
||||
title: 平均/ピタゴラス平均
|
||||
challengeType: 5
|
||||
forumTopicId: 302227
|
||||
dashedName: averagespythagorean-means
|
||||
@ -8,24 +8,24 @@ dashedName: averagespythagorean-means
|
||||
|
||||
# --description--
|
||||
|
||||
Compute all three of the [Pythagorean means](https://en.wikipedia.org/wiki/Pythagorean means "wp: Pythagorean means") of the set of integers $1$ through $10$ (inclusive).
|
||||
$1$ から $10$ を含む整数の集合における全部で3つの [ピタゴラス平均](https://en.wikipedia.org/wiki/Pythagorean means "wp: Pythagorean means") を計算します。
|
||||
|
||||
Show that $A(x_1,\\ldots,x_n) \\geq G(x_1,\\ldots,x_n) \\geq H(x_1,\\ldots,x_n)$ for this set of positive integers.
|
||||
正の整数の集合において、$A(x_1,\\ldots,x_n) \\geq G(x_1,\\ldots,x_n) \\geq H(x_1,\\ldots,x_n)$ を示します。
|
||||
|
||||
<ul>
|
||||
<li>The most common of the three means, the <a class='rosetta__link--rosetta' href='https://rosettacode.org/wiki/Averages/Arithmetic mean' title='Averages/Arithmetic mean' target='_blank'>arithmetic mean</a>, is the sum of the list divided by its length:<br>
|
||||
<big>$ A(x_1, \ldots, x_n) = \frac{x_1 + \cdots + x_n}{n}$</big></li>
|
||||
<li>The <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Geometric mean' title='wp: Geometric mean' target='_blank'>geometric mean</a> is the $n$th root of the product of the list:<br>
|
||||
<li>3つの平均の最も一般的なものである <a class='rosetta__link--rosetta' href='https://rosettacode.org/wiki/Averages/Arithmetic mean' title='Averages/Arithmetic mean' target='_blank'>算術平均</a>は、リストの総和をその長さで割ったものです。<br>
|
||||
<big>$ A(x_1) \ldots, x_n) = \frac{x_1 + \cdots + x_n}{n}$</big></li>
|
||||
<li><a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Geometric mean' title='wp: Geometric mean' target='_blank'>幾何平均</a> は、リストの総乗の $n$乗根です。<br>
|
||||
<big>$ G(x_1, \ldots, x_n) = \sqrt[n]{x_1 \cdots x_n} $</big></li>
|
||||
<li>The <a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Harmonic mean' title='wp: Harmonic mean' target='_blank'>harmonic mean</a> is $n$ divided by the sum of the reciprocal of each item in the list:<br>
|
||||
<li><a class='rosetta__link--wiki' href='https://en.wikipedia.org/wiki/Harmonic mean' title='wp: Harmonic mean' target='_blank'>調和平均</a> は、リスト内の各項目の逆数合計で割った$n$ です。<br>
|
||||
<big>$ H(x_1, \ldots, x_n) = \frac{n}{\frac{1}{x_1} + \cdots + \frac{1}{x_n}} $</big></li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
When writing your function, assume the input is an ordered array of all inclusive numbers.
|
||||
関数を書くときは、入力がすべての包括的数値の規則配列であると想定します。
|
||||
|
||||
For the answer, please output an object in the following format:
|
||||
答えは、以下の形式でオブジェクトを出力してください。
|
||||
|
||||
```js
|
||||
{
|
||||
@ -40,13 +40,13 @@ For the answer, please output an object in the following format:
|
||||
|
||||
# --hints--
|
||||
|
||||
`pythagoreanMeans` should be a function.
|
||||
`pythagoreanMeans` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof pythagoreanMeans === 'function');
|
||||
```
|
||||
|
||||
`pythagoreanMeans([1, 2, ..., 10])` should equal the same output above.
|
||||
`pythagoreanMeans([1, 2, ..., 10])` は上記の出力と同じになります。
|
||||
|
||||
```js
|
||||
assert.deepEqual(pythagoreanMeans(range1), answer1);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594da033de4190850b893874
|
||||
title: Averages/Root mean square
|
||||
title: 平均/二乗平均平方根
|
||||
challengeType: 5
|
||||
forumTopicId: 302228
|
||||
dashedName: averagesroot-mean-square
|
||||
@ -8,23 +8,23 @@ dashedName: averagesroot-mean-square
|
||||
|
||||
# --description--
|
||||
|
||||
Compute the [Root mean square](https://en.wikipedia.org/wiki/Root mean square "wp: Root mean square") of the numbers 1 through 10 inclusive.
|
||||
1から10までの数字の [二乗平均平方根](https://en.wikipedia.org/wiki/Root mean square "wp: Root mean square") を計算します。
|
||||
|
||||
The *root mean square* is also known by its initials RMS (or rms), and as the **quadratic mean**.
|
||||
*二乗平均平方根* は、頭文字のRMS(またはrms) や **平方平均** としても知られています。
|
||||
|
||||
The RMS is calculated as the mean of the squares of the numbers, square-rooted:
|
||||
RMSは、二乗値の平均の平方根として計算されます。
|
||||
|
||||
$$x\_{\\mathrm{rms}} = \\sqrt {{{x_1}^2 + {x_2}^2 + \\cdots + {x_n}^2} \\over n}. $$
|
||||
|
||||
# --hints--
|
||||
|
||||
`rms` should be a function.
|
||||
`rms` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof rms === 'function');
|
||||
```
|
||||
|
||||
`rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])` should equal `6.2048368229954285`.
|
||||
`rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])` は `6.2048368229954285` と等しくなります。
|
||||
|
||||
```js
|
||||
assert.equal(rms(arr1), answer1);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594db4d0dedb4c06a2a4cefd
|
||||
title: Babbage problem
|
||||
title: バベッジの問題
|
||||
challengeType: 5
|
||||
forumTopicId: 302229
|
||||
dashedName: babbage-problem
|
||||
@ -8,30 +8,30 @@ dashedName: babbage-problem
|
||||
|
||||
# --description--
|
||||
|
||||
[Charles Babbage](https://en.wikipedia.org/wiki/Charles_Babbage "wp: Charles_Babbage"), looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example:
|
||||
[チャールズ・バベッジ](https://en.wikipedia.org/wiki/Charles_Babbage "wp: Charles_Babbage")は、解析機関が解決できる問題の種類に目を向け、次の例を挙げました。
|
||||
|
||||
<blockquote>
|
||||
What is the smallest positive integer whose square ends in the digits 269,696?
|
||||
2乗の末尾が269,696になる最小の正の整数は何ですか?
|
||||
<footer style='margin-left: 2em;'>Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, <i>Electronic Computers</i>, second edition, 1970, p. 125.</footer>
|
||||
</blockquote>
|
||||
|
||||
He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.
|
||||
答えは99,736で、その2乗は9,947,269,696であると考えましたが、確信はありませんでした。
|
||||
|
||||
The task is to find out if Babbage had the right answer.
|
||||
バベッジの答えが正しかったかどうかを調べましょう。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function to return the lowest integer that satisfies the Babbage problem. If Babbage was right, return Babbage's number.
|
||||
バベッジの問題の答えとなる最小の整数を返す関数を作成します。 バベッジが正しかった場合は、バベッジが答えた数値を返します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`babbage` should be a function.
|
||||
`babbage` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof babbage === 'function');
|
||||
```
|
||||
|
||||
`babbage(99736, 269696)` should not return 99736 (there is a smaller answer).
|
||||
`babbage(99736, 269696)` は 99736 を返さないはずです(もっと小さな答えがあります)。
|
||||
|
||||
```js
|
||||
assert.equal(babbage(babbageAns, endDigits), answer);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 594dc6c729e5700999302b45
|
||||
title: Balanced brackets
|
||||
title: 対の括弧
|
||||
challengeType: 5
|
||||
forumTopicId: 302230
|
||||
dashedName: balanced-brackets
|
||||
@ -8,129 +8,129 @@ dashedName: balanced-brackets
|
||||
|
||||
# --description--
|
||||
|
||||
Determine whether a generated string of brackets is balanced; that is, whether it consists entirely of pairs of opening/closing brackets (in that order), none of which mis-nest.
|
||||
生成された括弧が対になっているかどうかを確認します。括弧が開き括弧と閉じ括弧の順番で対になっているかどうか、誤った入れ子になっていないかどうかを確認します。
|
||||
|
||||
**Examples:**
|
||||
| Input | Output |
|
||||
| ------------------------- | ------ |
|
||||
| <code>\[]</code> | true |
|
||||
| <code>]\[</code> | false |
|
||||
| <code>[][]</code> | true |
|
||||
| <code>]\[]</code> | false |
|
||||
| <code>\[]]\[\[]</code> | false |
|
||||
| <code>\[\[\[\[]]]]</code> | true |
|
||||
**例:**
|
||||
| 入力 | 出力 |
|
||||
| ------------------------- | -- |
|
||||
| <code>\[]</code> | 真 |
|
||||
| <code>]\[</code> | 偽 |
|
||||
| <code>[][]</code> | 真 |
|
||||
| <code>]\[]</code> | 偽 |
|
||||
| <code>\[]]\[\[]</code> | 偽 |
|
||||
| <code>\[\[\[\[]]]]</code> | 真 |
|
||||
|
||||
# --hints--
|
||||
|
||||
`isBalanced` should be a function.
|
||||
`isBalanced` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof isBalanced === 'function');
|
||||
```
|
||||
|
||||
`isBalanced("[]")` should return true.
|
||||
`isBalanced("[]")` は真を返します。
|
||||
|
||||
```js
|
||||
assert(isBalanced(testCases[0]));
|
||||
```
|
||||
|
||||
`isBalanced("]][[[][][][]][")` should return false.
|
||||
`isBalanced("]][[[][][][]][")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[1]));
|
||||
```
|
||||
|
||||
`isBalanced("[][[[[][][[[]]]]]]")` should return true.
|
||||
`isBalanced("[][[[[][][[[]]]]]]")` は真を返します。
|
||||
|
||||
```js
|
||||
assert(isBalanced(testCases[2]));
|
||||
```
|
||||
|
||||
`isBalanced("][")` should return false.
|
||||
`isBalanced("][")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[3]));
|
||||
```
|
||||
|
||||
`isBalanced("[[[]]]][[]")` should return false.
|
||||
`isBalanced("[[[]]]][[]")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[4]));
|
||||
```
|
||||
|
||||
`isBalanced("][[]")` should return false.
|
||||
`isBalanced("][[]")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[5]));
|
||||
```
|
||||
|
||||
`isBalanced("][[][]][[[]]")` should return false.
|
||||
`isBalanced("][[][]][[[]]")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[6]));
|
||||
```
|
||||
|
||||
`isBalanced("[[][]]][")` should return false.
|
||||
`isBalanced("[[][]]][")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[7]));
|
||||
```
|
||||
|
||||
`isBalanced("[[[]]][[]]]][][[")` should return false.
|
||||
`isBalanced("[[[]]][[]]]][][[")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[8]));
|
||||
```
|
||||
|
||||
`isBalanced("[]][[]]][[[[][]]")` should return false.
|
||||
`isBalanced("[]][[]]][[[[][]]")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[9]));
|
||||
```
|
||||
|
||||
`isBalanced("][]][[][")` should return false.
|
||||
`isBalanced("][]][[][")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[10]));
|
||||
```
|
||||
|
||||
`isBalanced("[[]][[][]]")` should return true.
|
||||
`isBalanced("[[]][[][]]")` は真を返します。
|
||||
|
||||
```js
|
||||
assert(isBalanced(testCases[11]));
|
||||
```
|
||||
|
||||
`isBalanced("[[]]")` should return true.
|
||||
`isBalanced("[[]]")` は真を返します。
|
||||
|
||||
```js
|
||||
assert(isBalanced(testCases[12]));
|
||||
```
|
||||
|
||||
`isBalanced("]][]][[]][[[")` should return false.
|
||||
`isBalanced("]][]][[]][[[")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[13]));
|
||||
```
|
||||
|
||||
`isBalanced("][]][][[")` should return false.
|
||||
`isBalanced("][]][][[")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[14]));
|
||||
```
|
||||
|
||||
`isBalanced("][][")` should return false.
|
||||
`isBalanced("][][")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[15]));
|
||||
```
|
||||
|
||||
`isBalanced("[]]]")` should return false.
|
||||
`isBalanced("[]]]")` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!isBalanced(testCases[16]));
|
||||
```
|
||||
|
||||
`isBalanced("")` should return true.
|
||||
`isBalanced("")` は真を返します。
|
||||
|
||||
```js
|
||||
assert(isBalanced(testCases[17]));
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5951815dd895584b06884620
|
||||
title: Circles of given radius through two points
|
||||
title: 2点を通る指定半径の円
|
||||
challengeType: 5
|
||||
forumTopicId: 302231
|
||||
dashedName: circles-of-given-radius-through-two-points
|
||||
@ -8,30 +8,30 @@ dashedName: circles-of-given-radius-through-two-points
|
||||
|
||||
# --description--
|
||||
|
||||
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
|
||||
平面上の2点と半径が指定されると、指定半径の円が2点を通って2つ描かれます。
|
||||
|
||||
**Exceptions:**
|
||||
**例外:**
|
||||
|
||||
<ul>
|
||||
<li>A radius of zero should be treated as never describing circles (except in the case where the points are coincident).</li>
|
||||
<li>If the points are coincident then an infinite number of circles with the point on their circumference can be drawn, unless the radius is equal to zero as well which then collapses the circles to a point.</li>
|
||||
<li>If the points form a diameter then return a single circle.</li>
|
||||
<li>If the points are too far apart then no circles can be drawn.</li>
|
||||
<li>半径が0である場合は、2点が完全に一致する場合を除き、円は描かれません。</li>
|
||||
<li>2点が完全に一致している場合、円周上にその点が存在する円を無数描くことができます。 ただし、半径もゼロである場合、円が点となります。</li>
|
||||
<li>2点が直径を形成する場合は、1つの円を返します。</li>
|
||||
<li>2点があまりにも離れている場合、円を描くことができません。</li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function that takes two points and a radius and returns the two circles through those points. For each resulting circle, provide the coordinates for the center of each circle rounded to four decimal digits. Return each coordinate as an array, and coordinates as an array of arrays.
|
||||
2点と半径を受け取り、2点を通る二つの円を返す関数を作成します。 得られる各円の中心座標を小数点第4位に丸めます。 各座標を配列として、座標を配列の配列として返します。
|
||||
|
||||
**For edge cases, return the following:**
|
||||
**エッジケースの場合、以下を返します。**
|
||||
|
||||
<ul>
|
||||
<li>If points are on the diameter, return one point. If the radius is also zero however, return <code>"Radius Zero"</code>.</li>
|
||||
<li>If points are coincident, return <code>"Coincident point. Infinite solutions"</code>.</li>
|
||||
<li>If points are farther apart than the diameter, return <code>"No intersection. Points further apart than circle diameter"</code>.</li>
|
||||
<li>2点が直径上にある場合は、1 点を返します。 ただし、半径もゼロの場合は、<code>"Radius Zero"</code> を返します。</li>
|
||||
<li>2点が完全に一致する場合は、 <code>"Coincident point. Infinite solutions" </code> を返します。</li>
|
||||
<li>2点が直径よりも離れている場合は、<code>"No intersection. Points further apart than circle diameter" </code>を返します。</li>
|
||||
</ul>
|
||||
|
||||
**Sample inputs:**
|
||||
**入力例**
|
||||
|
||||
<pre> p1 p2 r
|
||||
0.1234, 0.9876 0.8765, 0.2345 2.0
|
||||
@ -43,37 +43,37 @@ Implement a function that takes two points and a radius and returns the two circ
|
||||
|
||||
# --hints--
|
||||
|
||||
`getCircles` should be a function.
|
||||
`getCircles` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof getCircles === 'function');
|
||||
```
|
||||
|
||||
`getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)` should return `[[1.8631, 1.9742], [-0.8632, -0.7521]]`.
|
||||
`getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)` は `[[1.8631, 1.9742], [-0.8632, -0.7521]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getCircles(...testCases[0]), answers[0]);
|
||||
```
|
||||
|
||||
`getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)` should return `[0, 1]`
|
||||
`getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)` は `[0, 1]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getCircles(...testCases[1]), answers[1]);
|
||||
```
|
||||
|
||||
`getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)` should return `Coincident point. Infinite solutions`
|
||||
`getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)` は `Coincident point. Infinite solutions `を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getCircles(...testCases[2]), answers[2]);
|
||||
```
|
||||
|
||||
`getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)` should return `No intersection. Points further apart than circle diameter`
|
||||
`getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)` は、`No intersection. Points further apart than circle diameter ` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getCircles(...testCases[3]), answers[3]);
|
||||
```
|
||||
|
||||
`getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)` should return `Radius Zero`
|
||||
`getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)` は`Radius Zero` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getCircles(...testCases[4]), answers[4]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5951a53863c8a34f02bf1bdc
|
||||
title: Closest-pair problem
|
||||
title: 最近点対の問題
|
||||
challengeType: 5
|
||||
forumTopicId: 302232
|
||||
dashedName: closest-pair-problem
|
||||
@ -8,9 +8,9 @@ dashedName: closest-pair-problem
|
||||
|
||||
# --description--
|
||||
|
||||
Provide a function to find the closest two points among a set of given points in two dimensions.
|
||||
2次元の任意の点の集合の中から最も近い2点を見つける関数を提供します。
|
||||
|
||||
The straightforward solution is a $O(n^2)$ algorithm (which we can call *brute-force algorithm*); the pseudo-code (using indexes) could be simply:
|
||||
簡単な解決策は、(*brute-force algorithm*と呼ばれる)$O(n^2)$ アルゴリズムを使用することです。疑似コード(インデックス使用)は単純に以下のようになります。
|
||||
|
||||
<pre><strong>bruteForceClosestPair</strong> of P(1), P(2), ... P(N)
|
||||
<strong>if</strong> N < 2 <strong>then</strong>
|
||||
@ -30,7 +30,7 @@ The straightforward solution is a $O(n^2)$ algorithm (which we can call *brute-f
|
||||
<strong>endif</strong>
|
||||
</pre>
|
||||
|
||||
A better algorithm is based on the recursive divide and conquer approach, which is $O(n\log n)$ a pseudo-code could be:
|
||||
より好ましいアルゴリズムは、$O(n\log n)$の再帰的な分割統治法に基づいており、疑似コードは以下のようになります。
|
||||
|
||||
<pre><strong>closestPair</strong> of (xP, yP)
|
||||
where xP is P(1) .. P(N) sorted by x coordinate, and
|
||||
@ -65,9 +65,9 @@ A better algorithm is based on the recursive divide and conquer approach, which
|
||||
<strong>endif</strong>
|
||||
</pre>
|
||||
|
||||
For the input, expect the argument to be an array of `Point` objects with `x` and `y` members set to numbers. Return an object containing the key:value pairs for `distance` and `pair` (the pair of two closest points).
|
||||
入力には、引数を `x` と `y` メンバーが数字に設定されている `Point` オブジェクトの配列であると想定します。 `distance` と `pair` の key:value ペア (最も近い2点のペア) を含むオブジェクトを返します。
|
||||
|
||||
For example `getClosestPair` with input array `points`:
|
||||
例えば、入力配列 `points` を持つ `getClosestPair` の場合
|
||||
|
||||
```js
|
||||
const points = [
|
||||
@ -77,7 +77,7 @@ const points = [
|
||||
];
|
||||
```
|
||||
|
||||
Would return:
|
||||
次のものを返します。
|
||||
|
||||
```js
|
||||
{
|
||||
@ -95,24 +95,24 @@ Would return:
|
||||
}
|
||||
```
|
||||
|
||||
**Note:** Sort the `pair` array by their `x` values in incrementing order.
|
||||
**注記: ** `pair` 配列を `x` の値で昇順に並べ替えます。
|
||||
|
||||
|
||||
# --hints--
|
||||
|
||||
`getClosestPair` should be a function.
|
||||
`getClosestPair` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof getClosestPair === 'function');
|
||||
```
|
||||
|
||||
`getClosestPair(points1).distance` should be `0.0894096443343775`.
|
||||
`getClosestPair(points1).distance` は `0.0894096443343775` になります。
|
||||
|
||||
```js
|
||||
assert.equal(getClosestPair(points1).distance, answer1.distance);
|
||||
```
|
||||
|
||||
`getClosestPair(points1).pair` should be `[ { x: 7.46489, y: 4.6268 }, { x: 7.46911, y: 4.71611 } ]`.
|
||||
`getClosestPair(points1).pair` は `[ { x: 7.46489, y: 4.6268 }, { x: 7.46911, y: 4.71611 } ]` になります。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -121,13 +121,13 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`getClosestPair(points2).distance` should be `65.06919393998976`.
|
||||
`getClosestPair(points2).distance` は `65.06919393998976` になります。
|
||||
|
||||
```js
|
||||
assert.equal(getClosestPair(points2).distance, answer2.distance);
|
||||
```
|
||||
|
||||
`getClosestPair(points2).pair` should be `[ { x: 37134, y: 1963 }, { x: 37181, y: 2008 } ]`.
|
||||
`getClosestPair(points2).pair` は `[ { x: 37134, y: 1963 }, { x: 37181, y: 2008 } ]` になります。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -136,13 +136,13 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`getClosestPair(points3).distance` should be `6754.625082119658`.
|
||||
`getClosestPair(points3).distance` は `6754.625082119658` になります。
|
||||
|
||||
```js
|
||||
assert.equal(getClosestPair(points3).distance, answer3.distance);
|
||||
```
|
||||
|
||||
`getClosestPair(points3).pair` should be `[ { x: 46817, y: 64975 }, { x: 48953, y: 58567 } ]`.
|
||||
`getClosestPair(points3).pair` は `[ { x: 46817, y: 64975 }, { x: 48953, y: 58567 } ]` になります。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5958469238c0d8d2632f46db
|
||||
title: Combinations
|
||||
title: 組み合わせ
|
||||
challengeType: 5
|
||||
forumTopicId: 302233
|
||||
dashedName: combinations
|
||||
@ -8,11 +8,11 @@ dashedName: combinations
|
||||
|
||||
# --description--
|
||||
|
||||
Given non-negative integers `m` and `n`, generate all size `m` combinations of the integers from `0` (zero) to `n-1` in sorted order (each combination is sorted and the entire table is sorted).
|
||||
負でない整数 `m` と `n` が与えられると、`0` (ゼロ) から `n-1` までの整数におけるすべての `m` の組み合わせをソート順に生成します (各組合せとテーブル全体を並べ替えます)。
|
||||
|
||||
**Example:**
|
||||
**例:**
|
||||
|
||||
`3` comb `5` is:
|
||||
`3` と `5` の組み合わせは以下の通りです。
|
||||
|
||||
<pre>0 1 2
|
||||
0 1 3
|
||||
@ -28,19 +28,19 @@ Given non-negative integers `m` and `n`, generate all size `m` combinations of t
|
||||
|
||||
# --hints--
|
||||
|
||||
`combinations` should be a function.
|
||||
`combinations` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof combinations === 'function');
|
||||
```
|
||||
|
||||
`combinations(3, 5)` should return `[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]`.
|
||||
`combinations(3, 5)` は `[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(combinations(testInput1[0], testInput1[1]), testOutput1);
|
||||
```
|
||||
|
||||
`combinations(4, 6)` should return `[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]`
|
||||
`combinations(4, 6)` は `[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(combinations(testInput2[0], testInput2[1]), testOutput2);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 596e414344c3b2872167f0fe
|
||||
title: Comma quibbling
|
||||
title: コンマキブリング
|
||||
challengeType: 5
|
||||
forumTopicId: 302234
|
||||
dashedName: comma-quibbling
|
||||
@ -8,63 +8,63 @@ dashedName: comma-quibbling
|
||||
|
||||
# --description--
|
||||
|
||||
Comma quibbling is a task originally set by Eric Lippert in his [blog](https://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx).
|
||||
カンマキブリング はもともとエリック・リッパートが彼の [ブログ](https://blogs.msdn.com/b/ericlippert/archive/2009/04/15/comma-quibbling.aspx) で提示したタスクです。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to generate a string output which is the concatenation of input words from a list/sequence where:
|
||||
リスト/シーケンスからの入力単語の連結である文字列を出力する関数を作成します。
|
||||
|
||||
<ol>
|
||||
<li>An input of no words produces the output string of just the two brace characters (<code>"{}"</code>)</li>
|
||||
<li>An input of just one word, e.g. <code>["ABC"]</code>, produces the output string of the word inside the two braces, e.g. <code>"{ABC}"</code></li>
|
||||
<li>An input of two words, e.g. <code>["ABC", "DEF"]</code>, produces the output string of the two words inside the two braces with the words separated by the string <code>" and "</code>, e.g. <code>"{ABC and DEF}"</code></li>
|
||||
<li>An input of three or more words, e.g. <code>["ABC", "DEF", "G", "H"]</code>, produces the output string of all but the last word separated by <code>", "</code> with the last word separated by <code>" and "</code> and all within braces; e.g. <code>"{ABC, DEF, G and H}"</code></li>
|
||||
<li>単語を入力しなかった場合、2つの中括弧文字 (<code>"{}"</code>) だけの出力文字列が生成されます。</li>
|
||||
<li>1単語、例えば <code>["ABC"]</code>、だけを入力した場合、<code>"{ABC}"</code> のように、2つの中括弧の中にその単語が出力文字列として生成されます。</li>
|
||||
<li>2つの単語、例えば <code>["ABC", "DEF"]</code>、を入力した場合、<code>"{ABC and DEF}"</code> のように、文字列 <code>" and "</code> に区切られた2つの単語が、2つの中括弧の中に出力文字列として生成されます。</li>
|
||||
<li>3つ以上の単語、 例えば <code>["ABC", "DEF", "G", "H"]</code> を入力した場合、<code>"{ABC, DEF, G and H}"</code> のように、最後の単語以外のすべての単語は、<code>", "</code> で区切られ、最後の単語は <code>" and "</code> で区切られ、すべての単語が中括弧の中に出力文字列として生成されます。</li>
|
||||
</ol>
|
||||
|
||||
Test your function with the following series of inputs showing your output here on this page:
|
||||
次の一連の入力によりこのページに出力表示して、関数をテストします。
|
||||
|
||||
<ul>
|
||||
<li>[] # (No input words).</li>
|
||||
<li>[] # (入力単語なし)</li>
|
||||
<li>["ABC"]</li>
|
||||
<li>["ABC", "DEF"]</li>
|
||||
<li>["ABC", "DEF", "G", "H"]</li>
|
||||
</ul>
|
||||
|
||||
**Note:** Assume words are non-empty strings of uppercase characters for this task.
|
||||
**注記:** このタスクで、単語は大文字の空でない文字列です。
|
||||
|
||||
# --hints--
|
||||
|
||||
`quibble` should be a function.
|
||||
`quibble` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof quibble === 'function');
|
||||
```
|
||||
|
||||
`quibble(["ABC"])` should return a string.
|
||||
`quibble(["ABC"])` は文字列を返します。
|
||||
|
||||
```js
|
||||
assert(typeof quibble(['ABC']) === 'string');
|
||||
```
|
||||
|
||||
`quibble([])` should return "{}".
|
||||
`quibble([])` は "{}"を返します。
|
||||
|
||||
```js
|
||||
assert.equal(quibble(testCases[0]), results[0]);
|
||||
```
|
||||
|
||||
`quibble(["ABC"])` should return "{ABC}".
|
||||
`quibble(["ABC"])` は "{ABC}"を返します。
|
||||
|
||||
```js
|
||||
assert.equal(quibble(testCases[1]), results[1]);
|
||||
```
|
||||
|
||||
`quibble(["ABC", "DEF"])` should return "{ABC and DEF}".
|
||||
`quibble(["ABC", "DEF"])` は "{ABC and DEF}"を返します。
|
||||
|
||||
```js
|
||||
assert.equal(quibble(testCases[2]), results[2]);
|
||||
```
|
||||
|
||||
`quibble(["ABC", "DEF", "G", "H"])` should return "{ABC,DEF,G and H}".
|
||||
`quibble(["ABC", "DEF", "G", "H"])` は "{ABC,DEF,G and H}"を返します。
|
||||
|
||||
```js
|
||||
assert.equal(quibble(testCases[3]), results[3]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 596e457071c35c882915b3e4
|
||||
title: Compare a list of strings
|
||||
title: 文字列リストの比較
|
||||
challengeType: 5
|
||||
forumTopicId: 302235
|
||||
dashedName: compare-a-list-of-strings
|
||||
@ -8,82 +8,82 @@ dashedName: compare-a-list-of-strings
|
||||
|
||||
# --description--
|
||||
|
||||
Given a [list](https://en.wikipedia.org/wiki/List_(abstract_data_type) "wp: List\_(abstract_data_type)") of arbitrarily many strings, implement a function for each of the following conditions:
|
||||
任意の多くの文字列 [リスト](https://en.wikipedia.org/wiki/List_(abstract_data_type) "wp: List\_(abstract_data_type)") が与えられた場合、以下の各条件で関数を作成します。
|
||||
|
||||
<ul>
|
||||
<li>test if they are all lexically equal</li>
|
||||
<li>test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order)</li>
|
||||
<li>それらがすべて語彙として等しいかどうかをテストします</li>
|
||||
<li>すべての文字列がその後の文字列よりも語彙として短いかどうかをテストします (例えば、リストが厳密な昇順であるかどうか)</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`allEqual` should be a function.
|
||||
`allEqual` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof allEqual === 'function');
|
||||
```
|
||||
|
||||
`azSorted` should be a function.
|
||||
`azSorted` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof azSorted === 'function');
|
||||
```
|
||||
|
||||
`allEqual(["AA", "AA", "AA", "AA"])` should return true.
|
||||
`allEqual(["AA", "AA", "AA", "AA"])` は真を返します。
|
||||
|
||||
```js
|
||||
assert(allEqual(testCases[0]));
|
||||
```
|
||||
|
||||
`azSorted(["AA", "AA", "AA", "AA"])` should return false.
|
||||
`azSorted(["AA", "AA", "AA", "AA"])` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!azSorted(testCases[0]));
|
||||
```
|
||||
|
||||
`allEqual(["AA", "ACB", "BB", "CC"])` should return false.
|
||||
`allEqual(["AA", "ACB", "BB", "CC"])` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!allEqual(testCases[1]));
|
||||
```
|
||||
|
||||
`azSorted(["AA", "ACB", "BB", "CC"])` should return true.
|
||||
`azSorted(["AA", "ACB", "BB", "CC"])` は真を返します。
|
||||
|
||||
```js
|
||||
assert(azSorted(testCases[1]));
|
||||
```
|
||||
|
||||
`allEqual([])` should return true.
|
||||
`allEqual([])` は真を返します。
|
||||
|
||||
```js
|
||||
assert(allEqual(testCases[2]));
|
||||
```
|
||||
|
||||
`azSorted([])` should return true.
|
||||
`azSorted([])` は真を返します。
|
||||
|
||||
```js
|
||||
assert(azSorted(testCases[2]));
|
||||
```
|
||||
|
||||
`allEqual(["AA"])` should return true.
|
||||
`allEqual(["AA"])` は真を返します。
|
||||
|
||||
```js
|
||||
assert(allEqual(testCases[3]));
|
||||
```
|
||||
|
||||
`azSorted(["AA"])` should return true.
|
||||
`azSorted(["AA"])` は真を返します。
|
||||
|
||||
```js
|
||||
assert(azSorted(testCases[3]));
|
||||
```
|
||||
|
||||
`allEqual(["BB", "AA"])` should return false.
|
||||
`allEqual(["BB", "AA"])` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!allEqual(testCases[4]));
|
||||
```
|
||||
|
||||
`azSorted(["BB", "AA"])` should return false.
|
||||
`azSorted(["BB", "AA"])` は偽を返します。
|
||||
|
||||
```js
|
||||
assert(!azSorted(testCases[4]));
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 596fd036dc1ab896c5db98b1
|
||||
title: Convert seconds to compound duration
|
||||
title: 秒を複合表示に変換
|
||||
challengeType: 5
|
||||
forumTopicId: 302236
|
||||
dashedName: convert-seconds-to-compound-duration
|
||||
@ -8,69 +8,69 @@ dashedName: convert-seconds-to-compound-duration
|
||||
|
||||
# --description--
|
||||
|
||||
Implement a function which:
|
||||
以下の関数を作成します。
|
||||
|
||||
<ul>
|
||||
<li>takes a positive integer representing a duration in seconds as input (e.g., <code>100</code>), and</li>
|
||||
<li>returns a string which shows the same duration decomposed into weeks, days, hours, minutes, and seconds as detailed below (e.g., <code>1 min, 40 sec</code>).</li>
|
||||
<li>継続期間を秒単位で表す正の整数を入力します (例えば <code>100</code>)。</li>
|
||||
<li>以下の詳細のように、週、日、時、分、秒に分解された同じ期間を示す文字列を返します (例えば <code>1 min, 40 sec</code>)。</li>
|
||||
</ul>
|
||||
|
||||
Demonstrate that it passes the following three test-cases:
|
||||
次の3つのテストケースで正しく変換されることを示します。
|
||||
|
||||
<div style='font-size:115%; font-weight: bold;'>Test Cases</div>
|
||||
<div style='font-size:115%; font-weight: bold;'>テストケース</div>
|
||||
|
||||
| Input number | Output number |
|
||||
| ------------ | ------------------------- |
|
||||
| 7259 | <code>2 hr, 59 sec</code> |
|
||||
| 86400 | <code>1 d</code> |
|
||||
| 6000000 | <code>9 wk, 6 d, 10 hr, 40 min</code> |
|
||||
| 入力した数字 | 出力された数字 |
|
||||
| ------- | ------------------------- |
|
||||
| 7259 | <code>2 hr, 59 sec</code> |
|
||||
| 86400 | <code>1 d</code> |
|
||||
| 6000000 | <code>9 wk, 6 d, 10 hr, 40 min</code> |
|
||||
|
||||
<div style="font-size:115%; font-weight: bold;">Details</div>
|
||||
<div style="font-size:115%; font-weight: bold;">詳細</div>
|
||||
<ul>
|
||||
<li>
|
||||
The following five units should be used:
|
||||
以下の5つの単位を使用する必要があります。
|
||||
|
||||
| Unit | Suffix used in Output | Conversion |
|
||||
| 単位 | アウトプットで使用される接尾辞 | 換算 |
|
||||
| ------ | --------------------- | --------------------- |
|
||||
| week |!!crwdBlockTags_18_sgaTkcolBdwrc!! | 1 week = 7 days |
|
||||
| day |!!crwdBlockTags_19_sgaTkcolBdwrc!! | 1 day = 24 hours |
|
||||
| hour |!!crwdBlockTags_20_sgaTkcolBdwrc!! | 1 hour = 60 minutes |
|
||||
| minute |!!crwdBlockTags_21_sgaTkcolBdwrc!! | 1 minute = 60 seconds |
|
||||
| 週 |!!crwdBlockTags_18_sgaTkcolBdwrc!! | 1 週間 = 7 日 |
|
||||
| day |!!crwdBlockTags_19_sgaTkcolBdwrc!! | 1 日 = 24 時間 |
|
||||
| hour |!!crwdBlockTags_20_sgaTkcolBdwrc!! | 1 時間 = 60 分 |
|
||||
| minute |!!crwdBlockTags_21_sgaTkcolBdwrc!! | 1 分 = 60 秒 |
|
||||
| second |!!crwdBlockTags_22_sgaTkcolBdwrc!! | --- |
|
||||
|
||||
</li>
|
||||
<li>
|
||||
However, <strong>only</strong> include quantities with non-zero values in the output (e.g., return <code>1 d</code> and not <code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code>).
|
||||
ただし、ゼロではない値 <strong>のみ</strong> が出力されます(例えば <code>0 wk, 1 d, 0 hr, 0 min, 0 sec</code>ではなく、<code>1 d</code>を返します)。
|
||||
</li>
|
||||
<li>
|
||||
Give larger units precedence over smaller ones as much as possible (e.g., return <code>2 min, 10 sec</code> and not <code>1 min, 70 sec</code> or <code>130 sec</code>).
|
||||
可能な限り小さな単位よりも大きな単位を優先します (例えば <code>1 min, 70 sec</code> または <code>130 sec</code> ではなく、<code>2 min, 10 sec</code> を返します)。
|
||||
</li>
|
||||
<li>
|
||||
Mimic the formatting shown in the test-cases (quantities sorted from largest unit to smallest and separated by comma+space; value and unit of each quantity separated by space).
|
||||
テストケースに表示される書式設定(数量が最大単位から最小単位の順でソートされ、カンマ+スペースで区切られ、各数量の値と単位がスペースで区切られる)にします。
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`convertSeconds` should be a function.
|
||||
`convertSeconds` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof convertSeconds === 'function');
|
||||
```
|
||||
|
||||
`convertSeconds(7259)` should return `2 hr, 59 sec`.
|
||||
`convertSeconds(7259)` は `2 hr, 59 sec` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(convertSeconds(testCases[0]), results[0]);
|
||||
```
|
||||
|
||||
`convertSeconds(86400)` should return `1 d`.
|
||||
`convertSeconds(86400)` は `1 d` をを返します。
|
||||
|
||||
```js
|
||||
assert.equal(convertSeconds(testCases[1]), results[1]);
|
||||
```
|
||||
|
||||
`convertSeconds(6000000)` should return `9 wk, 6 d, 10 hr, 40 min`.
|
||||
`convertSeconds(6000000)` は `9 wk, 6 d, 10 hr, 40 min` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(convertSeconds(testCases[2]), results[2]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 596fda99c69f779975a1b67d
|
||||
title: Count occurrences of a substring
|
||||
title: 部分文字列の出現回数を数える
|
||||
challengeType: 5
|
||||
forumTopicId: 302237
|
||||
dashedName: count-occurrences-of-a-substring
|
||||
@ -8,42 +8,42 @@ dashedName: count-occurrences-of-a-substring
|
||||
|
||||
# --description--
|
||||
|
||||
Create a function, or show a built-in function, to count the number of non-overlapping occurrences of a substring inside a string.
|
||||
関数を作成するか、組み込み関数を表示して、文字列内で重複しない部分文字列の発生回数を数えます。
|
||||
|
||||
The function should take two arguments:
|
||||
関数は二つの引数を取ります。
|
||||
|
||||
<ul>
|
||||
<li>the first argument being the string to search, and</li>
|
||||
<li>the second a substring to be searched for.</li>
|
||||
<li>1つ目の引数は検索文字列です。</li>
|
||||
<li>2つ目の引数は検索する部分文字列です。</li>
|
||||
</ul>
|
||||
|
||||
It should return an integer count.
|
||||
整数カウントを返します。
|
||||
|
||||
The matching should yield the highest number of non-overlapping matches.
|
||||
照合は、重複しない最大一致数になります。
|
||||
|
||||
In general, this essentially means matching from left-to-right or right-to-left.
|
||||
通常、これは左から右へ、または右から左への照合を意味します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`countSubstring` should be a function.
|
||||
`countSubstring` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof countSubstring === 'function');
|
||||
```
|
||||
|
||||
`countSubstring("the three truths", "th")` should return `3`.
|
||||
`countSubstring("the three truths", "th")` は `3` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(countSubstring(testCases[0], searchString[0]), results[0]);
|
||||
```
|
||||
|
||||
`countSubstring("ababababab", "abab")` should return `2`.
|
||||
`countSubstring("ababababab", "abab")` は `2` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(countSubstring(testCases[1], searchString[1]), results[1]);
|
||||
```
|
||||
|
||||
`countSubstring("abaabba*bbaba*bbab", "a*b")` should return `2`.
|
||||
`countSubstring("abaabba*bbaba*bbab", "a*b")` は `2` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(countSubstring(testCases[2], searchString[2]), results[2]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59713bd26bdeb8a594fb9413
|
||||
title: Count the coins
|
||||
title: 硬貨を数える
|
||||
challengeType: 5
|
||||
forumTopicId: 302238
|
||||
dashedName: count-the-coins
|
||||
@ -8,51 +8,51 @@ dashedName: count-the-coins
|
||||
|
||||
# --description--
|
||||
|
||||
There are four types of common coins in [US](https://en.wikipedia.org/wiki/United_States) currency:
|
||||
[米国](https://en.wikipedia.org/wiki/United_States) 通貨には4種類の共通硬貨があります。
|
||||
|
||||
<ul>
|
||||
<li>quarters (25 cents)</li>
|
||||
<li>dimes (10 cents)</li>
|
||||
<li>nickels (5 cents), and</li>
|
||||
<li>pennies (1 cent)</li>
|
||||
<li>25セント硬貨</li>
|
||||
<li>10セント硬貨</li>
|
||||
<li>5セント硬貨</li>
|
||||
<li>1セント硬貨</li>
|
||||
</ul>
|
||||
|
||||
<p>There are six ways to make change for 15 cents:</p>
|
||||
<p>15セントを両替するには6つの組み合わせがあります。</p>
|
||||
|
||||
<ul>
|
||||
<li>A dime and a nickel</li>
|
||||
<li>A dime and 5 pennies</li>
|
||||
<li>3 nickels</li>
|
||||
<li>2 nickels and 5 pennies</li>
|
||||
<li>A nickel and 10 pennies</li>
|
||||
<li>15 pennies</li>
|
||||
<li>10セント硬貨1枚と5セント硬貨1枚</li>
|
||||
<li>10セント硬貨1枚と1セント硬貨5枚</li>
|
||||
<li>5セント硬貨3枚</li>
|
||||
<li>5セント硬貨2枚と1セント硬貨5枚</li>
|
||||
<li>5セント硬貨1枚と1セント硬貨10枚</li>
|
||||
<li>1セント硬貨15枚</li>
|
||||
</ul>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a function to determine how many ways there are to make change for a given input, `cents`, that represents an amount of US pennies using these common coins.
|
||||
米国の1セント硬貨である `cents` での入力値を、共通硬貨を使用して両替する場合、いくつの組み合わせがあるかを求める関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`countCoins` should be a function.
|
||||
`countCoins` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof countCoins === 'function');
|
||||
```
|
||||
|
||||
`countCoins(15)` should return `6`.
|
||||
`countCoins(15)` は `6` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(countCoins(15), 6);
|
||||
```
|
||||
|
||||
`countCoins(85)` shouls return `163`.
|
||||
`countCoins(85)` は `163` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(countCoins(85), 163);
|
||||
```
|
||||
|
||||
`countCoins(100)` should return `242`.
|
||||
`countCoins(100)` は `242` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(countCoins(100), 242);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59713da0a428c1a62d7db430
|
||||
title: Cramer's rule
|
||||
title: クラメルの公式
|
||||
challengeType: 5
|
||||
forumTopicId: 302239
|
||||
dashedName: cramers-rule
|
||||
@ -8,43 +8,43 @@ dashedName: cramers-rule
|
||||
|
||||
# --description--
|
||||
|
||||
In [linear algebra](https://en.wikipedia.org/wiki/linear algebra "wp: linear algebra"), [Cramer's rule](https://en.wikipedia.org/wiki/Cramer's rule "wp: Cramer's rule") is an explicit formula for the solution of a [system of linear equations](https://en.wikipedia.org/wiki/system of linear equations "wp: system of linear equations") with as many equations as unknowns, valid whenever the system has a unique solution. It expresses the solution in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one column by the vector of right hand sides of the equations.
|
||||
[線形代数で](https://en.wikipedia.org/wiki/linear algebra "wp: linear algebra")、[クラメルの公式](https://en.wikipedia.org/wiki/Cramer's rule "wp: Cramer's rule") は未知数と同じくらい多くの方程式を含む [線形方程式のシステム](https://en.wikipedia.org/wiki/system of linear equations "wp: system of linear equations") を解くための明示的な公式であり、システムに一意の解があれば常に有効です。 解を、(正方) 係数行列と、列を方程式右辺のベクトルで置き換えて得られる行列の行列式で表します。
|
||||
|
||||
Given
|
||||
次のように仮定します。
|
||||
|
||||
$\\left\\{\\begin{matrix}a_1x + b_1y + c_1z&= {\\color{red}d_1}\\\\a_2x + b_2y + c_2z&= {\\color{red}d_2}\\\\a_3x + b_3y + c_3z&= {\\color{red}d_3}\\end{matrix}\\right.$
|
||||
|
||||
which in matrix format is
|
||||
行列形式で、上記は以下のように表されます。
|
||||
|
||||
$\\begin{bmatrix} a_1 & b_1 & c_1 \\\\ a_2 & b_2 & c_2 \\\\ a_3 & b_3 & c_3 \\end{bmatrix}\\begin{bmatrix} x \\\\ y \\\\ z \\end{bmatrix}=\\begin{bmatrix} {\\color{red}d_1} \\\\ {\\color{red}d_2} \\\\ {\\color{red}d_3} \\end{bmatrix}.$
|
||||
|
||||
Then the values of $x, y$ and $z$ can be found as follows:
|
||||
したがって、$x、y$、および $z$ の値は以下のようになります。
|
||||
|
||||
$x = \\frac{\\begin{vmatrix} {\\color{red}d_1} & b_1 & c_1 \\\\ {\\color{red}d_2} & b_2 & c_2 \\\\ {\\color{red}d_3} & b_3 & c_3 \\end{vmatrix} } { \\begin{vmatrix} a_1 & b_1 & c_1 \\\\ a_2 & b_2 & c_2 \\\\ a_3 & b_3 & c_3 \\end{vmatrix}}, \\quad y = \\frac {\\begin{vmatrix} a_1 & {\\color{red}d_1} & c_1 \\\\ a_2 & {\\color{red}d_2} & c_2 \\\\ a_3 & {\\color{red}d_3} & c_3 \\end{vmatrix}} {\\begin{vmatrix} a_1 & b_1 & c_1 \\\\ a_2 & b_2 & c_2 \\\\ a_3 & b_3 & c_3 \\end{vmatrix}}, \\text{ and }z = \\frac { \\begin{vmatrix} a_1 & b_1 & {\\color{red}d_1} \\\\ a_2 & b_2 & {\\color{red}d_2} \\\\ a_3 & b_3 & {\\color{red}d_3} \\end{vmatrix}} {\\begin{vmatrix} a_1 & b_1 & c_1 \\\\ a_2 & b_2 & c_2 \\\\ a_3 & b_3 & c_3 \\end{vmatrix} }.$
|
||||
|
||||
# --instructions--
|
||||
|
||||
Given the following system of equations:
|
||||
以下の連立方程式が与えられます。
|
||||
|
||||
$\\begin{cases} 2w-x+5y+z=-3 \\\\ 3w+2x+2y-6z=-32 \\\\ w+3x+3y-z=-47 \\\\ 5w-2x-3y+3z=49 \\\\ \\end{cases}$
|
||||
|
||||
solve for $w$, $x$, $y$ and $z$, using Cramer's rule.
|
||||
クラメルの公式を使用すると、解は $w$、$x$、$y$ および $z$となります。
|
||||
|
||||
# --hints--
|
||||
|
||||
`cramersRule` should be a function.
|
||||
`cramersRule` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof cramersRule === 'function');
|
||||
```
|
||||
|
||||
`cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])` should return `[2, -12, -4, 1]`.
|
||||
`cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])` は `[2, -12, -4, 1]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(cramersRule(matrices[0], freeTerms[0]), answers[0]);
|
||||
```
|
||||
|
||||
`cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])` should return `[1, 1, -1]`.
|
||||
`cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])` は `[1, 1, -1]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(cramersRule(matrices[1], freeTerms[1]), answers[1]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7e03
|
||||
title: Cumulative standard deviation
|
||||
title: 累積標準偏差
|
||||
challengeType: 5
|
||||
forumTopicId: 302240
|
||||
dashedName: cumulative-standard-deviation
|
||||
@ -8,41 +8,41 @@ dashedName: cumulative-standard-deviation
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that takes an array of numbers as parameter and returns the [standard deviation](https://en.wikipedia.org/wiki/Standard Deviation) of the series.
|
||||
数値の配列をパラメータとして取り、級数の [標準偏差](https://en.wikipedia.org/wiki/Standard Deviation) を返す関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`standardDeviation` should be a function.
|
||||
`standardDeviation` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof standardDeviation == 'function');
|
||||
```
|
||||
|
||||
`standardDeviation([2, 4, 4, 4, 5, 5, 7, 9])` should return a number.
|
||||
`standardDeviation([2, 4, 4, 4, 5, 5, 7, 9])` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof standardDeviation([2, 4, 4, 4, 5, 5, 7, 9]) == 'number');
|
||||
```
|
||||
|
||||
`standardDeviation([2, 4, 4, 4, 5, 5, 7, 9])` should return `2`.
|
||||
`standardDeviation([2, 4, 4, 4, 5, 5, 7, 9])` は `2` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(standardDeviation([2, 4, 4, 4, 5, 5, 7, 9]), 2);
|
||||
```
|
||||
|
||||
`standardDeviation([600, 470, 170, 430, 300])` should return `147.323`.
|
||||
`standardDeviation([600, 470, 170, 430, 300])` は `147.323` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(standardDeviation([600, 470, 170, 430, 300]), 147.323);
|
||||
```
|
||||
|
||||
`standardDeviation([75, 83, 96, 100, 121, 125])` should return `18.239`.
|
||||
`standardDeviation([75, 83, 96, 100, 121, 125])` は `18.239` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(standardDeviation([75, 83, 96, 100, 121, 125]), 18.239);
|
||||
```
|
||||
|
||||
`standardDeviation([23, 37, 45, 49, 56, 63, 63, 70, 72, 82])` should return `16.87`.
|
||||
`standardDeviation([23, 37, 45, 49, 56, 63, 63, 70, 72, 82])` は `16.87` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
@ -51,7 +51,7 @@ assert.equal(
|
||||
);
|
||||
```
|
||||
|
||||
`standardDeviation([271, 354, 296, 301, 333, 326, 285, 298, 327, 316, 287, 314])` should return `22.631`.
|
||||
`standardDeviation([271, 354, 296, 301, 333, 326, 285, 298, 327, 316, 287, 314])` は `22.631` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -8,69 +8,69 @@ dashedName: cusip
|
||||
|
||||
# --description--
|
||||
|
||||
A **CUSIP** is a nine-character alphanumeric code that identifies a North American financial security for the purposes of facilitating clearing and settlement of trades. The CUSIP was adopted as an American National Standard under Accredited Standards X9.6.
|
||||
**CUSIP** は、取引の清算と決済を容易にする目的で、北米の有価証券を識別する9文字の英数字コードです。 CUSIPは、Accredited Standards X9.6に基づき、米国国家標準協会として採用されました。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a string as a parameter and checks if the string is valid CUSIP.
|
||||
文字列をパラメータとして取り、文字列が有効なCUSIPであるかどうかをチェックする関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`isCusip` should be a function.
|
||||
`isCusip` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof isCusip == 'function');
|
||||
```
|
||||
|
||||
`isCusip("037833100")` should return a boolean.
|
||||
`isCusip("037833100")` はブール値を返します。
|
||||
|
||||
```js
|
||||
assert(typeof isCusip('037833100') == 'boolean');
|
||||
```
|
||||
|
||||
`isCusip("037833100")` should return `true`.
|
||||
`isCusip("037833100")` は `true` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('037833100'), true);
|
||||
```
|
||||
|
||||
`isCusip("17275R102")` should return `true`.
|
||||
`isCusip("17275R102")` は `true` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('17275R102'), true);
|
||||
```
|
||||
|
||||
`isCusip("38259P50a")` should return `false`.
|
||||
`isCusip("38259P50a")` は `false` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('38259P50a'), false);
|
||||
```
|
||||
|
||||
`isCusip("38259P508")` should return `true`.
|
||||
`isCusip("38259P508")` は `true` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('38259P508'), true);
|
||||
```
|
||||
|
||||
`isCusip("38259P50#")` should return `false`.
|
||||
`isCusip("38259P50#")` は `false` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('38259P50#'), false);
|
||||
```
|
||||
|
||||
`isCusip("68389X105")` should return `true`.
|
||||
`isCusip("68389X105")` は `true` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('68389X105'), true);
|
||||
```
|
||||
|
||||
`isCusip("68389X106")` should return `false`.
|
||||
`isCusip("68389X106")` は `false` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('68389X106'), false);
|
||||
```
|
||||
|
||||
`isCusip("5949181")` should return `false`.
|
||||
`isCusip("5949181")` は `false` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(isCusip('5949181'), false);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7e06
|
||||
title: Cut a rectangle
|
||||
title: 長方形を切る
|
||||
challengeType: 5
|
||||
forumTopicId: 302242
|
||||
dashedName: cut-a-rectangle
|
||||
@ -8,7 +8,7 @@ dashedName: cut-a-rectangle
|
||||
|
||||
# --description--
|
||||
|
||||
A given rectangle is made from *m* × *n* squares. If *m* and *n* are not both odd, then it is possible to cut a path through the rectangle along the square edges such that the rectangle splits into two connected pieces with the same shape (after rotating one of the pieces by 180°). All such paths for 2 × 2 and 4 × 3 rectangles are shown below.
|
||||
長方形が *m* × *n* の正方形から作られているとします。 *m* と *n* が両方とも奇数でない場合、(片方を180°回転させて) 長方形が同じ形状のつながった2ピースに分割されるように、正方形の端に沿って長方形を切ることができます。 以下のように、2 × 2 と 4 × 3 の長方形を切ります。
|
||||
|
||||
<div style="width: 100%; text-align: center;">
|
||||
<svg xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" width="520" height="170" aria-hidden="true" alt="Diagram showing the possible paths for 2 by 2 and 4 by 3 rectangles">
|
||||
@ -92,47 +92,47 @@ A given rectangle is made from *m* × *n* squares. If *m* and *n* are not both o
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that calculates the number of different ways to cut an *m* × *n* rectangle.
|
||||
*m* × *n* の長方形の切り方が何通りあるかを計算する関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`cutRectangle` should be a function.
|
||||
`cutRectangle` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof cutRectangle == 'function');
|
||||
```
|
||||
|
||||
`cutRectangle(2, 2)` should return a number.
|
||||
`cutRectangle(2, 2)` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof cutRectangle(2, 2) == 'number');
|
||||
```
|
||||
|
||||
`cutRectangle(2, 2)` should return `2`.
|
||||
`cutRectangle(2, 2)` は `2` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(cutRectangle(2, 2), 2);
|
||||
```
|
||||
|
||||
`cutRectangle(4, 3)` should return `9`.
|
||||
`cutRectangle(4, 3)` は `9` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(cutRectangle(4, 3), 9);
|
||||
```
|
||||
|
||||
`cutRectangle(4, 4)` should return `22`.
|
||||
`cutRectangle(4, 4)` は `22` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(cutRectangle(4, 4), 22);
|
||||
```
|
||||
|
||||
`cutRectangle(8, 3)` should return `53`.
|
||||
`cutRectangle(8, 3)` は `53` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(cutRectangle(8, 3), 53);
|
||||
```
|
||||
|
||||
`cutRectangle(7, 4)` should return `151`.
|
||||
`cutRectangle(7, 4)` は `151` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(cutRectangle(7, 4), 151);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59669d08d75b60482359409f
|
||||
title: Date format
|
||||
title: 日付形式
|
||||
challengeType: 5
|
||||
forumTopicId: 302243
|
||||
dashedName: date-format
|
||||
@ -8,15 +8,15 @@ dashedName: date-format
|
||||
|
||||
# --description--
|
||||
|
||||
Return an array with two date strings of the current date with the following specifications:
|
||||
次の仕様で、現在の日付の日付文字列を2つ持つ配列を返します。
|
||||
|
||||
- The first string's date order should be the year number, month number, and day number separated by dashes (`-`).
|
||||
- The first string's year should be four digits in length.
|
||||
- The first string's month and day should not contain any leading zeros.
|
||||
- The second string's weekday and month names should not be abbreviated.
|
||||
- The second string's day should not contain any leading zeros.
|
||||
- 最初の文字列の日付は、年、月、日の順にダッシュで区切られます(`-`)。
|
||||
- 最初の文字列の年は、4桁です。
|
||||
- 最初の文字列の月と日は、先頭にゼロを含めません。
|
||||
- 2番目の文字列の曜日と月は、省略表記にしません。
|
||||
- 2番目の文字列の日付は、先頭にゼロを含めません。
|
||||
|
||||
Example outputs:
|
||||
出力例:
|
||||
|
||||
```js
|
||||
['2007-11-23', 'Friday, November 23, 2007']
|
||||
@ -25,25 +25,25 @@ Example outputs:
|
||||
|
||||
# --hints--
|
||||
|
||||
`getDateFormats` should be a function.
|
||||
`getDateFormats` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof getDateFormats === 'function');
|
||||
```
|
||||
|
||||
`getDateFormats` should return an object.
|
||||
`getDateFormats` はオブジェクトを返します。
|
||||
|
||||
```js
|
||||
assert(typeof getDateFormats() === 'object');
|
||||
```
|
||||
|
||||
`getDateFormats` should return an array with 2 elements.
|
||||
`getDateFormats` は2つの要素を持つ配列を返します。
|
||||
|
||||
```js
|
||||
assert(getDateFormats().length === 2);
|
||||
```
|
||||
|
||||
`getDateFormats` should return the correct date in the right format
|
||||
`getDateFormats` は正しい形式で正確な日付を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(getDateFormats(), dates, equalsMessage);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5966c21cf732a95f1b67dd28
|
||||
title: Date manipulation
|
||||
title: 日付操作
|
||||
challengeType: 5
|
||||
forumTopicId: 302244
|
||||
dashedName: date-manipulation
|
||||
@ -8,27 +8,27 @@ dashedName: date-manipulation
|
||||
|
||||
# --description--
|
||||
|
||||
Given a date string in EST, output the given date as a string with 12 hours added to the time. Time zone should be preserved.
|
||||
ESTに基づく日付文字列が与えられると、12時間を加えて日付を文字列として出力します。 タイムゾーンは保持します。
|
||||
|
||||
Example input: `"March 6 2009 7:30pm EST"`
|
||||
入力例: `"March 6 2009 7:30pm EST"`
|
||||
|
||||
Example output: `"March 7 2009 7:30am EST"`
|
||||
出力例: `"March 7 2009 7:30am EST"`
|
||||
|
||||
# --hints--
|
||||
|
||||
`add12Hours` should be a function.
|
||||
`add12Hours` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof add12Hours === 'function');
|
||||
```
|
||||
|
||||
`add12Hours(dateString)` should return a string.
|
||||
`add12Hours(dateString)` は文字列を返します。
|
||||
|
||||
```js
|
||||
assert(typeof add12Hours('January 17 2017 11:43am EST') === 'string');
|
||||
```
|
||||
|
||||
`add12Hours("January 17 2017 11:43am EST")` should return `"January 17 2017 11:43pm EST"`
|
||||
`add12Hours("January 17 2017 11:43am EST")` は `"January 17 2017 11:43pm EST"` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -36,25 +36,25 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
Should handle day change. `add12Hours("March 6 2009 7:30pm EST")` should return `"March 7 2009 7:30am EST"`
|
||||
日付が変更されます。 `add12Hours("March 6 2009 7:30pm EST")` は `"March 7 2009 7:30am EST"` を返します。
|
||||
|
||||
```js
|
||||
assert(add12Hours('March 6 2009 7:30pm EST') === 'March 7 2009 7:30am EST');
|
||||
```
|
||||
|
||||
Should handle month change in a leap years. `add12Hours("February 29 2004 9:15pm EST")` should return `"March 1 2004 9:15am EST"`
|
||||
うるう年の月に変更が加えられます。 `add12Hours("February 29 2004 9:15pm EST")` は `"March 1 2004 9:15am EST"` を返します。
|
||||
|
||||
```js
|
||||
assert(add12Hours('February 29 2004 9:15pm EST') === 'March 1 2004 9:15am EST');
|
||||
```
|
||||
|
||||
Should handle month change in a common years. `add12Hours("February 28 1999 3:15pm EST")` should return `"March 1 1999 3:15am EST"`
|
||||
平年の月に変更が加えられます。 `add12Hours("February 28 1999 3:15pm EST")` は `"March 1 1999 3:15am EST"` を返します。
|
||||
|
||||
```js
|
||||
assert(add12Hours('February 28 1999 3:15pm EST') === 'March 1 1999 3:15am EST');
|
||||
```
|
||||
|
||||
Should handle year change. `add12Hours("December 31 2020 1:45pm EST")` should return `"January 1 2021 1:45am EST"`
|
||||
年に変更が加えられます。 `add12Hours("December 31 2020 1:45pm EST")` は `"January 1 2021 1:45am EST"` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5966f99c45e8976909a85575
|
||||
title: Day of the week
|
||||
title: 曜日
|
||||
challengeType: 5
|
||||
forumTopicId: 302245
|
||||
dashedName: day-of-the-week
|
||||
@ -8,33 +8,33 @@ dashedName: day-of-the-week
|
||||
|
||||
# --description--
|
||||
|
||||
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).
|
||||
ある会社は、クリスマスが日曜日と重なる場合、従業員に追加の有給休暇を与えることにしました。それにより、従業員は祝日と合わせて次の週 (12月25日から1月1日まで) 働く必要がなくなります。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that takes a start year and an end year and return an array of all the years where the 25th of December will be a Sunday.
|
||||
開始年と終了年が入力されると、12月25日が日曜日と重なる年の配列を返す関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`findXmasSunday` should be a function.
|
||||
`findXmasSunday` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof findXmasSunday === 'function');
|
||||
```
|
||||
|
||||
`findXmasSunday(2000, 2100)` should return an array.
|
||||
`findXmasSunday(2000, 2100)` は配列を返します。
|
||||
|
||||
```js
|
||||
assert(typeof findXmasSunday(2000, 2100) === 'object');
|
||||
```
|
||||
|
||||
`findXmasSunday(1970, 2017)` should return `[1977, 1983, 1988, 1994, 2005, 2011, 2016]`
|
||||
`findXmasSunday(1970, 2017)` は `[1977, 1983, 1988, 1994, 2005, 2011, 2016]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(findXmasSunday(1970, 2017), firstSolution);
|
||||
```
|
||||
|
||||
`findXmasSunday(2008, 2121)` should return `[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]`
|
||||
`findXmasSunday(2008, 2121)` は `[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(findXmasSunday(2008, 2121), secondSolution);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59694356a6e7011f7f1c5f4e
|
||||
title: Deal cards for FreeCell
|
||||
title: フリーセルのカードを配る
|
||||
challengeType: 5
|
||||
forumTopicId: 302246
|
||||
dashedName: deal-cards-for-freecell
|
||||
@ -8,36 +8,36 @@ dashedName: deal-cards-for-freecell
|
||||
|
||||
# --description--
|
||||
|
||||
*FreeCell* is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for [DOS](https://rosettacode.org/wiki/DOS "DOS"), then [Windows](https://rosettacode.org/wiki/Windows "Windows"). This version introduced 32000 numbered deals.
|
||||
*フリーセル* は、ポール・アルフィレ (Paul Alfille) が1978年にPLATOシステムに導入したソリティアというカードゲームです。 Microsoftのジム・ホーン (Jim Horne) は、ゲーム名をフリーセルに変更し、[DOS](https://rosettacode.org/wiki/DOS "DOS")向け、そして[Windows](https://rosettacode.org/wiki/Windows "Windows")向けに、ゲームを再実装しました。 このバージョンでは、32000のゲーム番号が導入されました。
|
||||
|
||||
As the game became popular, Jim Horne disclosed the algorithm, and other implementations of FreeCell began to reproduce the Microsoft deals. These deals are numbered from 1 to 32000. Newer versions from Microsoft have 1 million deals, numbered from 1 to 1000000; some implementations allow numbers outside that range.
|
||||
ゲームが普及し、ジム・ホーンがアルゴリズムを開示したため、他のフリーセル実装でもMicrosoftと同様のアルゴリズムでカードが配られるようになりました。 カードの配り方には1から32000まで番号が付けられています。 Microsoftの新しいバージョンでは、1から1000000までの番号が付けられた100万のゲーム番号があります。一部の実装では、この範囲外の番号も使用されています。
|
||||
|
||||
The algorithm uses this [linear congruential generator](https://rosettacode.org/wiki/linear congruential generator "linear congruential generator") from Microsoft C:
|
||||
Microsoft Cにおける [線形合同法](https://rosettacode.org/wiki/linear congruential generator "linear congruential generator") をアルゴリズムに使用しています。
|
||||
|
||||
<ul>
|
||||
<li>$state_{n + 1} \equiv 214013 \times state_n + 2531011 \pmod{2^{31}}$</li>
|
||||
<li>$rand_n = state_n \div 2^{16}$</li>
|
||||
<li>$rand_n$ is in range 0 to 32767.</li>
|
||||
<li>$rand_n$ は 0から32767の範囲です。</li>
|
||||
</ul>
|
||||
|
||||
The algorithm follows:
|
||||
アルゴリズムは以下のとおりです。
|
||||
|
||||
<ol>
|
||||
<li>Seed the RNG with the number of the deal.
|
||||
</li><li>Create an <a href='https://rosettacode.org/wiki/array' title='array' target='_blank'>array</a> of 52 cards: Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs, 2 of Diamonds, and so on through the ranks: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King. The array indexes are 0 to 51, with Ace of Clubs at 0, and King of Spades at 51.</li>
|
||||
<li>Until the array is empty:</li>
|
||||
<li>Choose a random card at index ≡ next random number (mod array length).</li>
|
||||
<li>RNGにゲーム番号を与えます。
|
||||
</li><li>52枚のカードの <a href='https://rosettacode.org/wiki/array' title='array' target='_blank'>配列</a> を作成します。クラブのエース、ダイヤモンドのエース、ハートのエース、スペードのエース、クラブの2、ダイヤモンドの2、と続きます。エース、2、3、4、5、6、7、8、9、10、ジャック、クイーン、キングの順番です。 配列インデックスは0から51で、クラブのエースは0、スペードのキングは51です。</li>
|
||||
<li>配列が空になるまでです。</li>
|
||||
<li>インデックスでランダムなカードを選択します≡ 次の乱数(Mod配列の長さ)。</li>
|
||||
<ul>
|
||||
<li>Swap this random card with the last card of the array.</li>
|
||||
<li>Remove this random card from the array. (Array length goes down by 1.)</li>
|
||||
<li>Deal this random card.</li>
|
||||
<li>このランダムなカードを配列の最後のカードと交換します。</li>
|
||||
<li>このランダムなカードを配列から削除します (配列の数が1つ減る)。</li>
|
||||
<li>このランダムなカードを配ります。</li>
|
||||
</ul>
|
||||
<li>Deal all 52 cards, face up, across 8 columns. The first 8 cards go in 8 columns, the next 8 cards go on the first 8 cards, and so on.</li>
|
||||
<li>52枚すべてのカードを、表を上にして8列に配ります。 最初の8枚のカードが8列に配られ、その上に次の8枚のカードが配られ、と続いていきます。</li>
|
||||
</ol>
|
||||
|
||||
**Example:**
|
||||
**例:**
|
||||
|
||||
**Order to deal cards**
|
||||
**カードを配る順番**
|
||||
|
||||
<pre> 1 2 3 4 5 6 7 8
|
||||
9 10 11 12 13 14 15 16
|
||||
@ -47,7 +47,7 @@ The algorithm follows:
|
||||
41 42 43 44 45 46 47 48
|
||||
49 50 51 52</pre>
|
||||
|
||||
**Game #1**
|
||||
**ゲーム#1**
|
||||
|
||||
```js
|
||||
[
|
||||
@ -61,7 +61,7 @@ The algorithm follows:
|
||||
]
|
||||
```
|
||||
|
||||
**Game #617**
|
||||
**ゲーム#617**
|
||||
|
||||
```js
|
||||
[
|
||||
@ -77,37 +77,37 @@ The algorithm follows:
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to take a deal number and deal cards in the same order as this algorithm. The function must return a two dimensional array representing the FreeCell board.
|
||||
ゲーム番号を受け取り、このアルゴリズムと同じ順序でカードを配る関数を作成します。 この関数はフリーセルボードを表す2次元配列を返します。
|
||||
|
||||
Deals can also be checked against [FreeCell solutions to 1000000 games](https://freecellgamesolutions.com/). (Summon a video solution, and it displays the initial deal.)
|
||||
ゲーム番号は、[1000000ゲームのフリーセルソリューション](https://freecellgamesolutions.com/) に照らし合わせて確認することもできます (ビデオソリューションを呼び出し、最初のゲーム番号を表示する)。
|
||||
|
||||
# --hints--
|
||||
|
||||
`dealFreeCell` should be a function.
|
||||
`dealFreeCell` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof dealFreeCell === 'function');
|
||||
```
|
||||
|
||||
`dealFreeCell(seed)` should return an object.
|
||||
`dealFreeCell(seed)` はオブジェクトを返します。
|
||||
|
||||
```js
|
||||
assert(typeof dealFreeCell(1) === 'object');
|
||||
```
|
||||
|
||||
`dealFreeCell(seed)` should return an array of length 7.
|
||||
`dealFreeCell(seed)` は長さ7の配列を返します。
|
||||
|
||||
```js
|
||||
assert(dealFreeCell(1).length === 7);
|
||||
```
|
||||
|
||||
`dealFreeCell(1)` should return an array identical to example "Game #1"
|
||||
`dealFreeCell(1)` は例「Game #1」と同一の配列を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(dealFreeCell(1), game1);
|
||||
```
|
||||
|
||||
`dealFreeCell(617)` should return an array identical to example "Game #617"
|
||||
`dealFreeCell(617)` は「Game #617」と同一の配列を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(dealFreeCell(617), game617);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 596a8888ab7c01048de257d5
|
||||
title: Deepcopy
|
||||
title: ディープコピー
|
||||
challengeType: 5
|
||||
forumTopicId: 302247
|
||||
dashedName: deepcopy
|
||||
@ -8,44 +8,44 @@ dashedName: deepcopy
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that returns a deep copy of a given object. The copy must not be the same object that was given.
|
||||
与えられたオブジェクトのディープコピーを返す関数を作成します。 コピーは与えられたオブジェクトと同じであってはなりません。
|
||||
|
||||
This task will not test for:
|
||||
このタスクは次のものをテストするものではありません。
|
||||
|
||||
<ul>
|
||||
<li>Objects with properties that are functions</li>
|
||||
<li>Date objects or object with properties that are Date objects</li>
|
||||
<li>RegEx or object with properties that are RegEx objects</li>
|
||||
<li>Prototype copying</li>
|
||||
<li>関数のプロパティを持つオブジェクト</li>
|
||||
<li>日付オブジェクト、または日付オブジェクトであるプロパティを持つオブジェクト</li>
|
||||
<li>RegEx、またはRegExオブジェクトであるプロパティを持つオブジェクト</li>
|
||||
<li>プロトタイプのコピー</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`deepcopy` should be a function.
|
||||
`deepcopy` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof deepcopy === 'function');
|
||||
```
|
||||
|
||||
`deepcopy({test: "test"})` should return an object.
|
||||
`deepcopy({test: "test"})` はオブジェクトを返します。
|
||||
|
||||
```js
|
||||
assert(typeof deepcopy(obj1) === 'object');
|
||||
```
|
||||
|
||||
`deepcopy` should not return the same object that was provided.
|
||||
`deepcopy` は元のオブジェクトと同じオブジェクトを返しません。
|
||||
|
||||
```js
|
||||
assert(deepcopy(obj2) != obj2);
|
||||
```
|
||||
|
||||
When passed an object containing an array, `deepcopy` should return a deep copy of the object.
|
||||
配列を含むオブジェクトが渡された場合、 `deepcopy` はそのオブジェクトのディープコピーを返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(deepcopy(obj2), obj2);
|
||||
```
|
||||
|
||||
When passed an object containing another object, `deepcopy` should return a deep copy of the object.
|
||||
別のオブジェクトを含むオブジェクトが渡された場合、 `deepcopy` はそのオブジェクトのディープコピーを返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(deepcopy(obj3), obj3);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 597089c87eec450c68aa1643
|
||||
title: Define a primitive data type
|
||||
title: プリミティブデータ型を定義
|
||||
challengeType: 5
|
||||
forumTopicId: 302248
|
||||
dashedName: define-a-primitive-data-type
|
||||
@ -8,96 +8,96 @@ dashedName: define-a-primitive-data-type
|
||||
|
||||
# --description--
|
||||
|
||||
Define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10.
|
||||
整数のように動作するが、最小の有効値が1で最大の有効値が10である型を定義します。
|
||||
|
||||
Error handling:
|
||||
エラー処理:
|
||||
|
||||
<ul>
|
||||
<li>If you try to instantiate a <code>Num</code> with a value outside of 1 - 10, it should throw a <code>TypeError</code> with an error message of <code>'Out of range'</code>.</li>
|
||||
<li>If you try to instantiate a <code>Num</code> with a value that is not a number, it should throw a <code>TypeError</code> with an error message of <code>'Not a Number'</code>.</li>
|
||||
<li><code>Num</code> を1から10以外の値でインスタンス化しようとすると、<code>TypeError</code> が返され、<code>'Out of range'</code> のエラーメッセージが表示されます。</li>
|
||||
<li><code>Num</code> を数字ではない値でインスタンス化しようとすると、<code>TypeError</code> が返され、<code>'Not a Number'</code> のエラーメッセージが表示されます。</li>
|
||||
</ul>
|
||||
|
||||
# --hints--
|
||||
|
||||
`Num` should be a function.
|
||||
`Num` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof Num === 'function');
|
||||
```
|
||||
|
||||
`new Num(4)` should return an object.
|
||||
`new Num(4)` はオブジェクトを返します。
|
||||
|
||||
```js
|
||||
assert(typeof new Num(4) === 'object');
|
||||
```
|
||||
|
||||
`new Num('test')` should throw a TypeError with message 'Not a Number'.
|
||||
`new Num('test')` は TypeError を返し、「Not a Number」のメッセージが表示されます。
|
||||
|
||||
```js
|
||||
assert.throws(() => new Num('test'), TypeError);
|
||||
```
|
||||
|
||||
`new Num(0)` should throw a TypeError with message 'Out of range'.
|
||||
`new Num(0)` は TypeError を返し、「Out of range」のメッセージが表示されます。
|
||||
|
||||
```js
|
||||
assert.throws(() => new Num(0), TypeError);
|
||||
```
|
||||
|
||||
`new Num(-5)` should throw a TypeError with message 'Out of range'.
|
||||
`new Num(-5)` は TypeError を返し、「Out of range」のメッセージが表示されます。
|
||||
|
||||
```js
|
||||
assert.throws(() => new Num(-5), TypeError);
|
||||
```
|
||||
|
||||
`new Num(10)` should throw a TypeError with message 'Out of range'.
|
||||
`new Num(10)` は TypeError を返し、「Out of range」のメッセージが表示されます。
|
||||
|
||||
```js
|
||||
assert.throws(() => new Num(11), TypeError);
|
||||
```
|
||||
|
||||
`new Num(20)` should throw a TypeError with message 'Out of range'.
|
||||
`new Num(20)` は TypeError を返し、「Out of range」のメッセージが表示されます。
|
||||
|
||||
```js
|
||||
assert.throws(() => new Num(20), TypeError);
|
||||
```
|
||||
|
||||
`new Num(3) + new Num(4)` should equal 7.
|
||||
`new Num(3) + new Num(4)` は 7 と等しくなります。
|
||||
|
||||
```js
|
||||
assert.equal(new Num(3) + new Num(4), 7);
|
||||
```
|
||||
|
||||
`new Num(3) - new Num(4)` should equal -1.
|
||||
`new Num(3) - new Num(4)` は -1 と等しくなります。
|
||||
|
||||
```js
|
||||
assert.equal(new Num(3) - new Num(4), -1);
|
||||
```
|
||||
|
||||
`new Num(3) * new Num(4)` should equal 12.
|
||||
`new Num(3) * new Num(4)` は 12 と等しくなります。
|
||||
|
||||
```js
|
||||
assert.equal(new Num(3) * new Num(4), 12);
|
||||
```
|
||||
|
||||
`new Num(3) / new Num(4)` should equal 0.75.
|
||||
`new Num(3) / new Num(4)` は 0.75 と等しくなります。
|
||||
|
||||
```js
|
||||
assert.equal(new Num(3) / new Num(4), 0.75);
|
||||
```
|
||||
|
||||
`new Num(3) < new Num(4)` should be true.
|
||||
`new Num(3) < new Num(4)` は真となります。
|
||||
|
||||
```js
|
||||
assert(new Num(3) < new Num(4));
|
||||
```
|
||||
|
||||
`new Num(3) > new Num(4)` should be false.
|
||||
`new Num(3) > new Num(4)` は偽となります。
|
||||
|
||||
```js
|
||||
assert(!(new Num(3) > new Num(4)));
|
||||
```
|
||||
|
||||
`(new Num(5)).toString()` should return '5'
|
||||
`(new Num(5)).toString()` は「5」を返します。
|
||||
|
||||
```js
|
||||
assert.equal(new Num(5).toString(), '5');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59f40b17e79dbf1ab720ed7a
|
||||
title: Department Numbers
|
||||
title: 部署番号
|
||||
challengeType: 5
|
||||
forumTopicId: 302249
|
||||
dashedName: department-numbers
|
||||
@ -8,23 +8,23 @@ dashedName: department-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
There is a highly organized city that has decided to assign a number to each of their departments:
|
||||
高度に組織化された都市が、各部署に番号を割り当てることにしました。
|
||||
|
||||
<ul>
|
||||
<li>Police department</li>
|
||||
<li>Sanitation department</li>
|
||||
<li>Fire department</li>
|
||||
<li>警察局</li>
|
||||
<li>公衆衛生局</li>
|
||||
<li>消防局</li>
|
||||
</ul>
|
||||
|
||||
Each department can have a number between 1 and 7 (inclusive).
|
||||
各部署は1から7までの数字を持つことができます。
|
||||
|
||||
The three department numbers are to be unique (different from each other) and must add up to the number 12.
|
||||
3つの部署番号は (互いに異なる) 一意の数字で、足して12にする必要があります。
|
||||
|
||||
The Chief of the Police doesn't like odd numbers and wants to have an even number for his department.
|
||||
警察長官は、奇数が好きではないので、部署に偶数番号が欲しいと考えています。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a program which outputs all valid combinations as an array.
|
||||
すべての有効な組み合わせを配列として出力するプログラムを作成します。
|
||||
|
||||
```js
|
||||
[2, 3, 7] [2, 4, 6] [2, 6, 4]
|
||||
@ -36,25 +36,25 @@ Write a program which outputs all valid combinations as an array.
|
||||
|
||||
# --hints--
|
||||
|
||||
`combinations` should be a function.
|
||||
`combinations` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof combinations === 'function');
|
||||
```
|
||||
|
||||
`combinations([1, 2, 3], 6)` should return an Array.
|
||||
`combinations([1, 2, 3], 6)` は配列を返します。
|
||||
|
||||
```js
|
||||
assert(Array.isArray(combinations([1, 2, 3], 6)));
|
||||
```
|
||||
|
||||
`combinations([1, 2, 3, 4, 5, 6, 7], 12)` should return an array of length 14.
|
||||
`combinations([1, 2, 3, 4, 5, 6, 7], 12)` は14の配列を返します。
|
||||
|
||||
```js
|
||||
assert(combinations(nums, total).length === len);
|
||||
```
|
||||
|
||||
`combinations([1, 2, 3, 4, 5, 6, 7], 12)` should return all valid combinations.
|
||||
`combinations([1, 2, 3, 4, 5, 6, 7], 12)` はすべての有効な組み合わせを返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(combinations(nums, total), result);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59f4eafba0343628bb682785
|
||||
title: Discordian date
|
||||
title: ディスコルディア暦の日付
|
||||
challengeType: 5
|
||||
forumTopicId: 302250
|
||||
dashedName: discordian-date
|
||||
@ -8,17 +8,17 @@ dashedName: discordian-date
|
||||
|
||||
# --description--
|
||||
|
||||
Convert a given date from the [Gregorian calendar](https://en.wikipedia.org/wiki/Gregorian calendar "wp: Gregorian calendar") to the [Discordian calendar](https://en.wikipedia.org/wiki/Discordian calendar "wp: Discordian calendar").
|
||||
与えられた日付を[グレゴリオ暦](https://en.wikipedia.org/wiki/Gregorian calendar "wp: Gregorian calendar") から [ディスコルディア暦](https://en.wikipedia.org/wiki/Discordian calendar "wp: Discordian calendar")に変換します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`discordianDate` should be a function.
|
||||
`discordianDate` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof discordianDate === 'function');
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2010, 6, 22))` should return `"Pungenday, the 57th day of Confusion in the YOLD 3176"`.
|
||||
`discordianDate(new Date(2010, 6, 22))` は `"Pungenday, the 57th day of Confusion in the YOLD 3176"` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -27,7 +27,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2012, 1, 28))` should return `"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"`.
|
||||
`discordianDate(new Date(2012, 1, 28))` は `"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -36,7 +36,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2012, 1, 29))` should return `"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\'s Day!"`.
|
||||
`discordianDate(new Date(2012, 1, 29))` は `"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\'s Day!" ` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -45,7 +45,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2012, 2, 1))` should return `"Setting Orange, the 60th day of Chaos in the YOLD 3178"`.
|
||||
`discordianDate(new Date(2012, 2, 1))` は `"Setting Orange, the 60th day of Chaos in the YOLD 3178"` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -54,7 +54,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2010, 0, 5))` should return `"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"`.
|
||||
`discordianDate(new Date(2010, 0, 5))` は `"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!" ` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -63,7 +63,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2011, 4, 3))` should return `"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!"`.
|
||||
`discordianDate(new Date(2011, 4, 3))` は `"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!" ` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -72,7 +72,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`discordianDate(new Date(2015, 9, 19))` should return `"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"`.
|
||||
`discordianDate(new Date(2015, 9, 19))` は `"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"` を返します。
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5a23c84252665b21eecc7e1e
|
||||
title: Dot product
|
||||
title: ドット積
|
||||
challengeType: 5
|
||||
forumTopicId: 302251
|
||||
dashedName: dot-product
|
||||
@ -8,47 +8,47 @@ dashedName: dot-product
|
||||
|
||||
# --description--
|
||||
|
||||
Create a function, to compute the **[dot product](https://en.wikipedia.org/wiki/Dot product)**, also known as the **scalar product** of two vectors.
|
||||
2つのベクトルの**スカラー積**としても知られる**[ドット積](https://en.wikipedia.org/wiki/Dot product)**を計算する関数を作成します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`dotProduct` should be a function.
|
||||
`dotProduct` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof dotProduct == 'function');
|
||||
```
|
||||
|
||||
`dotProduct([1, 3, -5], [4, -2, -1])` should return a number.
|
||||
`dotProduct([1, 3, -5], [4, -2, -1])` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof dotProduct([1, 3, -5], [4, -2, -1]) == 'number');
|
||||
```
|
||||
|
||||
`dotProduct([1, 3, -5], [4, -2, -1])` should return `3`.
|
||||
`dotProduct([1, 3, -5], [4, -2, -1])` は `3` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3);
|
||||
```
|
||||
|
||||
`dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])` should return `130`.
|
||||
`dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])` は `130` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), 130);
|
||||
```
|
||||
|
||||
`dotProduct([5, 4, 3, 2], [7, 8, 9, 6])` should return `106`.
|
||||
`dotProduct([5, 4, 3, 2], [7, 8, 9, 6])` は `106` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([5, 4, 3, 2], [7, 8, 9, 6]), 106);
|
||||
```
|
||||
|
||||
`dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6])` should return `-36`.
|
||||
`dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6])` は `-36` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6]), -36);
|
||||
```
|
||||
|
||||
`dotProduct([17, 27, 34, 43, 15], [62, 73, 48, 95, 110])` should return `10392`.
|
||||
`dotProduct([17, 27, 34, 43, 15], [62, 73, 48, 95, 110])` は `10392` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(dotProduct([17, 27, 34, 43, 15], [62, 73, 48, 95, 110]), 10392);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 599c333915e0ea32d04d4bec
|
||||
title: Element-wise operations
|
||||
title: 要素ごとの演算
|
||||
challengeType: 5
|
||||
forumTopicId: 302252
|
||||
dashedName: element-wise-operations
|
||||
@ -8,29 +8,29 @@ dashedName: element-wise-operations
|
||||
|
||||
# --description--
|
||||
|
||||
Implement basic element-wise matrix-matrix and scalar-matrix operations.
|
||||
基本的な要素ごとの matrix-matrix と scalar-matrix 演算を実装します。
|
||||
|
||||
**Implement:**
|
||||
**実装:**
|
||||
|
||||
<ul>
|
||||
<li>addition</li>
|
||||
<li>subtraction</li>
|
||||
<li>multiplication</li>
|
||||
<li>division</li>
|
||||
<li>exponentiation</li>
|
||||
<li>加法</li>
|
||||
<li>減法</li>
|
||||
<li>乗法</li>
|
||||
<li>除法</li>
|
||||
<li>累乗法</li>
|
||||
</ul>
|
||||
|
||||
The first parameter will be the operation to be performed, for example, "m_add" for matrix addition and "s_add" for scalar addition. The second and third parameters will be the matrices on which the operations are to be performed.
|
||||
最初のパラメータは、実行される演算を表します。例えば、行列の加法では"m_add"、スカラーの加法では"s_add"です。 2番目と3番目のパラメータは、演算の対象となる行列を表します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`operation` should be a function.
|
||||
`operation` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof operation === 'function');
|
||||
```
|
||||
|
||||
`operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[2,4],[6,8]]`.
|
||||
`operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])` は `[[2,4],[6,8]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -52,7 +52,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`operation("s_add",[[1,2],[3,4]],2)` should return `[[3,4],[5,6]]`.
|
||||
`operation("s_add",[[1,2],[3,4]],2)` は `[[3,4],[5,6]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -71,7 +71,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[0,0],[0,0]]`.
|
||||
`operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])` は `[[0,0],[0,0]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -93,7 +93,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[1,4],[9,16]]`.
|
||||
`operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])` は `[[1,4],[9,16]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -115,7 +115,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[1,1],[1,1]]`.
|
||||
`operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])` は `[[1,1],[1,1]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -137,7 +137,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[1,4],[27,256]]`.
|
||||
`operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])` は `[[1,4],[27,256]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
@ -159,7 +159,7 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
`operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])` should return `[[10,12,14,16],[18,20,22,24]]`.
|
||||
`operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])` は `[[10,12,14,16],[18,20,22,24]]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 599d0ba974141b0f508b37d5
|
||||
title: Emirp primes
|
||||
title: エマープ
|
||||
challengeType: 5
|
||||
forumTopicId: 302253
|
||||
dashedName: emirp-primes
|
||||
@ -8,30 +8,30 @@ dashedName: emirp-primes
|
||||
|
||||
# --description--
|
||||
|
||||
An emirp (**prime** spelled backwards) are primes that when reversed (in their decimal representation) are a different prime.
|
||||
emirp (**prime** の逆さの綴り) は、(10 進数表記で) 逆から読んでも素数になる素数です。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that:
|
||||
以下の関数を作成します。
|
||||
|
||||
<ul>
|
||||
<li>Shows the first <code>n</code> emirp numbers.</li>
|
||||
<li>Shows the emirp numbers in a range.</li>
|
||||
<li>Shows the number of emirps in a range.</li>
|
||||
<li>Shows the <code>n<sup>th</sup></code> emirp number.</li>
|
||||
<li>最初の <code>n</code> 個のエマープを表示します。</li>
|
||||
<li>範囲内のエマープを表示します。</li>
|
||||
<li>範囲内のエマープの数を表示します。</li>
|
||||
<li><code>n<sup>th</sup></code> のエマープを表示します。</li>
|
||||
</ul>
|
||||
|
||||
The function should accept two parameters. The first will receive `n` or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the <code>n<sup>th</sup></code> prime). According to the parameters the function should return an array or a number.
|
||||
関数は2つのパラメーターを使用します。 1つ目としては、`n` または範囲を配列として受け取ります。 2 つ目は、ブール値です。 ブール値は、関数が エマープを配列として返すか、単一の数値 として返すかを指定します (範囲内の素数、または <code>n<sup>th</sup></code> 素数)。 パラメータに基づき、関数は配列または数値を返します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`emirps` should be a function.
|
||||
`emirps` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof emirps === 'function');
|
||||
```
|
||||
|
||||
`emirps(20,true)` should return `[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]`
|
||||
`emirps(20,true)` は `[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(emirps(20, true), [
|
||||
@ -58,13 +58,13 @@ assert.deepEqual(emirps(20, true), [
|
||||
]);
|
||||
```
|
||||
|
||||
`emirps(1000)` should return `70529`
|
||||
`emirps(1000)` は `70529` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(emirps(1000), 70529);
|
||||
```
|
||||
|
||||
`emirps([7700,8000],true)` should return `[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]`
|
||||
`emirps([7700,8000],true)` は `[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(emirps([7700, 8000], true), [
|
||||
@ -82,7 +82,7 @@ assert.deepEqual(emirps([7700, 8000], true), [
|
||||
]);
|
||||
```
|
||||
|
||||
`emirps([7700,8000],false)` should return `11`
|
||||
`emirps([7700,8000],false)` は `11` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(emirps([7700, 8000], false), 11);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 599d15309e88c813a40baf58
|
||||
title: Entropy
|
||||
title: エントロピー
|
||||
challengeType: 5
|
||||
forumTopicId: 302254
|
||||
dashedName: entropy
|
||||
@ -8,53 +8,53 @@ dashedName: entropy
|
||||
|
||||
# --description--
|
||||
|
||||
Calculate the Shannon entropy H of a given input string.
|
||||
与えられた入力文字列のシャノンエントロピーHを計算します。
|
||||
|
||||
Given the discreet random variable $X$ that is a string of $N$ "symbols" (total characters) consisting of $n$ different characters (n=2 for binary), the Shannon entropy of X in bits/symbol is:
|
||||
$n$ の異なる文字 (2進数でn=2) からなる$N$「シンボル」文字列 (合計文字) である離散確率変数 $X$ の場合、Xのシャノンエントロピーをビット/シンボルで表すと以下のようになります。
|
||||
|
||||
$H_2(X) = -\\sum\_{i=1}^n \\frac{count_i}{N} \\log_2 \\left(\\frac{count_i}{N}\\right)$
|
||||
|
||||
where $count_i$ is the count of character $n_i$.
|
||||
$count_i$ は、文字 $n_i$ の数です。
|
||||
|
||||
# --hints--
|
||||
|
||||
`entropy` should be a function.
|
||||
`entropy` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof entropy === 'function');
|
||||
```
|
||||
|
||||
`entropy("0")` should return `0`
|
||||
`entropy("0")` は `0` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(entropy('0'), 0);
|
||||
```
|
||||
|
||||
`entropy("01")` should return `1`
|
||||
`entropy("01")` は `1` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(entropy('01'), 1);
|
||||
```
|
||||
|
||||
`entropy("0123")` should return `2`
|
||||
`entropy("0123")` は `2` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(entropy('0123'), 2);
|
||||
```
|
||||
|
||||
`entropy("01234567")` should return `3`
|
||||
`entropy("01234567")` は `3` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(entropy('01234567'), 3);
|
||||
```
|
||||
|
||||
`entropy("0123456789abcdef")` should return `4`
|
||||
`entropy("0123456789abcdef")` は `4` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(entropy('0123456789abcdef'), 4);
|
||||
```
|
||||
|
||||
`entropy("1223334444")` should return `1.8464393446710154`
|
||||
`entropy("1223334444")` は `1.8464393446710154` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(entropy('1223334444'), 1.8464393446710154);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5987fd532b954e0f21b5d3f6
|
||||
title: Equilibrium index
|
||||
title: 平衡インデックス
|
||||
challengeType: 5
|
||||
forumTopicId: 302255
|
||||
dashedName: equilibrium-index
|
||||
@ -8,9 +8,9 @@ dashedName: equilibrium-index
|
||||
|
||||
# --description--
|
||||
|
||||
An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices.
|
||||
数列の平衡インデックスは、下位インデックスの要素の合計が上位インデックスの要素の合計と等しくなるような数列へのインデックスです。
|
||||
|
||||
For example, in a sequence $A$:
|
||||
下記は数列 $A$ の例です。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$A_0 = -7$</big></li>
|
||||
@ -22,67 +22,67 @@ For example, in a sequence $A$:
|
||||
<li><big>$A_6 = 0$</big></li>
|
||||
</ul>
|
||||
|
||||
`3` is an equilibrium index, because:
|
||||
`3` は以下の理由で平衡インデックスです。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$A_0 + A_1 + A_2 = A_4 + A_5 + A_6$</big></li>
|
||||
</ul>
|
||||
|
||||
`6` is also an equilibrium index, because:
|
||||
`6` も以下の理由で平衡インデックスです。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0$</big></li>
|
||||
</ul>
|
||||
|
||||
(sum of zero elements is zero)
|
||||
(要素ゼロの合計はゼロです。)
|
||||
|
||||
`7` is not an equilibrium index, because it is not a valid index of sequence $A$.
|
||||
`7` は、数列 $A$ の有効なインデックスではないため、平衡インデックスではありません。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that, given a sequence, returns its equilibrium indices (if any).
|
||||
与えられた数列で、平衡インデックスがあれば返す関数を作成します。
|
||||
|
||||
Assume that the sequence may be very long.
|
||||
非常に長い数式の可能性もあります。
|
||||
|
||||
# --hints--
|
||||
|
||||
`equilibrium` should be a function.
|
||||
`equilibrium` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof equilibrium === 'function');
|
||||
```
|
||||
|
||||
`equilibrium([-7, 1, 5, 2, -4, 3, 0])` should return `[3,6]`.
|
||||
`equilibrium([-7, 1, 5, 2, -4, 3, 0])` は `[3,6]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(equilibrium(equilibriumTests[0]), ans[0]);
|
||||
```
|
||||
|
||||
`equilibrium([2, 4, 6])` should return `[]`.
|
||||
`equilibrium([2, 4, 6])` は `[]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(equilibrium(equilibriumTests[1]), ans[1]);
|
||||
```
|
||||
|
||||
`equilibrium([2, 9, 2])` should return `[1]`.
|
||||
`equilibrium([2, 9, 2])` は `[1]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(equilibrium(equilibriumTests[2]), ans[2]);
|
||||
```
|
||||
|
||||
`equilibrium([1, -1, 1, -1, 1, -1, 1])` should return `[0,1,2,3,4,5,6]`.
|
||||
`equilibrium([1, -1, 1, -1, 1, -1, 1])` は `[0,1,2,3,4,5,6]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(equilibrium(equilibriumTests[3]), ans[3]);
|
||||
```
|
||||
|
||||
`equilibrium([1])` should return `[0]`.
|
||||
`equilibrium([1])` は `[0]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(equilibrium(equilibriumTests[4]), ans[4]);
|
||||
```
|
||||
|
||||
`equilibrium([])` should return `[]`.
|
||||
`equilibrium([])` は `[]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(equilibrium(equilibriumTests[5]), ans[5]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 599d1566a02b571412643b84
|
||||
title: Ethiopian multiplication
|
||||
title: エチオピア乗算
|
||||
challengeType: 5
|
||||
forumTopicId: 302257
|
||||
dashedName: ethiopian-multiplication
|
||||
@ -8,24 +8,24 @@ dashedName: ethiopian-multiplication
|
||||
|
||||
# --description--
|
||||
|
||||
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.
|
||||
エチオピア乗算は、加算、倍増、および半減のみを使用して整数を乗算する方法です。
|
||||
|
||||
**Method:**
|
||||
**方法:**
|
||||
|
||||
<ol>
|
||||
<li>Take two numbers to be multiplied and write them down at the top of two columns</li>
|
||||
<li>In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of <code>1</code></li>
|
||||
<li>In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows <code>1</code></li>
|
||||
<li>Examine the table produced and discard any row where the value in the left column is even</li>
|
||||
<li>Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together</li>
|
||||
<li>乗算対象の2つの数を取り、2つの列の上に書きます。</li>
|
||||
<li>左側の列で、最後の数字を繰り返し2で割り、残りを捨て、値が <code>1</code> になるまで同じ列の最後に結果を書き込みます。</li>
|
||||
<li>右側の列で、繰り返し最後の数字を2倍にして、結果を列の最後に書きます。 左側の列に <code>1</code> が表示されている行まで結果を入れ、その後停止します。</li>
|
||||
<li>出来上がったテーブル見て、左側の列の値が偶数である行を削除します。</li>
|
||||
<li>残っている右側の列の値を加算すると、元の2つの数を乗算した結果になります。</li>
|
||||
</ol>
|
||||
|
||||
**For example:** `17 × 34`
|
||||
**例:** `17 × 34`
|
||||
|
||||
<pre>17 34
|
||||
</pre>
|
||||
|
||||
Halving the first column:
|
||||
最初の列の値を2で割ります。
|
||||
|
||||
<pre>17 34
|
||||
8
|
||||
@ -34,7 +34,7 @@ Halving the first column:
|
||||
1
|
||||
</pre>
|
||||
|
||||
Doubling the second column:
|
||||
2列目を倍にします。
|
||||
|
||||
<pre>17 34
|
||||
8 68
|
||||
@ -43,7 +43,7 @@ Doubling the second column:
|
||||
1 544
|
||||
</pre>
|
||||
|
||||
Strike-out rows whose first cell is even:
|
||||
最初の列が偶数の行の値を消します。
|
||||
|
||||
<pre>17 34
|
||||
8 <strike>68</strike>
|
||||
@ -52,7 +52,7 @@ Strike-out rows whose first cell is even:
|
||||
1 544
|
||||
</pre>
|
||||
|
||||
Sum the remaining numbers in the right-hand column:
|
||||
右側の列の残りの数字を合計します。
|
||||
|
||||
<!-- markdownlint-disable MD003 -->
|
||||
|
||||
@ -67,55 +67,55 @@ Sum the remaining numbers in the right-hand column:
|
||||
|
||||
<!-- markdownlint-enable MD003 -->
|
||||
|
||||
So `17` multiplied by `34`, by the Ethiopian method is `578`.
|
||||
エチオピア乗算で `17` に `34` を掛けると `578` になります。
|
||||
|
||||
# --instructions--
|
||||
|
||||
The task is to define three named functions/methods/procedures/subroutines:
|
||||
タスクは、3つの名前付き関数/メソッド/プロシージャ/サブルーチンを定義することです。
|
||||
|
||||
<ol>
|
||||
<li>one to halve an integer,</li>
|
||||
<li>one to double an integer, and</li>
|
||||
<li>one to state if an integer is even</li>
|
||||
<li>整数を半分にする</li>
|
||||
<li>整数を2倍にする</li>
|
||||
<li>整数が偶数かどうかを示す</li>
|
||||
</ol>
|
||||
|
||||
Use these functions to create a function that does Ethiopian multiplication.
|
||||
これらを使ってエチオピア乗算を行う関数を作ります。
|
||||
|
||||
<!-- markdownlint-disable MD046-->
|
||||
|
||||
# --hints--
|
||||
|
||||
`eth_mult` should be a function.
|
||||
`eth_mult` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof eth_mult === 'function');
|
||||
```
|
||||
|
||||
`eth_mult(17,34)` should return `578`.
|
||||
`eth_mult(17,34)` は `578` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eth_mult(17, 34), 578);
|
||||
```
|
||||
|
||||
`eth_mult(23,46)` should return `1058`.
|
||||
`eth_mult(23,46)` は `1058` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eth_mult(23, 46), 1058);
|
||||
```
|
||||
|
||||
`eth_mult(12,27)` should return `324`.
|
||||
`eth_mult(12,27)` は `324` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eth_mult(12, 27), 324);
|
||||
```
|
||||
|
||||
`eth_mult(56,98)` should return `5488`.
|
||||
`eth_mult(56,98)` は `5488` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eth_mult(56, 98), 5488);
|
||||
```
|
||||
|
||||
`eth_mult(63,74)` should return `4662`.
|
||||
`eth_mult(63,74)` は `4662` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eth_mult(63, 74), 4662);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59880443fb36441083c6c20e
|
||||
title: Euler method
|
||||
title: オイラー法
|
||||
challengeType: 5
|
||||
forumTopicId: 302258
|
||||
dashedName: euler-method
|
||||
@ -8,63 +8,63 @@ dashedName: euler-method
|
||||
|
||||
# --description--
|
||||
|
||||
Euler's method numerically approximates solutions of first-order ordinary differential equations (ODEs) with a given initial value. It is an explicit method for solving initial value problems (IVPs), as described in [this article](https://www.freecodecamp.org/news/eulers-method-explained-with-examples/ "news: Euler's Method Explained with Examples").
|
||||
オイラー法は、所定の初期値を持つ1階の常微分方程式 (ODE) の解における近似値を求めます。 [記事](https://www.freecodecamp.org/news/eulers-method-explained-with-examples/ "news: Euler's Method Explained with Examples") で論説されているように、初期値の問題(IVP)を解くための明示的な方法です。
|
||||
|
||||
The ODE has to be provided in the following form:
|
||||
ODEは以下の形式で書きます。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$\frac{dy(t)}{dt} = f(t,y(t))$</big></li>
|
||||
</ul>
|
||||
|
||||
with an initial value
|
||||
下記が初期値です。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$y(t_0) = y_0$</big></li>
|
||||
</ul>
|
||||
|
||||
To get a numeric solution, we replace the derivative on the LHS with a finite difference approximation:
|
||||
数値解を得るために、LHS上の導関数を有限差分近似に置き換えます。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$\frac{dy(t)}{dt} \approx \frac{y(t+h)-y(t)}{h}$</big></li>
|
||||
</ul>
|
||||
|
||||
then solve for $y(t+h)$:
|
||||
次に $y(t+h)$ の値を求めます。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$y(t+h) \approx y(t) + h \, \frac{dy(t)}{dt}$</big></li>
|
||||
</ul>
|
||||
|
||||
which is the same as
|
||||
これは以下と同じです。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$y(t+h) \approx y(t) + h \, f(t,y(t))$</big></li>
|
||||
</ul>
|
||||
|
||||
The iterative solution rule is then:
|
||||
反復解法ルールは次のとおりです。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$y_{n+1} = y_n + h \, f(t_n, y_n)$</big></li>
|
||||
</ul>
|
||||
|
||||
where $h$ is the step size, the most relevant parameter for accuracy of the solution. A smaller step size increases accuracy but also the computation cost, so it has always has to be hand-picked according to the problem at hand.
|
||||
$h$ はステップサイズで、解の精度に関連する最も重要なパラメータです。 ステップサイズが小さいほど精度は向上しますが、計算コストも高くなるため、目の前の問題に応じて常に手作業で処理する必要があります。
|
||||
|
||||
**Example: Newton's Cooling Law**
|
||||
**例: ニュートンの冷却の法則**
|
||||
|
||||
Newton's cooling law describes how an object of initial temperature $T(t_0) = T_0$ cools down in an environment of temperature $T_R$:
|
||||
ニュートンの冷却の法則は、温度$T_R$下において、初期温度$T(t_0) = T_0$ のオブジェクトが冷却される様子を表した法則です。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$\frac{dT(t)}{dt} = -k \, \Delta T$</big></li>
|
||||
</ul>
|
||||
|
||||
or
|
||||
または
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$\frac{dT(t)}{dt} = -k \, (T(t) - T_R)$</big></li>
|
||||
</ul>
|
||||
|
||||
It says that the cooling rate $\\frac{dT(t)}{dt}$ of the object is proportional to the current temperature difference $\\Delta T = (T(t) - T_R)$ to the surrounding environment.
|
||||
オブジェクトの冷却率 $\\frac{dT(t)}{dt}$ は、周囲環境に対する現在の温度差 $\\Delta T = (T) - T_R)$ に比例するとされています。
|
||||
|
||||
The analytical solution, which we will compare to the numerical approximation, is
|
||||
数値近似との比較として、解析解は以下のとおりです。
|
||||
|
||||
<ul style='list-style: none;'>
|
||||
<li><big>$T(t) = T_R + (T_0 - T_R) \; e^{-k t}$</big></li>
|
||||
@ -72,54 +72,54 @@ The analytical solution, which we will compare to the numerical approximation, i
|
||||
|
||||
# --instructions--
|
||||
|
||||
Implement a routine of Euler's method and then use it to solve the given example of Newton's cooling law for three different step sizes of:
|
||||
オイラー方のルーチンを実装して、以下の3つの異なるステップサイズのニュートンの冷却の法則の例題を解きます。
|
||||
|
||||
<ul>
|
||||
<li><code>2 s</code></li>
|
||||
<li><code>5 s</code> and</li>
|
||||
<li><code>5 s</code></li>
|
||||
<li><code>10 s</code></li>
|
||||
</ul>
|
||||
|
||||
and compare with the analytical solution.
|
||||
次に、解析解と比較します。
|
||||
|
||||
**Initial values:**
|
||||
**初期値:**
|
||||
|
||||
<ul>
|
||||
<li>initial temperature <big>$T_0$</big> shall be <code>100 °C</code></li>
|
||||
<li>room temperature <big>$T_R$</big> shall be <code>20 °C</code></li>
|
||||
<li>cooling constant <big>$k$</big> shall be <code>0.07</code></li>
|
||||
<li>time interval to calculate shall be from <code>0 s</code> to <code>100 s</code></li>
|
||||
<li>初期温度 <big>$T_0$</big> は <code>100 °C</code> です</li>
|
||||
<li>室温 <big>$T_R$</big> は <code>20 °C</code> です</li>
|
||||
<li>冷却定数 <big>$k$</big> は <code>0.07</code>です</li>
|
||||
<li>計算する時間間隔は、 <code>0 s</code> から <code>100 s</code>です</li>
|
||||
</ul>
|
||||
|
||||
First parameter to the function is initial time, second parameter is initial temperature, third parameter is elapsed time and fourth parameter is step size.
|
||||
関数の最初のパラメータは初期時間、2番目のパラメータは初期温度、3番目のパラメータは経過時間、4番目のパラメータはステップサイズです。
|
||||
|
||||
# --hints--
|
||||
|
||||
`eulersMethod` should be a function.
|
||||
`eulersMethod` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof eulersMethod === 'function');
|
||||
```
|
||||
|
||||
`eulersMethod(0, 100, 100, 2)` should return a number.
|
||||
`eulersMethod(0, 100, 100, 2)` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof eulersMethod(0, 100, 100, 2) === 'number');
|
||||
```
|
||||
|
||||
`eulersMethod(0, 100, 100, 2)` should return 20.0424631833732.
|
||||
`eulersMethod(0, 100, 100, 2)` は 20.0424631833732 を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eulersMethod(0, 100, 100, 2), 20.0424631833732);
|
||||
```
|
||||
|
||||
`eulersMethod(0, 100, 100, 5)` should return 20.01449963666907.
|
||||
`eulersMethod(0, 100, 100, 5)` は 20.01449963666907 を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eulersMethod(0, 100, 100, 5), 20.01449963666907);
|
||||
```
|
||||
|
||||
`eulersMethod(0, 100, 100, 10)` should return 20.000472392.
|
||||
`eulersMethod(0, 100, 100, 10)` は 20.000472392 を返します。
|
||||
|
||||
```js
|
||||
assert.equal(eulersMethod(0, 100, 100, 10), 20.000472392);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 598de241872ef8353c58a7a2
|
||||
title: Evaluate binomial coefficients
|
||||
title: 二項係数の評価
|
||||
challengeType: 5
|
||||
forumTopicId: 302259
|
||||
dashedName: evaluate-binomial-coefficients
|
||||
@ -8,45 +8,45 @@ dashedName: evaluate-binomial-coefficients
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to calculate the binomial coefficient for the given value of n and k.
|
||||
与えられたnとkの値の二項係数を計算する関数を作成します。
|
||||
|
||||
This formula is recommended:
|
||||
以下の数式を推奨します。
|
||||
|
||||
$\\binom{n}{k} = \\frac{n!}{(n-k)!k!} = \\frac{n(n-1)(n-2)\\ldots(n-k+1)}{k(k-1)(k-2)\\ldots 1}$
|
||||
|
||||
# --hints--
|
||||
|
||||
`binom` should be a function.
|
||||
`binom` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof binom === 'function');
|
||||
```
|
||||
|
||||
`binom(5,3)` should return 10.
|
||||
`binom(5,3)` は10を返します。
|
||||
|
||||
```js
|
||||
assert.equal(binom(5, 3), 10);
|
||||
```
|
||||
|
||||
`binom(7,2)` should return 21.
|
||||
`binom(7,2)` は21を返します。
|
||||
|
||||
```js
|
||||
assert.equal(binom(7, 2), 21);
|
||||
```
|
||||
|
||||
`binom(10,4)` should return 210.
|
||||
`binom(10,4)` は210を返します。
|
||||
|
||||
```js
|
||||
assert.equal(binom(10, 4), 210);
|
||||
```
|
||||
|
||||
`binom(6,1)` should return 6.
|
||||
`binom(6,1)` は6を返します。
|
||||
|
||||
```js
|
||||
assert.equal(binom(6, 1), 6);
|
||||
```
|
||||
|
||||
`binom(12,8)` should return 495.
|
||||
`binom(12,8)` は495を返します。
|
||||
|
||||
```js
|
||||
assert.equal(binom(12, 8), 495);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59e09e6d412c5939baa02d16
|
||||
title: Execute a Markov algorithm
|
||||
title: マルコフアルゴリズム
|
||||
challengeType: 5
|
||||
forumTopicId: 302260
|
||||
dashedName: execute-a-markov-algorithm
|
||||
@ -8,9 +8,9 @@ dashedName: execute-a-markov-algorithm
|
||||
|
||||
# --description--
|
||||
|
||||
Create an interpreter for a [Markov Algorithm](https://en.wikipedia.org/wiki/Markov algorithm "wp: Markov algorithm").
|
||||
[マルコフアルゴリズム](https://en.wikipedia.org/wiki/Markov algorithm "wp: Markov algorithm") のインタプリタを作成します。
|
||||
|
||||
Rules have the syntax:
|
||||
ルールの構文は以下のとおりです。
|
||||
|
||||
<pre>[ruleset] ::= (([comment] | [rule]) [newline]+)*
|
||||
[comment] ::= # {[any character]}
|
||||
@ -18,17 +18,17 @@ Rules have the syntax:
|
||||
[whitespace] ::= ([tab] | [space]) [[whitespace]]
|
||||
</pre>
|
||||
|
||||
There is one rule per line.
|
||||
1行に1つのルールがあります。
|
||||
|
||||
If there is a `.` (period) present before the \[replacement], then this is a terminating rule in which case the interpreter must halt execution.
|
||||
\[replacement] の前に`.` (ピリオド) がある場合、インタプリタが演算を停止する規則があります。
|
||||
|
||||
A ruleset consists of a sequence of rules, with optional comments.
|
||||
ルールセットは、任意のコメントを含む一連のルールで構成されます。
|
||||
|
||||
Rulesets
|
||||
ルールセット
|
||||
|
||||
Use the following tests on entries:
|
||||
以下のテストを入力に使用します。
|
||||
|
||||
**Ruleset 1:**
|
||||
**ルールセット1:**
|
||||
|
||||
<pre># This rules file is extracted from Wikipedia:
|
||||
# <code>http://en.wikipedia.org/wiki/Markov_Algorithm</code>
|
||||
@ -40,11 +40,11 @@ the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
</pre>
|
||||
|
||||
Sample text of `I bought a B of As from T S.` should generate the output `I bought a bag of apples from my brother.`
|
||||
`I bought a B of As from T S.` というサンプルテキストで、 `I bought a bag of apples from my brother.` が出力されます。
|
||||
|
||||
**Ruleset 2:**
|
||||
**ルールセット2:**
|
||||
|
||||
A test of the terminating rule
|
||||
停止規則のテスト
|
||||
|
||||
<pre># Slightly modified from the rules on Wikipedia
|
||||
A -> apple
|
||||
@ -55,11 +55,11 @@ the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
</pre>
|
||||
|
||||
Sample text of `I bought a B of As from T S.` should generate `I bought a bag of apples from T shop.`
|
||||
`I bought a B of As from T S.` というサンプルテキストで、 `I bought a bag of apples from T shop.` が出力されます。
|
||||
|
||||
**Ruleset 3:**
|
||||
**ルールセット3:**
|
||||
|
||||
This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped.
|
||||
これは正しい置換順序をテストします。特別な正規表現文字がエスケープされない場合、単純な正規表現ベースの置換ルーチンをトラップする場合があります。
|
||||
|
||||
<pre># BNF Syntax testing rules
|
||||
A -> apple
|
||||
@ -74,11 +74,11 @@ the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
</pre>
|
||||
|
||||
Sample text of `I bought a B of As W my Bgage from T S.` should generate `I bought a bag of apples with my money from T shop.`
|
||||
`I bought a B of As W my Bgage from T S.` というサンプルテキストで、 `I bought a bag of apples with my money from T shop.` が出力されます。
|
||||
|
||||
**Ruleset 4:**
|
||||
**ルールセット4:**
|
||||
|
||||
This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.)
|
||||
これはルールスキャンの正しい順序をテストし、誤った順序でスキャンする置換ルーチンをトラップする場合があります。 一般的な単項乗算エンジンを実装します。 (この実装では、入力式をアンダースコア内に置くことに注意してください。)
|
||||
|
||||
<pre>### Unary Multiplication Engine, for testing Markov Algorithm implementations
|
||||
### By Donal Fellows.
|
||||
@ -110,15 +110,15 @@ _1 -> 1
|
||||
_+_ ->
|
||||
</pre>
|
||||
|
||||
Sample text of `_1111*11111_` should generate the output `11111111111111111111`
|
||||
`_1111*11111_` というサンプルテキストで、`11111111111111111111` が出力されます。
|
||||
|
||||
**Ruleset 5:**
|
||||
**ルールセット5:**
|
||||
|
||||
A simple [Turing machine](http://en.wikipedia.org/wiki/Turing_machine "link: http://en.wikipedia.org/wiki/Turing_machine"), implementing a three-state [busy beaver](http://en.wikipedia.org/wiki/Busy_beaver "link: http://en.wikipedia.org/wiki/Busy_beaver").
|
||||
シンプルな [チューリングマシン](http://en.wikipedia.org/wiki/Turing_machine "link: http://en.wikipedia.org/wiki/Turing_machine")は、3-状態 [ビジービーバー](http://en.wikipedia.org/wiki/Busy_beaver "link: http://en.wikipedia.org/wiki/Busy_beaver")を実装します。
|
||||
|
||||
The tape consists of `0`s and `1`s, the states are `A`, `B`, `C` and `H` (for `H`alt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input.
|
||||
このテープは `0`と`1`からなり、状態は `A`、`B`、`C` および`H` (`H`altの場合) であり、先頭の位置は先頭文字の前に状態文字を書くことにより示されます。 マシンが操作する元のテープをすべて入力する必要あります。
|
||||
|
||||
Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets.
|
||||
マルコフアルゴリズムがチューリング完全であることを示すだけでなく、 最初の4つのルールセットでは見つからなかったC++実装のバグを検出することができました。
|
||||
|
||||
<pre># Turing machine: three-state busy beaver
|
||||
#
|
||||
@ -140,41 +140,41 @@ B1 -> 1B
|
||||
1C1 -> H11
|
||||
</pre>
|
||||
|
||||
This ruleset should turn `000000A000000` into `00011H1111000`
|
||||
このルールセットで `000000A000000` が `00011H1111000`に変更されます。
|
||||
|
||||
# --hints--
|
||||
|
||||
`markov` should be a function.
|
||||
`markov` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof markov === 'function');
|
||||
```
|
||||
|
||||
`markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` should return "I bought a bag of apples from my brother.".
|
||||
`markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")`は「I bought a bag of apples from my brother.」を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(markov(rules[0], tests[0]), outputs[0]);
|
||||
```
|
||||
|
||||
`markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` should return "I bought a bag of apples from T shop.".
|
||||
`markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` は「I bought a bag of apples from T shop.」を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(markov(rules[1], tests[1]), outputs[1]);
|
||||
```
|
||||
|
||||
`markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")` should return "I bought a bag of apples with my money from T shop.".
|
||||
`markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")` は「I bought a bag of apples with my money from T shop.」を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(markov(rules[2], tests[2]), outputs[2]);
|
||||
```
|
||||
|
||||
`markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")` should return "11111111111111111111".
|
||||
`markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")` は「11111111111111111111」を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(markov(rules[3], tests[3]), outputs[3]);
|
||||
```
|
||||
|
||||
`markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")` should return "00011H1111000".
|
||||
`markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")` は「00011H1111000」を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(markov(rules[4], tests[4]), outputs[4]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59e0a8df964e4540d5abe599
|
||||
title: Execute Brain****
|
||||
title: Brain****の実行
|
||||
challengeType: 5
|
||||
forumTopicId: 302261
|
||||
dashedName: execute-brain
|
||||
@ -8,54 +8,54 @@ dashedName: execute-brain
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to implement a Brain\*\*\*\* interpreter. The function will take a string as a parameter and should return a string as the output. More details are given below:
|
||||
Brain\*\*\*\*\* インタプリタを実行する関数を作成します。 関数はパラメータとして文字列を取り、出力文字列を返します。 詳細は以下の通りです。
|
||||
|
||||
RCBF is a set of [Brainf\*\*\*](https://rosettacode.org/wiki/Brainf*** "Brainf\*\*\*") compilers and interpreters written for Rosetta Code in a variety of languages.
|
||||
RCBFは ロゼッタコード用に様々な言語で書かれた[Brainf\*\*\*](https://rosettacode.org/wiki/Brainf*** "Brainf\*\*\*") コンパイラおよびインタプリタのセットです。
|
||||
|
||||
Below are links to each of the versions of RCBF.
|
||||
以下は、RCBFの各バージョンへのリンクです。
|
||||
|
||||
An implementation need only properly implement the following instructions:
|
||||
実装には以下の手順を適切に実行する必要があります。
|
||||
|
||||
| Command | Description |
|
||||
| ------------------------- | ------------------------------------------------------------------------------------------ |
|
||||
| <code>></code> | Move the pointer to the right |
|
||||
| <code><</code> | Move the pointer to the left |
|
||||
| <code>+</code> | Increment the memory cell under the pointer |
|
||||
| <code>-</code> | Decrement the memory cell under the pointer |
|
||||
| <code>.</code> | Output the character signified by the cell at the pointer |
|
||||
| <code>,</code> | Input a character and store it in the cell at the pointer |
|
||||
| <code>\[</code> | Jump past the matching <code>]</code> if the cell under the pointer is 0 |
|
||||
| <code>]</code> | Jump back to the matching <code>\[</code> if the cell under the pointer is nonzero |
|
||||
| コマンド | 説明 |
|
||||
| ------------------------- | ---------------------------------------------------------- |
|
||||
| <code>></code> | ポインタを右に移動します |
|
||||
| <code><</code> | ポインタを左に移動します |
|
||||
| <code>+</code> | ポインタの下にあるメモリーセルを増やします |
|
||||
| <code>-</code> | ポインタの下にあるメモリーセルを減らします |
|
||||
| <code>.</code> | ポインターのセルで示された文字を出力します |
|
||||
| <code>,</code> | 文字を入力し、ポインタのセルに格納します |
|
||||
| <code>\[</code> | ポインタの下のセルが 0 の場合、一致する <code>]</code> をジャンプします |
|
||||
| <code>]</code> | ポインタの下のセルがゼロでない場合、一致する <code>\[</code> にジャンプして戻ります |
|
||||
|
||||
Any cell size is allowed, EOF (*E*nd-*O*-*F*ile) support is optional, as is whether you have bounded or unbounded memory.
|
||||
セルのサイズに制限はありません。メモリに制限があるかどうかに関わらず、EOF (*E*nd-*O*-*F*ile) のサポートは任意です。
|
||||
|
||||
# --hints--
|
||||
|
||||
`brain(bye)` should return a string
|
||||
`brain(bye)` は文字列を返します。
|
||||
|
||||
```js
|
||||
assert(typeof brain(bye) === 'string');
|
||||
```
|
||||
|
||||
`brain("++++++[>++++++++++<-]>+++++.")` should return "A"
|
||||
`brain("++++++[>++++++++++<-]>+++++.")` は「A」を返します。
|
||||
|
||||
```js
|
||||
assert.equal(brain('++++++[>++++++++++<-]>+++++.'), 'A');
|
||||
```
|
||||
|
||||
`brain(bye)` should return `Goodbye, World!\r\n`
|
||||
`brain(bye)` は `Goodbye, World!\r\n` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(brain(bye), 'Goodbye, World!\r\n');
|
||||
```
|
||||
|
||||
`brain(hello)` should return `Hello World!\n`
|
||||
`brain(hello)` は `Hello World!\n` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(brain(hello), 'Hello World!\n');
|
||||
```
|
||||
|
||||
`brain(fib)` should return `1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89`
|
||||
`brain(fib)` は `1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(brain(fib), '1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89');
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 598ee8b91b410510ae82efef
|
||||
title: Extensible prime generator
|
||||
title: 拡張可能な素数ジェネレータ
|
||||
challengeType: 5
|
||||
forumTopicId: 302262
|
||||
dashedName: extensible-prime-generator
|
||||
@ -8,28 +8,28 @@ dashedName: extensible-prime-generator
|
||||
|
||||
# --description--
|
||||
|
||||
Write a generator of prime numbers, in order, that will automatically adjust to accommodate the generation of any reasonably high prime.
|
||||
かなり高い素数の生成に対応するために自動的に調整する素数ジェネレータを作成します。
|
||||
|
||||
The generator should be able to:
|
||||
ジェネレータで次のことが可能です。
|
||||
|
||||
<ul>
|
||||
<li>Show the first <code>n</code> prime numbers</li>
|
||||
<li>Show the prime numbers in a range</li>
|
||||
<li>Show the number of primes in a range</li>
|
||||
<li>Show the <code>n<sup>th</sup></code> prime number</li>
|
||||
<li>最初の <code>n</code> 個の素数を表示する</li>
|
||||
<li>範囲内に素数を表示する</li>
|
||||
<li>範囲内の素数の数を表示する</li>
|
||||
<li><code>n<sup>th</sup></code> の素数を表示する</li>
|
||||
</ul>
|
||||
|
||||
The function should have two parameters. The first will receive `n` or the range as an array. The second will receive a boolean, that specifies if the function returns the prime numbers as an array or a single number(the number of primes in the range or the <code>n<sup>th</sup></code> prime). According to the parameters the function should return an array.
|
||||
関数は二つのパラメーターを使用します。 1つ目は、`n`、つまり配列としての範囲です。 2 つ目は、ブール値です。 ブール値は、関数が素数を配列として返すか、単一の数値 として返すかを指定します (範囲内の素数、または <code>n<sup>th</sup></code> 素数)。 パラメーターに基づき、関数は配列を返します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`primeGenerator` should be a function.
|
||||
`primeGenerator` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof primeGenerator === 'function');
|
||||
```
|
||||
|
||||
`primeGenerator(20, true)` should return `[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]`.
|
||||
`primeGenerator(20, true)` は `[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(primeGenerator(20, true), [
|
||||
@ -56,7 +56,7 @@ assert.deepEqual(primeGenerator(20, true), [
|
||||
]);
|
||||
```
|
||||
|
||||
`primeGenerator([100, 150], true)` should return `[101, 103, 107, 109, 113, 127, 131, 137, 139, 149]`.
|
||||
`primeGenerator([100, 150], true)` は `[101, 103, 107, 109, 113, 127, 131, 137, 139, 149]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(primeGenerator([100, 150], true), [
|
||||
@ -73,13 +73,13 @@ assert.deepEqual(primeGenerator([100, 150], true), [
|
||||
]);
|
||||
```
|
||||
|
||||
`primeGenerator([7700, 8000], false)` should return `30`.
|
||||
`primeGenerator([7700, 8000], false)` は `30` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(primeGenerator([7700, 8000], false), 30);
|
||||
```
|
||||
|
||||
`primeGenerator(10000, false)` should return `104729`.
|
||||
`primeGenerator(10000, false)` は `104729` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(primeGenerator(10000, false), 104729);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 597b2b2a2702b44414742771
|
||||
title: Factorial
|
||||
title: 階乗
|
||||
challengeType: 5
|
||||
forumTopicId: 302263
|
||||
dashedName: factorial
|
||||
@ -8,49 +8,49 @@ dashedName: factorial
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to return the factorial of a number.
|
||||
数字の階乗を返す関数を作成します。
|
||||
|
||||
Factorial of a number is given by:
|
||||
数値の階乗は次のようになります。
|
||||
|
||||
<pre><big>n! = n * (n-1) * (n-2) * ..... * 1</big>
|
||||
</pre>
|
||||
|
||||
For example:
|
||||
例:
|
||||
|
||||
<ul>
|
||||
<li><code>3! = 3 * 2 * 1 = 6</code></li>
|
||||
<li><code>4! = 4 * 3 * 2 * 1 = 24</code></li>
|
||||
</ul>
|
||||
|
||||
**Note:** `0! = 1`
|
||||
**注記:** `0! = 1`
|
||||
|
||||
# --hints--
|
||||
|
||||
`factorial` should be a function.
|
||||
`factorial` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof factorial === 'function');
|
||||
```
|
||||
|
||||
`factorial(2)` should return a number.
|
||||
`factorial(2)` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof factorial(2) === 'number');
|
||||
```
|
||||
|
||||
`factorial(3)` should return 6.
|
||||
`factorial(3)` は6を返します。
|
||||
|
||||
```js
|
||||
assert.equal(factorial(3), 6);
|
||||
```
|
||||
|
||||
`factorial(5)` should return 120.
|
||||
`factorial(5)` は120を返します。
|
||||
|
||||
```js
|
||||
assert.equal(factorial(5), 120);
|
||||
```
|
||||
|
||||
`factorial(10)` should return 3,628,800.
|
||||
`factorial(10)` は3,628,800を返します。
|
||||
|
||||
```js
|
||||
assert.equal(factorial(10), 3628800);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 598eea87e5cf4b116c3ff81a
|
||||
title: Factors of a Mersenne number
|
||||
title: メルセンヌ数の因数
|
||||
challengeType: 5
|
||||
forumTopicId: 302264
|
||||
dashedName: factors-of-a-mersenne-number
|
||||
@ -8,25 +8,25 @@ dashedName: factors-of-a-mersenne-number
|
||||
|
||||
# --description--
|
||||
|
||||
A Mersenne number is a number in the form of <code>2<sup>P</sup>-1</code>.
|
||||
メルセンヌ数は <code>2<sup>P</sup>-1</code> の形式の数値です。
|
||||
|
||||
If `P` is prime, the Mersenne number may be a Mersenne prime. (If `P` is not prime, the Mersenne number is also not prime.)
|
||||
`P` が素数の場合、メルセンヌ数はメルセンヌの素数である場合があります。 ( `P` が素数でない場合、メルセンヌ数も素数ではありません。)
|
||||
|
||||
In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, [Lucas-Lehmer test](https://rosettacode.org/wiki/Lucas-Lehmer test "Lucas-Lehmer test").
|
||||
メルセンヌ素数を求めるには、長い時間を要する可能性がある [Lucas-Lehmer test](https://rosettacode.org/wiki/Lucas-Lehmer test "Lucas-Lehmer test") を開始する前に、小さな因数を見つけることによって指数を除去することをお勧めします。
|
||||
|
||||
There are very efficient algorithms for determining if a number divides <code>2<sup>P</sup>-1</code> (or equivalently, if <code>2<sup>P</sup> mod (the number) = 1</code>).
|
||||
数字が <code>2<sup>P</sup>-1</code> を割るかどうか (すなわち、<code>2<sup>P</sup> mod (the number) = 1</code> となるかどうか) を判定するのに適した非常に効率的なアルゴリズムがあります。
|
||||
|
||||
Some languages already have built-in implementations of this exponent-and-mod operation (called modPow or similar).
|
||||
指数と剰余演算 (modPow などと呼ばれる) の組み込み実装が既にある言語もあります。
|
||||
|
||||
The following is how to implement this modPow yourself:
|
||||
以下は、このmodPowを自分で実装する方法です。
|
||||
|
||||
For example, let's compute <code>2<sup>23</sup> mod 47</code>.
|
||||
例えば、 <code>2<sup>23</sup> mod 47</code> を計算してみましょう。
|
||||
|
||||
Convert the exponent 23 to binary, you get 10111. Starting with <code><tt>square</tt> = 1</code>, repeatedly square it.
|
||||
指数23を2進数に変換すると、10111が得られます。 <code><tt>square</tt> = 1</code> から始めて、繰り返し2乗にしていきます。
|
||||
|
||||
Remove the top bit of the exponent, and if it's 1 multiply `square` by the base of the exponentiation (2), then compute <code><tt>square</tt> modulo 47</code>.
|
||||
指数の上位ビットを削除し、1である場合、`square` に冪乗の底 (2) を掛けて、<code><tt>square</tt> modulo 47</code>を計算します。
|
||||
|
||||
Use the result of the modulo from the last step as the initial value of `square` in the next step:
|
||||
最後のステップのモジュロの結果を、次のステップの `square` の初期値として使用します。
|
||||
|
||||
<pre>Remove Optional
|
||||
square top bit multiply by 2 mod 47
|
||||
@ -38,51 +38,51 @@ square top bit multiply by 2 mod 47
|
||||
27*27 = 729 1 729*2 = 1458 1
|
||||
</pre>
|
||||
|
||||
Since <code>2<sup>23</sup> mod 47 = 1</code>, 47 is a factor of <code>2<sup>P</sup>-1</code>.
|
||||
<code>2<sup>23</sup> mod 47 = 1</code>であるため、 47 は <code>2<sup>P</sup>-1</code> の因数です。
|
||||
|
||||
(To see this, subtract 1 from both sides: <code>2<sup>23</sup>-1 = 0 mod 47</code>.)
|
||||
(これを理解するには、両辺から1を引きます: <code>2<sup>23</sup>-1 = 0 mod 47</code>。)
|
||||
|
||||
Since we've shown that 47 is a factor, <code>2<sup>23</sup>-1</code> is not prime.
|
||||
47 が因数であるとしているので、<code>2<sup>23</sup>-1</code> は素数ではありません。
|
||||
|
||||
Further properties of Mersenne numbers allow us to refine the process even more.
|
||||
メルセンヌ数には他にも特有の性質があるため、メルセンヌ数を使用するとプロセスをもっと改善できます。
|
||||
|
||||
Any factor `q` of <code>2<sup>P</sup>-1</code> must be of the form `2kP+1`, `k` being a positive integer or zero. Furthermore, `q` must be `1` or `7 mod 8`.
|
||||
<code>2<sup>P</sup>-1</code> の因数 `q` は `2kP+1`の形を取り、`k` は正の整数またはゼロです。 さらに、`q` は `1` または `7 mod 8` です。
|
||||
|
||||
Finally any potential factor `q` must be [prime](https://rosettacode.org/wiki/Primality by Trial Division "Primality by Trial Division").
|
||||
最後に、潜在的因数 `q` は [素数](https://rosettacode.org/wiki/Primality by Trial Division "Primality by Trial Division") でなければなりません。
|
||||
|
||||
As in other trial division algorithms, the algorithm stops when `2kP+1 > sqrt(N)`.These primarily tests only work on Mersenne numbers where `P` is prime. For example, <code>M<sub>4</sub>=15</code> yields no factors using these techniques, but factors into 3 and 5, neither of which fit `2kP+1`.
|
||||
他の試行徐算アルゴリズムと同様に、アルゴリズムは `2kP+1 > sqrt(N)`となった場合に停止します。これらのテストは、`P` が素数である場合に、メルセンヌ数に対してのみ働きます。 例えば、<code>M<sub>4</sub>=15</code> はこれらの手法で因数を生成しません。3と5を考えると、いずれも`2kP+1`に適合しません。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Using the above method find a factor of <code>2<sup>p</sup>-1</code>.
|
||||
上記のメソッドを使用して、<code>2<sup>p</sup>-1</code> の因数を求めます。
|
||||
|
||||
# --hints--
|
||||
|
||||
`check_mersenne` should be a function.
|
||||
`check_mersenne` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof check_mersenne === 'function');
|
||||
```
|
||||
|
||||
`check_mersenne(3)` should return a string.
|
||||
`check_mersenne(3)` は文字列を返します。
|
||||
|
||||
```js
|
||||
assert(typeof check_mersenne(3) == 'string');
|
||||
```
|
||||
|
||||
`check_mersenne(3)` should return the string `M3 = 2^3-1 is prime`.
|
||||
`check_mersenne(3)` は文字列 `M3 = 2^3-1 is prime` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(check_mersenne(3), 'M3 = 2^3-1 is prime');
|
||||
```
|
||||
|
||||
`check_mersenne(23)` should return the string `M23 = 2^23-1 is composite with factor 47`.
|
||||
`check_mersenne(23)` は文字列 `M23 = 2^23-1 is composite with factor 47` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(check_mersenne(23), 'M23 = 2^23-1 is composite with factor 47');
|
||||
```
|
||||
|
||||
`check_mersenne(929)` should return the string `M929 = 2^929-1 is composite with factor 13007`.
|
||||
`check_mersenne(929)` は 文字列 `M929 = 2^929-1 is composite with factor 13007` を返します。
|
||||
|
||||
```js
|
||||
assert.equal(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 597f1e7fbc206f0e9ba95dc4
|
||||
title: Factors of an integer
|
||||
title: 整数の因数
|
||||
challengeType: 5
|
||||
forumTopicId: 302265
|
||||
dashedName: factors-of-an-integer
|
||||
@ -8,31 +8,31 @@ dashedName: factors-of-an-integer
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function that returns the factors of a positive integer as an array.
|
||||
正の整数の因数を配列として返す関数を作成します。
|
||||
|
||||
These factors are the positive integers by which the number being factored can be divided to yield a positive integer result.
|
||||
これらの因数は正の整数であり、因数分解される数値を除算して、正の整数の結果を得ることができます。
|
||||
|
||||
# --hints--
|
||||
|
||||
`factors` should be a function.
|
||||
`factors` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof factors === 'function');
|
||||
```
|
||||
|
||||
`factors(45)` should return `[1,3,5,9,15,45]`.
|
||||
`factors(45)` は `[1,3,5,9,15,45]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(factors(45), ans[0]);
|
||||
```
|
||||
|
||||
`factors(53)` should return `[1,53]`.
|
||||
`factors(53)` は `[1,53]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(factors(53), ans[1]);
|
||||
```
|
||||
|
||||
`factors(64)` should return `[1,2,4,8,16,32,64]`.
|
||||
`factors(64)` は `[1,2,4,8,16,32,64]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(factors(64), ans[2]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 59c3ec9f15068017c96eb8a3
|
||||
title: Farey sequence
|
||||
title: ファレイ数列
|
||||
challengeType: 5
|
||||
forumTopicId: 302266
|
||||
dashedName: farey-sequence
|
||||
@ -8,18 +8,18 @@ dashedName: farey-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
The [Farey sequence](https://en.wikipedia.org/wiki/Farey sequence "wp: Farey sequence") <code>F<sub>n</sub></code> of order `n` is the sequence of completely reduced fractions between `0` and `1` which, when in lowest terms, have denominators less than or equal to `n`, arranged in order of increasing size.
|
||||
位数 `n` の [ファレイ数列](https://en.wikipedia.org/wiki/Farey sequence "wp: Farey sequence") <code>F<sub>n</sub></code> は、`0` から `1` の間の既約分数の数列であり、`n` 以下の分母を持ち、昇順に並べられます。
|
||||
|
||||
The *Farey sequence* is sometimes incorrectly called a *Farey series*.
|
||||
*ファレイ数列* は、 間違って *ファレイseries* と呼ばれることがあります。
|
||||
|
||||
Each Farey sequence:
|
||||
各ファレイ数列:
|
||||
|
||||
<ul>
|
||||
<li>starts with the value 0, denoted by the fraction $ \frac{0}{1} $</li>
|
||||
<li>ends with the value 1, denoted by the fraction $ \frac{1}{1}$.</li>
|
||||
<li>値は 0 から始まり、分数 $ \frac{0}{1}$ で表されます。</li>
|
||||
<li>値は 1 で終わり、分数 $ \frac{1}{1}$ で表されます。</li>
|
||||
</ul>
|
||||
|
||||
The Farey sequences of orders `1` to `5` are:
|
||||
`1` から `5` のファレイ数列は以下のとおりです。
|
||||
|
||||
<ul>
|
||||
<li style='list-style: none;'>${\bf\it{F}}_1 = \frac{0}{1}, \frac{1}{1}$</li>
|
||||
@ -31,35 +31,35 @@ The Farey sequences of orders `1` to `5` are:
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function that returns the Farey sequence of order `n`. The function should have one parameter that is `n`. It should return the sequence as an array.
|
||||
位数 `n` のファレイ数列を返す関数を作成します。 関数にはパラメータ `n` が必要です。 関数は数列を配列として返します。
|
||||
|
||||
# --hints--
|
||||
|
||||
`farey` should be a function.
|
||||
`farey` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof farey === 'function');
|
||||
```
|
||||
|
||||
`farey(3)` should return an array
|
||||
`farey(3)` は配列を返します。
|
||||
|
||||
```js
|
||||
assert(Array.isArray(farey(3)));
|
||||
```
|
||||
|
||||
`farey(3)` should return `["1/3","1/2","2/3"]`
|
||||
`farey(3)` は `["1/3","1/2","2/3"]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(farey(3), ['1/3', '1/2', '2/3']);
|
||||
```
|
||||
|
||||
`farey(4)` should return `["1/4","1/3","1/2","2/4","2/3","3/4"]`
|
||||
`farey(4)` は `["1/4","1/3","1/2","2/4","2/3","3/4"]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(farey(4), ['1/4', '1/3', '1/2', '2/4', '2/3', '3/4']);
|
||||
```
|
||||
|
||||
`farey(5)` should return `["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]`
|
||||
`farey(5)` は `["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(farey(5), [
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 598eef80ba501f1268170e1e
|
||||
title: Fibonacci n-step number sequences
|
||||
title: フィボナッチ n-ステップ 数列
|
||||
challengeType: 5
|
||||
forumTopicId: 302267
|
||||
dashedName: fibonacci-n-step-number-sequences
|
||||
@ -8,82 +8,82 @@ dashedName: fibonacci-n-step-number-sequences
|
||||
|
||||
# --description--
|
||||
|
||||
These number series are an expansion of the ordinary [Fibonacci sequence](https://rosettacode.org/wiki/Fibonacci sequence "Fibonacci sequence") where:
|
||||
これらは、通常の[フィボナッチ数列](https://rosettacode.org/wiki/Fibonacci sequence "Fibonacci sequence") を応用したものです。
|
||||
|
||||
<ol>
|
||||
<li>For $n = 2$ we have the Fibonacci sequence; with initial values $[1, 1]$ and $F_k^2 = F_{k-1}^2 + F_{k-2}^2$</li>
|
||||
<li>For $n = 3$ we have the tribonacci sequence; with initial values $[1, 1, 2]$ and $F_k^3 = F_{k-1}^3 + F_{k-2}^3 + F_{k-3}^3$</li>
|
||||
<li>For $n = 4$ we have the tetranacci sequence; with initial values $[1, 1, 2, 4]$ and $F_k^4 = F_{k-1}^4 + F_{k-2}^4 + F_{k-3}^4 + F_{k-4}^4$...</li>
|
||||
<li>For general $n>2$ we have the Fibonacci $n$-step sequence - $F_k^n$; with initial values of the first $n$ values of the $(n-1)$'th Fibonacci $n$-step sequence $F_k^{n-1}$; and $k$'th value of this $n$'th sequence being $F_k^n = \sum_{i=1}^{(n)} {F_{k-i}^{(n)}}$</li>
|
||||
<li>$n = 2$ の場合、初期値が$[1, 1]$ と $F_k^2 = F_{k-1}^2 + F_{k-2}^2$ であるフィボナッチ数列となります。</li>
|
||||
<li>$n = 3$の場合、初期値が $[1, 1, 2]$ と $F_k^3 = F_{k-1}^3 + F_{k-2}^3 + F_{k-3}^3$ であるトリボナッチ数列となります。</li>
|
||||
<li>$n = 4$の場合、初期値が $[1, 1, 2, 4]$ と $F_k^4 = F_{k-1}^4 + F_{k-2}^4 + F_{k-3}^4 + F_{k-4}^4$...であるテトラナッチ数列となります。</li>
|
||||
<li>通常の $n>2$ の場合は、フィボナッチ $n$-ステップ数列 - $F_k^n$となります。初期値は、$(n-1)$'th フィボナッチ $n$-ステップ数列 $F_k^{n-1}$ の最初の $n$ 値で、$n$ 番目の数列の $k$' 番目の値は、$F_k^n = \sum_{i=1}^{(n)} {F_{k-i}^{(n)}}$です。</li>
|
||||
</ol>
|
||||
|
||||
For small values of $n$, [Greek numeric prefixes](https://en.wikipedia.org/wiki/Number prefix#Greek_series "wp: Number prefix#Greek_series") are sometimes used to individually name each series.
|
||||
$n$ が小さい値の場合、[ギリシャ語の数を表す接頭辞](https://en.wikipedia.org/wiki/Number prefix#Greek_series "wp: Number prefix#Greek_series") が各列の名前を付けるのに使用されることがあります。
|
||||
|
||||
Fibonacci $n$-step sequences:
|
||||
フィボナッチ $n$-ステップ 数列:
|
||||
|
||||
| $n$ | Series name | Values |
|
||||
| --- | ----------- | ------------------------------------------------------ |
|
||||
| 2 | fibonacci | 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ... |
|
||||
| 3 | tribonacci | 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ... |
|
||||
| 4 | tetranacci | 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ... |
|
||||
| 5 | pentanacci | 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ... |
|
||||
| 6 | hexanacci | 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ... |
|
||||
| 7 | heptanacci | 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ... |
|
||||
| 8 | octonacci | 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ... |
|
||||
| 9 | nonanacci | 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ... |
|
||||
| 10 | decanacci | 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ... |
|
||||
| $n$ | 数列名 | 値 |
|
||||
| --- | ------ | ------------------------------------------------------ |
|
||||
| 2 | フィボナッチ | 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ... |
|
||||
| 3 | トリボナッチ | 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 ... |
|
||||
| 4 | テトラナッチ | 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536 ... |
|
||||
| 5 | ペンタナッチ | 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930 ... |
|
||||
| 6 | ヘキサナッチ | 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617 ... |
|
||||
| 7 | ヘプタナッチ | 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936 ... |
|
||||
| 8 | オクタナッチ | 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080 ... |
|
||||
| 9 | ノナナッチ | 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144 ... |
|
||||
| 10 | デカナッチ | 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172 ... |
|
||||
|
||||
Allied sequences can be generated where the initial values are changed: The [Lucas series](https://en.wikipedia.org/wiki/Lucas number "wp: Lucas number") sums the two preceding values like the fibonacci series for $n=2$ but uses $\[2, 1]$ as its initial values.
|
||||
類似の数列は、初期値が変更された場合に生成されます。[ルーカスシリーズ](https://en.wikipedia.org/wiki/Lucas number "wp: Lucas number") は $n=2$ のフィボナッチシリーズのように先行する2つの値を合計しますが、$\[2, 1]$ を初期値として使用します。
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to generate Fibonacci $n$-step number sequences and Lucas sequences. The first parameter will be $n$. The second parameter will be the number of elements to be returned. The third parameter will specify whether to output the Fibonacci sequence or the Lucas sequence. If the parameter is `"f"` then return the Fibonacci sequence and if it is `"l"`, then return the Lucas sequence. The sequences must be returned as an array.
|
||||
フィボナッチ $n$-ステップ 数列とルーカス数列を生成する関数を作成します。 最初のパラメータは $n$ です。 2 番目のパラメータは、返される要素の数です。 3つ目のパラメータはフィボナッチ数列とルーカス数列のどちらを出力するかを指定します。 パラメータが `"f"` の場合、フィボナッチ数列を返し、`"l"`の場合、ルーカス数列を返します。 数列は配列として返される必要があります。
|
||||
|
||||
# --hints--
|
||||
|
||||
`fib_luc` should be a function.
|
||||
`fib_luc` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof fib_luc === 'function');
|
||||
```
|
||||
|
||||
`fib_luc(2,10,"f")` should return `[1,1,2,3,5,8,13,21,34,55]`.
|
||||
`fib_luc(2,10,"f")` は `[1,1,2,3,5,8,13,21,34,55]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(2, 10, 'f'), ans[0]);
|
||||
```
|
||||
|
||||
`fib_luc(3,15,"f")` should return `[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]`.
|
||||
`fib_luc(3,15,"f")` は `[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(3, 15, 'f'), ans[1]);
|
||||
```
|
||||
|
||||
`fib_luc(4,15,"f")` should return `[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]`.
|
||||
`fib_luc(4,15,"f")`は `[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(4, 15, 'f'), ans[2]);
|
||||
```
|
||||
|
||||
`fib_luc(2,10,"l")` should return `[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]`.
|
||||
`fib_luc(2,10,"l")` は `[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(2, 10, 'l'), ans[3]);
|
||||
```
|
||||
|
||||
`fib_luc(3,15,"l")` should return `[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]`.
|
||||
`fib_luc(3,15,"l")` は `[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(3, 15, 'l'), ans[4]);
|
||||
```
|
||||
|
||||
`fib_luc(4,15,"l")` should return `[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]`.
|
||||
`fib_luc(4,15,"l")` は `[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(4, 15, 'l'), ans[5]);
|
||||
```
|
||||
|
||||
`fib_luc(5,15,"l")` should return `[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]`.
|
||||
`fib_luc(5,15,"l")` は `[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fib_luc(5, 15, 'l'), ans[6]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 597f24c1dda4e70f53c79c81
|
||||
title: Fibonacci sequence
|
||||
title: フィボナッチ数列
|
||||
challengeType: 5
|
||||
forumTopicId: 302268
|
||||
dashedName: fibonacci-sequence
|
||||
@ -8,43 +8,43 @@ dashedName: fibonacci-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
Write a function to generate the <code>n<sup>th</sup></code> Fibonacci number.
|
||||
<code>n<sup>th</sup></code> フィボナッチ数を生成する関数を作成します。
|
||||
|
||||
The <code>n<sup>th</sup></code> Fibonacci number is given by:
|
||||
<code>n<sup>th</sup></code> フィボナッチ数は以下にように計算されます。
|
||||
|
||||
<code>F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub></code>
|
||||
|
||||
The first two terms of the series are 0 and 1.
|
||||
級数の最初の2つの項は0と1です。
|
||||
|
||||
Hence, the series is: 0, 1, 1, 2, 3, 5, 8, 13...
|
||||
したがって、級数は0、1、1、2、3、5、8、13です。
|
||||
|
||||
# --hints--
|
||||
|
||||
`fibonacci` should be a function.
|
||||
`fibonacci` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof fibonacci === 'function');
|
||||
```
|
||||
|
||||
`fibonacci(2)` should return a number.
|
||||
`fibonacci(2)` は数字を返します。
|
||||
|
||||
```js
|
||||
assert(typeof fibonacci(2) == 'number');
|
||||
```
|
||||
|
||||
`fibonacci(3)` should return 2.
|
||||
`fibonacci(3)` は2を返します。
|
||||
|
||||
```js
|
||||
assert.equal(fibonacci(3), 2);
|
||||
```
|
||||
|
||||
`fibonacci(5)` should return 5.
|
||||
`fibonacci(5)` は5を返します。
|
||||
|
||||
```js
|
||||
assert.equal(fibonacci(5), 5);
|
||||
```
|
||||
|
||||
`fibonacci(10)` should return 55.
|
||||
`fibonacci(10)` は55を返します。
|
||||
|
||||
```js
|
||||
assert.equal(fibonacci(10), 55);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5992e222d397f00d21122931
|
||||
title: Fibonacci word
|
||||
title: フィボナッチ列
|
||||
challengeType: 5
|
||||
forumTopicId: 302269
|
||||
dashedName: fibonacci-word
|
||||
@ -8,33 +8,33 @@ dashedName: fibonacci-word
|
||||
|
||||
# --description--
|
||||
|
||||
The Fibonacci Word may be created in a manner analogous to the Fibonacci Sequence [as described here](https://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf):
|
||||
[文書で説明されているように](https://hal.archives-ouvertes.fr/docs/00/36/79/72/PDF/The_Fibonacci_word_fractal.pdf)、フィボナッチ列は、フィボナッチ数列と類似した方法で作成されます。
|
||||
|
||||
<pre>Define F_Word<sub>1</sub> as <strong>1</strong>
|
||||
Define F_Word<sub>2</sub> as <strong>0</strong>
|
||||
Form F_Word<sub>3</sub> as F_Word<sub>2</sub> concatenated with F_Word<sub>1</sub> i.e.: <strong>01</strong>
|
||||
Form F_Word<sub>n</sub> as F_Word<sub>n-1</sub> concatenated with F_word<sub>n-2</sub>
|
||||
<pre>F_Word<sub>1</sub> を <strong>1</strong> と定義します
|
||||
F_Word<sub>2</sub> を <strong>0</strong> と定義します
|
||||
F_Word<sub>3</sub> を F_Word <sub>1</sub> と結びついた F_Word<sub>2</sub> として作成します 例: <strong>01</strong>
|
||||
F_Word<sub>n</sub> を F_word <sub>n-2</sub> と結びついた F_Word<sub>n-1</sub> として作成します
|
||||
</pre>
|
||||
|
||||
# --instructions--
|
||||
|
||||
Write a function to return the Fibonacci Words up to `n`. `n` will be provided as a parameter to the function. The function should return an array of objects. The objects should be of the form: `{ N: 1, Length: 1, Entropy: 0, Word: '1' }`.
|
||||
`n` までのフィボナッチ列を返す関数を作成します。 関数のパラメータとして `n` が与えられます。 この関数はオブジェクトの配列を返します。 オブジェクトは `{ N: 1, Length: 1, Entropy: 0, Word: '1' }` の形式である必要があります。
|
||||
|
||||
# --hints--
|
||||
|
||||
`fibWord` should be a function.
|
||||
`fibWord` という関数です。
|
||||
|
||||
```js
|
||||
assert(typeof fibWord === 'function');
|
||||
```
|
||||
|
||||
`fibWord(5)` should return an array.
|
||||
`fibWord(5)` は配列を返します。
|
||||
|
||||
```js
|
||||
assert(Array.isArray(fibWord(5)));
|
||||
```
|
||||
|
||||
`fibWord(5)` should return `[{ N:1, Length:1, Entropy:0, Word:"1" },{ N:2, Length:1, Entropy:0, Word:"0" },{ N:3, Length:2, Entropy:1, Word:"01" },{ N:4, Length:3, Entropy:0.9182958340544896, Word:"010" },{ N:5, Length:5, Entropy:0.9709505944546688, Word:"01001" }]`.
|
||||
`fibWord(5)` は `[{ N:1, Length:1, Entropy:0, Word:"1" },{ N:2, Length:1, Entropy:0, Word:"0" },{ N:3, Length:2, Entropy:1, Word:"01" },{ N:4, Length:3, Entropy:0.9182958340544896, Word:"010" },{ N:5, Length:5, Entropy:0.9709505944546688, Word:"01001" }]` を返します。
|
||||
|
||||
```js
|
||||
assert.deepEqual(fibWord(5), ans);
|
||||
|
Reference in New Issue
Block a user