Skip to content

Commit 5fffaa3

Browse files
authored
Merge pull request #237 from chvmvd/add-highlight
2 parents 5f6c9bc + f6322c2 commit 5fffaa3

26 files changed

+179
-131
lines changed

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

static/function/introduce_language_fstring.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"outputs": [],
88
"source": [
99
"def introduce_self(name, language):\n",
10+
" # highlight-next-line\n",
1011
" print(f\"私の名前は、{name}です。{language}選択です。\")\n",
1112
"\n",
1213
"\n",

static/function/introduce_self_fstring.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"outputs": [],
88
"source": [
99
"def introduce_self(name):\n",
10+
" # highlight-next-line\n",
1011
" print(f\"私の名前は、{name}です。\")\n",
1112
"\n",
1213
"\n",

static/gaussian-elimination/gauss_jordan_elimination.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,31 @@
1010
" # 前進消去\n",
1111
" for i in range(len(a)):\n",
1212
" # 部分ピボット選択\n",
13+
" max_index = i\n",
1314
" for j in range(i + 1, len(a)):\n",
14-
" if abs(a[i][i]) < abs(a[j][i]):\n",
15-
" a[i], a[j] = a[j], a[i]\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",
1618
"\n",
1719
" # pivot倍で行を割る\n",
1820
" pivot = a[i][i]\n",
1921
" for j in range(i, len(a[i])):\n",
2022
" a[i][j] /= pivot\n",
2123
"\n",
24+
" # highlight-start\n",
2225
" # 掃き出す\n",
2326
" for j in range(len(a)):\n",
2427
" if j != i:\n",
2528
" factor = a[j][i]\n",
2629
" for k in range(i, len(a[i])):\n",
2730
" a[j][k] -= factor * a[i][k]\n",
31+
" # highlight-end\n",
32+
" # highlight-start\n",
2833
" x = []\n",
2934
" for i in range(len(a)):\n",
3035
" x.append(a[i][len(a[i]) - 1])\n",
3136
" return x\n",
37+
" # highlight-end\n",
3238
"\n",
3339
"\n",
3440
"print(gauss_jordan_elimination([[0, -2, 3, 2], [-1, 3, -2, 1], [1, -1, 6, 11]]))"

static/gaussian-elimination/gaussian_elimination_revised.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"def gaussian_elimination_revised(a):\n",
1010
" # 前進消去\n",
1111
" for i in range(len(a)):\n",
12+
" # highlight-start\n",
1213
" # 部分ピボット選択\n",
1314
" max_index = i\n",
1415
" for j in range(i + 1, len(a)):\n",
1516
" if abs(a[max_index][i]) < abs(a[j][i]):\n",
1617
" max_index = j\n",
1718
" a[i], a[max_index] = a[max_index], a[i]\n",
19+
" # highlight-end\n",
1820
"\n",
1921
" # pivot倍で行を割る\n",
2022
" pivot = a[i][i]\n",

static/image/append.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 2,
4-
"metadata": {},
52
"cells": [
63
{
4+
"cell_type": "code",
5+
"execution_count": null,
76
"metadata": {},
7+
"outputs": [],
88
"source": [
99
"a = [1, 2]\n",
1010
"a.append(3)\n",
1111
"print(a)"
12-
],
13-
"cell_type": "code",
14-
"outputs": [],
15-
"execution_count": null
12+
]
1613
}
17-
]
14+
],
15+
"metadata": {},
16+
"nbformat": 4,
17+
"nbformat_minor": 2
1818
}

static/life-game/count_neighbors.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
" cnt = 0\n",
1111
" for k in range(i - 1, i + 2):\n",
1212
" for l in range(j - 1, j + 2):\n",
13+
" # highlight-next-line\n",
1314
" if 0 <= k < len(board) and 0 <= l < len(board[k]):\n",
1415
" cnt += board[k][l]\n",
1516
" return cnt - board[i][j]\n",

static/life-game/is_alive.ipynb

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": {},
52
"cells": [
63
{
4+
"cell_type": "code",
5+
"execution_count": null,
76
"metadata": {},
7+
"outputs": [],
88
"source": [
99
"def count_neighbors(board, i, j):\n",
1010
" cnt = 0\n",
@@ -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,12 +32,15 @@
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))"
36-
],
37-
"cell_type": "code",
38-
"outputs": [],
39-
"execution_count": null
40+
]
4041
}
41-
]
42+
],
43+
"metadata": {},
44+
"nbformat": 4,
45+
"nbformat_minor": 2
4246
}

static/life-game/life_game.ipynb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 2,
4-
"metadata": {},
52
"cells": [
63
{
4+
"cell_type": "code",
5+
"execution_count": null,
76
"metadata": {},
7+
"outputs": [],
88
"source": [
99
"!pip install ita"
10-
],
11-
"cell_type": "code",
12-
"outputs": [],
13-
"execution_count": null
10+
]
1411
},
1512
{
13+
"cell_type": "code",
14+
"execution_count": null,
1615
"metadata": {},
16+
"outputs": [],
1717
"source": [
1818
"import ita\n",
1919
"\n",
2020
"%matplotlib inline"
21-
],
22-
"cell_type": "code",
23-
"outputs": [],
24-
"execution_count": null
21+
]
2522
},
2623
{
24+
"cell_type": "code",
25+
"execution_count": null,
2726
"metadata": {},
27+
"outputs": [],
2828
"source": [
2929
"def count_neighbors(board, i, j):\n",
3030
" cnt = 0\n",
@@ -82,10 +82,10 @@
8282
"n = 20\n",
8383
"images = life_game(data, n)\n",
8484
"ita.plot.animation_show(images)"
85-
],
86-
"cell_type": "code",
87-
"outputs": [],
88-
"execution_count": null
85+
]
8986
}
90-
]
87+
],
88+
"metadata": {},
89+
"nbformat": 4,
90+
"nbformat_minor": 2
9191
}

0 commit comments

Comments
 (0)