Skip to content

Commit b352174

Browse files
committed
Add highlight
1 parent e94360f commit b352174

21 files changed

Lines changed: 437 additions & 395 deletions

docs/02-python/05-function/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ Python では、きちんとインデント(字下げ)をしないとエラ
5252
<ViewSource path="/function/introduce_self.ipynb" />
5353

5454
:::note
55+
5556
上のプログラムでも問題ないのですが、実際には次のプログラムのように `f-string` を使った表記の方が可読性が高くなって実際の開発では好まれてたりします。しかし、あまり気にしなくて良いでしょう。ちなみに、`"` の前に `f` と書くことで、`"` 内の `{` で囲まれた変数の中身を表示できます。
5657

5758
<ViewSource path="/function/introduce_self_fstring.ipynb" />
59+
5860
:::
5961

6062
戻り値を使うと、次のようにも表現できます。

docs/05-algorithms/06-dp/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ DP には大きく分けて、二種類あります。トップダウン方式
8282

8383
次のようにしても良いでしょう。
8484

85-
<ViewSource path="/dp/fib_bottom_up.ipynb" />
85+
<ViewSource path="/dp/fib_bottom_up2.ipynb" />
8686

8787
:::
8888

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"metadata": {},
7-
"outputs": [],
8-
"source": [
9-
"def introduce_self(name, language):\n",
10-
" print(f\"私の名前は、{name}です。{language}選択です。\")\n",
11-
"\n",
12-
"\n",
13-
"introduce_self(\"東大太郎\", \"中国語\")"
14-
]
15-
}
16-
],
17-
"metadata": {},
18-
"nbformat": 4,
19-
"nbformat_minor": 2
2+
"nbformat": 4,
3+
"nbformat_minor": 2,
4+
"metadata": {},
5+
"cells": [
6+
{
7+
"metadata": {},
8+
"source": [
9+
"def introduce_self(name, language):\n",
10+
" # highlight-next-line\n",
11+
" print(f\"\u79c1\u306e\u540d\u524d\u306f\u3001{name}\u3067\u3059\u3002{language}\u9078\u629e\u3067\u3059\u3002\")\n",
12+
"\n",
13+
"\n",
14+
"introduce_self(\"\u6771\u5927\u592a\u90ce\", \"\u4e2d\u56fd\u8a9e\")"
15+
],
16+
"cell_type": "code",
17+
"outputs": [],
18+
"execution_count": null
19+
}
20+
]
2021
}
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"metadata": {},
7-
"outputs": [],
8-
"source": [
9-
"def introduce_self(name):\n",
10-
" print(f\"私の名前は、{name}です。\")\n",
11-
"\n",
12-
"\n",
13-
"introduce_self(\"田中\")"
14-
]
15-
}
16-
],
17-
"metadata": {},
18-
"nbformat": 4,
19-
"nbformat_minor": 2
2+
"nbformat": 4,
3+
"nbformat_minor": 2,
4+
"metadata": {},
5+
"cells": [
6+
{
7+
"metadata": {},
8+
"source": [
9+
"def introduce_self(name):\n",
10+
" # highlight-next-line\n",
11+
" print(f\"\u79c1\u306e\u540d\u524d\u306f\u3001{name}\u3067\u3059\u3002\")\n",
12+
"\n",
13+
"\n",
14+
"introduce_self(\"\u7530\u4e2d\")"
15+
],
16+
"cell_type": "code",
17+
"outputs": [],
18+
"execution_count": null
19+
}
20+
]
2021
}
Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"metadata": {},
7-
"outputs": [],
8-
"source": [
9-
"def gaussian_elimination_revised(a):\n",
10-
" # 前進消去\n",
11-
" for i in range(len(a)):\n",
12-
" # 部分ピボット選択\n",
13-
" max_index = i\n",
14-
" for j in range(i + 1, len(a)):\n",
15-
" if abs(a[max_index][i]) < abs(a[j][i]):\n",
16-
" max_index = j\n",
17-
" a[i], a[max_index] = a[max_index], a[i]\n",
18-
"\n",
19-
" # pivot倍で行を割る\n",
20-
" pivot = a[i][i]\n",
21-
" for j in range(i, len(a[i])):\n",
22-
" a[i][j] /= pivot\n",
23-
"\n",
24-
" # i + 1行目以降を掃き出す\n",
25-
" for j in range(i + 1, len(a)):\n",
26-
" factor = a[j][i]\n",
27-
" for k in range(i, len(a[i])):\n",
28-
" a[j][k] -= factor * a[i][k]\n",
29-
"\n",
30-
" # 後退代入\n",
31-
" x = [0 for _ in range(len(a[0]) - 1)]\n",
32-
" for i in reversed(range(len(a))):\n",
33-
" x[i] = a[i][len(a[i]) - 1]\n",
34-
" for j in range(i):\n",
35-
" a[j][len(a[i]) - 1] -= a[j][i] * x[i]\n",
36-
" return x\n",
37-
"\n",
38-
"\n",
39-
"print(gaussian_elimination_revised([[0, -2, 3, 2], [-1, 3, -2, 1], [1, -1, 6, 11]]))"
40-
]
41-
}
42-
],
43-
"metadata": {},
44-
"nbformat": 4,
45-
"nbformat_minor": 2
2+
"nbformat": 4,
3+
"nbformat_minor": 2,
4+
"metadata": {},
5+
"cells": [
6+
{
7+
"metadata": {},
8+
"source": [
9+
"def gaussian_elimination_revised(a):\n",
10+
" # \u524d\u9032\u6d88\u53bb\n",
11+
" for i in range(len(a)):\n",
12+
" # highlight-start\n",
13+
" # \u90e8\u5206\u30d4\u30dc\u30c3\u30c8\u9078\u629e\n",
14+
" max_index = i\n",
15+
" for j in range(i + 1, len(a)):\n",
16+
" if abs(a[max_index][i]) < abs(a[j][i]):\n",
17+
" max_index = j\n",
18+
" a[i], a[max_index] = a[max_index], a[i]\n",
19+
" # highlight-end\n",
20+
"\n",
21+
" # pivot\u500d\u3067\u884c\u3092\u5272\u308b\n",
22+
" pivot = a[i][i]\n",
23+
" for j in range(i, len(a[i])):\n",
24+
" a[i][j] /= pivot\n",
25+
"\n",
26+
" # i + 1\u884c\u76ee\u4ee5\u964d\u3092\u6383\u304d\u51fa\u3059\n",
27+
" for j in range(i + 1, len(a)):\n",
28+
" factor = a[j][i]\n",
29+
" for k in range(i, len(a[i])):\n",
30+
" a[j][k] -= factor * a[i][k]\n",
31+
"\n",
32+
" # \u5f8c\u9000\u4ee3\u5165\n",
33+
" x = [0 for _ in range(len(a[0]) - 1)]\n",
34+
" for i in reversed(range(len(a))):\n",
35+
" x[i] = a[i][len(a[i]) - 1]\n",
36+
" for j in range(i):\n",
37+
" a[j][len(a[i]) - 1] -= a[j][i] * x[i]\n",
38+
" return x\n",
39+
"\n",
40+
"\n",
41+
"print(gaussian_elimination_revised([[0, -2, 3, 2], [-1, 3, -2, 1], [1, -1, 6, 11]]))"
42+
],
43+
"cell_type": "code",
44+
"outputs": [],
45+
"execution_count": null
46+
}
47+
]
4648
}
Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"metadata": {},
7-
"outputs": [],
8-
"source": [
9-
"def count_neighbors(board, i, j):\n",
10-
" cnt = 0\n",
11-
" for k in range(i - 1, i + 2):\n",
12-
" for l in range(j - 1, j + 2):\n",
13-
" if 0 <= k < len(board) and 0 <= l < len(board[k]):\n",
14-
" cnt += board[k][l]\n",
15-
" return cnt - board[i][j]\n",
16-
"\n",
17-
"\n",
18-
"board = [[1, 1, 0], [1, 0, 0], [0, 0, 0]]\n",
19-
"print(count_neighbors(board, 0, 0))"
20-
]
21-
}
22-
],
23-
"metadata": {},
24-
"nbformat": 4,
25-
"nbformat_minor": 2
2+
"nbformat": 4,
3+
"nbformat_minor": 2,
4+
"metadata": {},
5+
"cells": [
6+
{
7+
"metadata": {},
8+
"source": [
9+
"def count_neighbors(board, i, j):\n",
10+
" cnt = 0\n",
11+
" for k in range(i - 1, i + 2):\n",
12+
" for l in range(j - 1, j + 2):\n",
13+
" # highlight-next-line\n",
14+
" if 0 <= k < len(board) and 0 <= l < len(board[k]):\n",
15+
" cnt += board[k][l]\n",
16+
" return cnt - board[i][j]\n",
17+
"\n",
18+
"\n",
19+
"board = [[1, 1, 0], [1, 0, 0], [0, 0, 0]]\n",
20+
"print(count_neighbors(board, 0, 0))"
21+
],
22+
"cell_type": "code",
23+
"outputs": [],
24+
"execution_count": null
25+
}
26+
]
2627
}

