From da8c5ed6a277f53aba2b88fae97cb925a379e9ef Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sat, 4 Feb 2023 15:49:24 +0900 Subject: [PATCH 1/4] Add hint at if article --- docs/01python/08if/index.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/01python/08if/index.mdx b/docs/01python/08if/index.mdx index 1a35d78e1..94ff83502 100644 --- a/docs/01python/08if/index.mdx +++ b/docs/01python/08if/index.mdx @@ -3,6 +3,7 @@ sidebar_position: 8 --- import ViewSource from "@site/src/components/ViewSource"; +import Hint from "@site/src/components/Hint"; import Answer from "@site/src/components/Answer"; # 条件分岐 @@ -143,6 +144,20 @@ else: 絶対値を求めるプログラムを作ってみましょう。 + + +次の式を思い起こせば、作れそうです。 + +$$ +|x|= +\begin{dcases} + x & \text{if $x\geq 0$,} \\ + -x & \text{else.} +\end{dcases} +$$ + + + From c271eea0223779fcb5318c5c13d70008b1f8adb4 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sat, 4 Feb 2023 15:57:56 +0900 Subject: [PATCH 2/4] Add hint at array article --- docs/01python/10array/index.mdx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/01python/10array/index.mdx b/docs/01python/10array/index.mdx index cc15c079d..8b9a5d21a 100644 --- a/docs/01python/10array/index.mdx +++ b/docs/01python/10array/index.mdx @@ -3,6 +3,7 @@ sidebar_position: 10 --- import ViewSource from "@site/src/components/ViewSource"; +import Hint from "@site/src/components/Hint"; import Answer from "@site/src/components/Answer"; # 配列 @@ -92,6 +93,16 @@ len(配列名) 生徒の英語の点数が書かれた配列を受け取って、その平均点を返す関数を作ってみましょう。 実際に、点数をそれぞれ 26 点、78 点、83 点、20 点、10 点、11 点、22 点、16 点、41 点、95 点として計算してみましょう。 + + +$n$ 個のデータを $x_1,x_2,\dots,x_n$、平均点を $\bar{x}$ とすると、次のようにして求められるのでした。 + +$$ +\bar{x}=\frac{x_1+x_2+\dots +x_n}{n}=\frac{\sum_{i=1}^n x_i}{n} +$$ + + + @@ -106,7 +117,7 @@ len(配列名) 今度は、分散を求めるプログラムを書いてみましょう。 -$n$ 個の観測データを $x_1,x_2,\cdots,x_n$、平均を $\bar{x}$ とすると、分散 $s^2$ は次のように与えられるとします。 +$n$ 個のデータを $x_1,x_2,\dots,x_n$、平均を $\bar{x}$ とすると、分散 $s^2$ は次のように与えられるとします。 $$ s^2=\frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n} From 2ed5f687ae856f34e42a61b66577f73e3e185f3e Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sat, 4 Feb 2023 16:00:54 +0900 Subject: [PATCH 3/4] Add hint at multi-array article --- docs/01python/11multi-array/index.mdx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/01python/11multi-array/index.mdx b/docs/01python/11multi-array/index.mdx index 0d697cbd7..a615b441b 100644 --- a/docs/01python/11multi-array/index.mdx +++ b/docs/01python/11multi-array/index.mdx @@ -3,6 +3,7 @@ sidebar_position: 11 --- import ViewSource from "@site/src/components/ViewSource"; +import Hint from "@site/src/components/Hint"; import Answer from "@site/src/components/Answer"; # 多次元配列 @@ -57,6 +58,12 @@ A、B、C の 3 人の生徒がいて、それぞれの国語、数学、英語 | **B** | 73 | 53 | 84 | | **C** | 63 | 48 | 64 | + + +まずそれぞれの生徒の得点の合計を求める関数を作ってから、その最高点を求める関数を作ると良いでしょう。 + + + From ed244882f460f77259b7ebd75222a2cc66484fc5 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sat, 4 Feb 2023 16:11:45 +0900 Subject: [PATCH 4/4] Add hint at practice article --- docs/01python/12practice/index.mdx | 29 ++++++++++++++++++++++++- docs/04algorithms/02recursion/index.mdx | 22 +------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/01python/12practice/index.mdx b/docs/01python/12practice/index.mdx index 130869e2d..f6ca2bab6 100644 --- a/docs/01python/12practice/index.mdx +++ b/docs/01python/12practice/index.mdx @@ -74,11 +74,38 @@ $n$ 番目まで Fizz Buzz での正しい解を表示するプログラムを 最大公約数を求めるプログラムを作ってみましょう。最大公約数(greatest common divisor)は、GCD とよく略されます。 + + +ユークリッドの互除法を用いれば簡単にできます。 + +ユークリッドの互除法を用いると、次のように最大公約数が計算できるのでした。 +$\mathrm{gcd}(a, b)$ を $a$ と $b$ の最大公約数とします。 + +例:$30$ と $18$ の最大公約数を求める。 + +$$ +\begin{align*} + \mathrm{gcd}(30, 18) &= \mathrm{gcd}(18, 30 - 18\times 1) \\ + &= \mathrm{gcd}(18, 12) \\ + &= \mathrm{gcd}(12, 18 - 12\times 1) \\ + &= \mathrm{gcd}(12, 6) \\ + &= \mathrm{gcd}(6, 12 - 6\times 2) \\ + &= \mathrm{gcd}(6, 0) \\ + &= 6 +\end{align*} +$$ + +よって、最大公約数は $6$ + + + +ユークリッドの互除法を使うと、最大公約数を求めるプログラムは次のようになります。 + -再帰を使うと次のようにもできます。再帰は後の項で説明します。 +再帰を使うと次のようにもできます。再帰を使ったプログラムは、後の項で紹介します。 diff --git a/docs/04algorithms/02recursion/index.mdx b/docs/04algorithms/02recursion/index.mdx index d759ebb9f..c01df272c 100644 --- a/docs/04algorithms/02recursion/index.mdx +++ b/docs/04algorithms/02recursion/index.mdx @@ -214,33 +214,13 @@ $$ -ユークリッドの互除法を用いれば簡単にできます。$\mathrm{gcd}(a, b)$ を $a$ と $b$ の最大公約数とします。 - -例:$30$ と $18$ の最大公約数を求める。 - -$$ -\begin{align*} - \mathrm{gcd}(30, 18) &= \mathrm{gcd}(18, 30 - 18\times 1) \\ - &= \mathrm{gcd}(18, 12) \\ - &= \mathrm{gcd}(12, 18 - 12\times 1) \\ - &= \mathrm{gcd}(12, 6) \\ - &= \mathrm{gcd}(6, 12 - 6\times 2) \\ - &= \mathrm{gcd}(6, 0) \\ - &= 6 -\end{align*} -$$ - -よって、最大公約数は $6$ - -これを使うと、最大公約数を求めるプログラムは次のようになります。 - :::note このプログラムは、はじめの引数が $a < b$ の場合でも動きます。一度目の再帰で、`gcd(b, a % b)` = `gcd(b, a)` が返されるからです。 -つまり、$18$ と $30$ の最大公約数を求めるとき、 +つまり、$18$ と $30$ の最大公約数を求めるとき、$\mathrm{gcd}(a, b)$ を $a$ と $b$ の最大公約数とすると、 $$ \begin{align*}