Skip to content

Commit 2ffaaa4

Browse files
committed
Merge branch 'update-advanced-article' of github.com:chvmvd/sikepuri-algorithm.github.io into update-advanced-article
2 parents 21545ee + bd4c49e commit 2ffaaa4

File tree

5 files changed

+63
-23
lines changed

5 files changed

+63
-23
lines changed

docs/01python/08if/index.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 8
33
---
44

55
import ViewSource from "@site/src/components/ViewSource";
6+
import Hint from "@site/src/components/Hint";
67
import Answer from "@site/src/components/Answer";
78

89
# 条件分岐
@@ -143,6 +144,20 @@ else:
143144

144145
絶対値を求めるプログラムを作ってみましょう。
145146

147+
<Hint>
148+
149+
次の式を思い起こせば、作れそうです。
150+
151+
$$
152+
|x|=
153+
\begin{dcases}
154+
x & \text{if $x\geq 0$,} \\
155+
-x & \text{else.}
156+
\end{dcases}
157+
$$
158+
159+
</Hint>
160+
146161
<Answer>
147162
<ViewSource path="/if/abs.ipynb" />
148163

docs/01python/10array/index.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 10
33
---
44

55
import ViewSource from "@site/src/components/ViewSource";
6+
import Hint from "@site/src/components/Hint";
67
import Answer from "@site/src/components/Answer";
78

89
# 配列
@@ -92,6 +93,16 @@ len(配列名)
9293
生徒の英語の点数が書かれた配列を受け取って、その平均点を返す関数を作ってみましょう。
9394
実際に、点数をそれぞれ 26 点、78 点、83 点、20 点、10 点、11 点、22 点、16 点、41 点、95 点として計算してみましょう。
9495

96+
<Hint>
97+
98+
$n$ 個のデータを $x_1,x_2,\dots,x_n$、平均点を $\bar{x}$ とすると、次のようにして求められるのでした。
99+
100+
$$
101+
\bar{x}=\frac{x_1+x_2+\dots +x_n}{n}=\frac{\sum_{i=1}^n x_i}{n}
102+
$$
103+
104+
</Hint>
105+
95106
<Answer>
96107
<ViewSource path="/array/average4.ipynb" />
97108

@@ -106,7 +117,7 @@ len(配列名)
106117

107118
今度は、分散を求めるプログラムを書いてみましょう。
108119

109-
$n$ 個の観測データを $x_1,x_2,\cdots,x_n$、平均を $\bar{x}$ とすると、分散 $s^2$ は次のように与えられるとします。
120+
$n$ 個のデータを $x_1,x_2,\dots,x_n$、平均を $\bar{x}$ とすると、分散 $s^2$ は次のように与えられるとします。
110121

111122
$$
112123
s^2=\frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n}

docs/01python/11multi-array/index.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 11
33
---
44

55
import ViewSource from "@site/src/components/ViewSource";
6+
import Hint from "@site/src/components/Hint";
67
import Answer from "@site/src/components/Answer";
78

89
# 多次元配列
@@ -57,6 +58,12 @@ A、B、C の 3 人の生徒がいて、それぞれの国語、数学、英語
5758
| **B** | 73 | 53 | 84 |
5859
| **C** | 63 | 48 | 64 |
5960

61+
<Hint>
62+
63+
まずそれぞれの生徒の得点の合計を求める関数を作ってから、その最高点を求める関数を作ると良いでしょう。
64+
65+
</Hint>
66+
6067
<Answer>
6168
<ViewSource path="/multi-array/total_score_max.ipynb" />
6269
</Answer>

docs/01python/12practice/index.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,35 @@ $n$ 番目まで Fizz Buzz での正しい解を表示するプログラムを
7474

7575
最大公約数を求めるプログラムを作ってみましょう。最大公約数(greatest common divisor)は、GCD とよく略されます。
7676

77+
<Hint>
78+
79+
ユークリッドの互除法を用いれば簡単にできます。
80+
81+
ユークリッドの互除法を用いると、次のように最大公約数が計算できるのでした。
82+
$\mathrm{gcd}(a, b)$ を $a$ と $b$ の最大公約数とします。
83+
84+
例:$30$ と $18$ の最大公約数を求める。
85+
86+
$$
87+
\begin{align*}
88+
\mathrm{gcd}(30, 18) &= \mathrm{gcd}(18, 30 - 18\times 1) \\
89+
&= \mathrm{gcd}(18, 12) \\
90+
&= \mathrm{gcd}(12, 18 - 12\times 1) \\
91+
&= \mathrm{gcd}(12, 6) \\
92+
&= \mathrm{gcd}(6, 12 - 6\times 2) \\
93+
&= \mathrm{gcd}(6, 0) \\
94+
&= 6
95+
\end{align*}
96+
$$
97+
98+
よって、最大公約数は $6$
99+
100+
</Hint>
101+
77102
<Answer>
78103

104+
ユークリッドの互除法を使うと、最大公約数を求めるプログラムは次のようになります。
105+
79106
<ViewSource path="/practice/gcd.ipynb" />
80107

81108
`a, b = b, a` は、次と同じ意味です。
@@ -86,7 +113,7 @@ a = b
86113
b = tmp
87114
```
88115

89-
再帰を使うと次のようにもできます。再帰は後の項で説明します
116+
再帰を使うと次のようにもできます。再帰を使ったプログラムは、後の項で紹介します
90117

91118
<ViewSource path="/practice/gcd_recursive.ipynb" />
92119

docs/04algorithms/02recursion/index.mdx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,33 +214,13 @@ $$
214214

215215
<Answer>
216216

217-
ユークリッドの互除法を用いれば簡単にできます。$\mathrm{gcd}(a, b)$ を $a$ と $b$ の最大公約数とします。
218-
219-
例:$30$ と $18$ の最大公約数を求める。
220-
221-
$$
222-
\begin{align*}
223-
\mathrm{gcd}(30, 18) &= \mathrm{gcd}(18, 30 - 18\times 1) \\
224-
&= \mathrm{gcd}(18, 12) \\
225-
&= \mathrm{gcd}(12, 18 - 12\times 1) \\
226-
&= \mathrm{gcd}(12, 6) \\
227-
&= \mathrm{gcd}(6, 12 - 6\times 2) \\
228-
&= \mathrm{gcd}(6, 0) \\
229-
&= 6
230-
\end{align*}
231-
$$
232-
233-
よって、最大公約数は $6$
234-
235-
これを使うと、最大公約数を求めるプログラムは次のようになります。
236-
237217
<ViewSource path="/recursion/gcd.ipynb" />
238218

239219
:::note
240220

241221
このプログラムは、はじめの引数が $a < b$ の場合でも動きます。一度目の再帰で、`gcd(b, a % b)` = `gcd(b, a)` が返されるからです。
242222

243-
つまり、$18$ と $30$ の最大公約数を求めるとき、
223+
つまり、$18$ と $30$ の最大公約数を求めるとき、$\mathrm{gcd}(a, b)$ を $a$ と $b$ の最大公約数とすると、
244224

245225
$$
246226
\begin{align*}

0 commit comments

Comments
 (0)