static/life-game/is_alive.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
" return cnt - board[i][j]\n",
1616
"\n",
1717
"\n",
18+
"# highlight-start\n",
1819
"def is_alive(board, i, j):\n",
1920
" neighbors_cnt = count_neighbors(board, i, j)\n",
2021
" if board[i][j] == 0:\n",
@@ -31,6 +32,9 @@
3132
" return 0\n",
3233
"\n",
3334
"\n",
35+
"# highlight-end\n",
36+
"\n",
37+
"\n",
3438
"board = [[1, 1, 0], [1, 0, 0], [0, 0, 0]]\n",
3539
"print(is_alive(board, 0, 0))"
3640
],

static/life-game/life_game_func.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
" return next_board\n",
6060
"\n",
6161
"\n",
62+
"# highlight-start\n",
6263
"def life_game(board, n):\n",
6364
" results = [0 for _ in range(n)]\n",
6465
" results[0] = board\n",
@@ -67,6 +68,9 @@
6768
" return results\n",
6869
"\n",
6970
"\n",
71+
"# highlight-end\n",
72+
"\n",
73+
"\n",
7074
"board = [[1, 1, 0], [1, 0, 0], [0, 0, 0]]\n",
7175
"n = 20\n",
7276
"print(life_game(board, n))"

static/life-game/next_generation.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
" return 0\n",
5050
"\n",
5151
"\n",
52+
"# highlight-start\n",
5253
"def next_generation(board):\n",
5354
" row = len(board)\n",
5455
" column = len(board[0])\n",
@@ -59,6 +60,9 @@
5960
" return next_board\n",
6061
"\n",
6162
"\n",
63+
"# highlight-end\n",
64+
"\n",
65+
"\n",
6266
"board = [[1, 1, 0], [1, 0, 0], [0, 0, 0]]\n",
6367
"print(next_generation(board))"
6468
],
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2+
"nbformat": 4,
3+
"nbformat_minor": 2,
4+
"metadata": {},
25
"cells": [
36
{
4-
"cell_type": "code",
5-
"execution_count": null,
67
"metadata": {},
7-
"outputs": [],
88
"source": [
99
"def calc_sum1d(scores):\n",
1010
" sum_val = 0\n",
@@ -13,6 +13,7 @@
1313
" return sum_val\n",
1414
"\n",
1515
"\n",
16+
"# highlight-start\n",
1617
"def calc_total_score_max(scores):\n",
1718
" max_score = 0\n",
1819
" for i in range(len(scores)):\n",
@@ -22,13 +23,16 @@
2223
" return max_score\n",
2324
"\n",
2425
"\n",
26+
"# highlight-end\n",
27+
"\n",
28+
"\n",
2529
"scores = [[83, 75, 32], [73, 53, 84], [63, 48, 64]]\n",
2630
"\n",
2731
"print(calc_total_score_max(scores))"
28-
]
32+
],
33+
"cell_type": "code",
34+
"outputs": [],
35+
"execution_count": null
2936
}
30-
],
31-
"metadata": {},
32-
"nbformat": 4,
33-
"nbformat_minor": 2
37+
]
3438
}

0 commit comments

Comments
 (0)