Skip to content

Commit

Permalink
add emoji-dice
Browse files Browse the repository at this point in the history
add emoji-dice display method
  • Loading branch information
math4mad committed Oct 4, 2023
1 parent 266c35b commit 99d82c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions _freeze/basic/1-dice/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hash": "ba26fa11c8c097bfed3fe1d8ba31a3bf",
"hash": "b3914cb87ac757f02e3b7159aa4a60f7",
"result": {
"markdown": "---\ntitle: \"1-basic-probability-dice \"\n---\n\n## 1. define tools\n### 1.1 Dice🎲\n\n::: {.cell execution_count=1}\n``` {.julia .cell-code}\nemoji_dice1=[\"1️⃣\",\"2️⃣\",\"3️⃣\",\"4️⃣\",\"5️⃣\",\"6️⃣\"]\nemoji_dice2=[\"1️⃣\",\"2️⃣\",\"3️⃣\",\"4️⃣\",\"5️⃣\",\"6️⃣\"]\ndice1=Vector(1:6)\ndice2=Vector(1:6)\nshow(dice1)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1, 2, 3, 4, 5, 6]\n```\n:::\n:::\n\n\n::: {.cell execution_count=2}\n``` {.julia .cell-code}\nusing PrettyTables\n\nmatrix=[[i,j] for i in dice1, j in dice2]\ndisplay(matrix)\ntwo_dice_space=vec(matrix)\ntwo_dice_size=length(two_dice_space)\n\"two_dice_size\"=>two_dice_size\n```\n\n::: {.cell-output .cell-output-display}\n```\n6×6 Matrix{Vector{Int64}}:\n [1, 1] [1, 2] [1, 3] [1, 4] [1, 5] [1, 6]\n [2, 1] [2, 2] [2, 3] [2, 4] [2, 5] [2, 6]\n [3, 1] [3, 2] [3, 3] [3, 4] [3, 5] [3, 6]\n [4, 1] [4, 2] [4, 3] [4, 4] [4, 5] [4, 6]\n [5, 1] [5, 2] [5, 3] [5, 4] [5, 5] [5, 6]\n [6, 1] [6, 2] [6, 3] [6, 4] [6, 5] [6, 6]\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=3}\n```\n\"two_dice_size\" => 36\n```\n:::\n:::\n\n\n## 2.question \n\n### 2.1 两个骰子乘积为4\n```julia\n cond(arr::Array,cond_number=4)=*(arr...)==cond_number\n```\n\n::: {.cell execution_count=3}\n``` {.julia .cell-code}\ncond1(arr::Array,cond_number=4)::Bool=*(arr...)==cond_number\nres1=filter(arr->cond1(arr),two_dice_space)\nshow(\"两个骰子乘积为4\"=>res1)\nprintln(\"\\n\")\nshow(\"两个骰子乘积为4概率\"=>length(res1)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"两个骰子乘积为4\" => [[4, 1], [2, 2], [1, 4]]\n\n\"两个骰子乘积为4概率\" => 1//12\n```\n:::\n:::\n\n\n### 2.2 两个骰子点数合计等于小于 5\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\ncond2(arr::Array)::Bool=sum(arr)<=5\nres2=filter(arr->cond2(arr),two_dice_space)\nshow(\"两个骰子点数合计等于小于5\"=>length(res2))\nprintln(\"\\n\")\nshow(\"两个骰子点数合计等于小于5的概率\"=>length(res2)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"两个骰子点数合计等于小于5\" => 10\n\n\"两个骰子点数合计等于小于5的概率\" => 5//18\n```\n:::\n:::\n\n\n### 2.3 两个骰子点数合计大于等于 10\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\ncond3(arr::Array)::Bool=sum(arr)>=10\nres3=filter(arr->cond3(arr),two_dice_space)\nshow(\"点数合计大于等于10\"=>res3)\nprintln(\"\\n\")\nshow(\"点数合计大于等于10的概率\"=>length(res3)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"点数合计大于等于10\" => [[6, 4], [5, 5], [6, 5], [4, 6], [5, 6], [6, 6]]\n\n\"点数合计大于等于10的概率\" => 1//6\n```\n:::\n:::\n\n\n### 2.4 两个骰子点数相同\n\n::: {.cell execution_count=6}\n``` {.julia .cell-code}\ncond4(arr::Array)::Bool=arr[1]==arr[2]\nres4=filter(arr->cond4(arr),two_dice_space)\nshow(\"两个骰子点数相同\"=>res4)\nprintln(\"\\n\")\nshow(\"两个骰子点数相同的概率\"=>length(res4)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"两个骰子点数相同\" => [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]\n\n\"两个骰子点数相同的概率\" => 1//6\n```\n:::\n:::\n\n\n### 2.5 两个骰子点数合计等于 10\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\ncond5(arr::Array)::Bool=sum(arr)==10\nres5=filter(arr->cond5(arr),two_dice_space)\nshow(\"点数合计等于10\"=>res5)\nprintln(\"\\n\")\nshow(\"点数合计等于10的概率\"=>length(res5)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"点数合计等于10\" => [[6, 4], [5, 5], [4, 6]]\n\n\"点数合计等于10的概率\" => 1//12\n```\n:::\n:::\n\n\n### 2.6 点数之和被5整除\n\n::: {.cell execution_count=8}\n``` {.julia .cell-code}\ncond6(arr::Array)::Bool=sum(arr)|>d->mod(d,5)==0\nres6=filter(arr->cond6(arr),two_dice_space)\nshow(\"点数之和被5整除\"=>res6)\nprintln(\"\\n\")\nshow(\"点数之和被5整除的概率\"=>length(res6)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"点数之和被5整除\" => [[4, 1], [3, 2], [2, 3], [1, 4], [6, 4], [5, 5], [4, 6]]\n\n\"点数之和被5整除的概率\" => 7//36\n```\n:::\n:::\n\n\n",
"markdown": "---\ntitle: \"1-basic-probability-dice \"\n---\n\n## 1. define tools\n### 1.1 Dice🎲\n\n::: {.cell execution_count=1}\n``` {.julia .cell-code}\nemoji_dice1=[\"1️⃣\",\"2️⃣\",\"3️⃣\",\"4️⃣\",\"5️⃣\",\"6️⃣\"]\nemoji_dice2=[\"1️⃣\",\"2️⃣\",\"3️⃣\",\"4️⃣\",\"5️⃣\",\"6️⃣\"]\nshow_dice_emoji(arr)=[[emoji_dice1[d[1]],emoji_dice2[d[2]]] for d in arr]\ndice1=Vector(1:6)\ndice2=Vector(1:6)\nshow(dice1)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1, 2, 3, 4, 5, 6]\n```\n:::\n:::\n\n\n::: {.cell execution_count=2}\n``` {.julia .cell-code}\nusing PrettyTables\n\nmatrix=[[i,j] for i in dice1, j in dice2]\nemo_matrix=[[emoji_dice1[i],emoji_dice2[j]] for i in dice1, j in dice2]\ndisplay(emo_matrix)\ntwo_dice_space=vec(matrix)\ntwo_dice_size=length(two_dice_space)\n\"two_dice_size\"=>two_dice_size\n```\n\n::: {.cell-output .cell-output-display}\n```\n6×6 Matrix{Vector{String}}:\n [\"1️⃣\", \"1️⃣\"] [\"1️⃣\", \"2️⃣\"] [\"1️⃣\", \"3️⃣\"] [\"1️⃣\", \"4️⃣\"] [\"1️⃣\", \"5️⃣\"] [\"1️⃣\", \"6️⃣\"]\n [\"2️⃣\", \"1️⃣\"] [\"2️⃣\", \"2️⃣\"] [\"2️⃣\", \"3️⃣\"] [\"2️⃣\", \"4️⃣\"] [\"2️⃣\", \"5️⃣\"] [\"2️⃣\", \"6️⃣\"]\n [\"3️⃣\", \"1️⃣\"] [\"3️⃣\", \"2️⃣\"] [\"3️⃣\", \"3️⃣\"] [\"3️⃣\", \"4️⃣\"] [\"3️⃣\", \"5️⃣\"] [\"3️⃣\", \"6️⃣\"]\n [\"4️⃣\", \"1️⃣\"] [\"4️⃣\", \"2️⃣\"] [\"4️⃣\", \"3️⃣\"] [\"4️⃣\", \"4️⃣\"] [\"4️⃣\", \"5️⃣\"] [\"4️⃣\", \"6️⃣\"]\n [\"5️⃣\", \"1️⃣\"] [\"5️⃣\", \"2️⃣\"] [\"5️⃣\", \"3️⃣\"] [\"5️⃣\", \"4️⃣\"] [\"5️⃣\", \"5️⃣\"] [\"5️⃣\", \"6️⃣\"]\n [\"6️⃣\", \"1️⃣\"] [\"6️⃣\", \"2️⃣\"] [\"6️⃣\", \"3️⃣\"] [\"6️⃣\", \"4️⃣\"] [\"6️⃣\", \"5️⃣\"] [\"6️⃣\", \"6️⃣\"]\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=46}\n```\n\"two_dice_size\" => 36\n```\n:::\n:::\n\n\n## 2.question \n\n### 2.1 两个骰子乘积为4\n```julia\n cond(arr::Array,cond_number=4)=*(arr...)==cond_number\n```\n\n::: {.cell execution_count=3}\n``` {.julia .cell-code}\ncond1(arr::Array,cond_number=4)::Bool=*(arr...)==cond_number\nres1=filter(arr->cond1(arr),two_dice_space)\n\nshow(\"两个骰子乘积为4\"=>show_dice_emoji(res1))\nprintln(\"\\n\")\nshow(\"两个骰子乘积为4概率\"=>length(res1)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"两个骰子乘积为4\" => [[\"4️⃣\", \"1️⃣\"], [\"2️⃣\", \"2️⃣\"], [\"1️⃣\", \"4️⃣\"]]\n\n\"两个骰子乘积为4概率\" => 1//12\n```\n:::\n:::\n\n\n### 2.2 两个骰子点数合计等于小于 5\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\ncond2(arr::Array)::Bool=sum(arr)<=5\nres2=filter(arr->cond2(arr),two_dice_space)\nshow(\"两个骰子点数合计等于小于5\"=>length(res2))\nprintln(\"\\n\")\nshow(\"两个骰子点数合计等于小于5的概率\"=>length(res2)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"两个骰子点数合计等于小于5\" => 10\n\n\"两个骰子点数合计等于小于5的概率\" => 5//18\n```\n:::\n:::\n\n\n### 2.3 两个骰子点数合计大于等于 10\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\ncond3(arr::Array)::Bool=sum(arr)>=10\nres3=filter(arr->cond3(arr),two_dice_space)\nshow(\"点数合计大于等于10\"=>show_dice_emoji(res3))\nprintln(\"\\n\")\nshow(\"点数合计大于等于10的概率\"=>length(res3)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"点数合计大于等于10\" => [[\"6️⃣\", \"4️⃣\"], [\"5️⃣\", \"5️⃣\"], [\"6️⃣\", \"5️⃣\"], [\"4️⃣\", \"6️⃣\"], [\"5️⃣\", \"6️⃣\"], [\"6️⃣\", \"6️⃣\"]]\n\n\"点数合计大于等于10的概率\" => 1//6\n```\n:::\n:::\n\n\n### 2.4 两个骰子点数相同\n\n::: {.cell execution_count=6}\n``` {.julia .cell-code}\ncond4(arr::Array)::Bool=arr[1]==arr[2]\nres4=filter(arr->cond4(arr),two_dice_space)\nshow(\"两个骰子点数相同\"=>res4|>show_dice_emoji)\nprintln(\"\\n\")\nshow(\"两个骰子点数相同的概率\"=>length(res4)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"两个骰子点数相同\" => [[\"1️⃣\", \"1️⃣\"], [\"2️⃣\", \"2️⃣\"], [\"3️⃣\", \"3️⃣\"], [\"4️⃣\", \"4️⃣\"], [\"5️⃣\", \"5️⃣\"], [\"6️⃣\", \"6️⃣\"]]\n\n\"两个骰子点数相同的概率\" => 1//6\n```\n:::\n:::\n\n\n### 2.5 两个骰子点数合计等于 10\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\ncond5(arr::Array)::Bool=sum(arr)==10\nres5=filter(arr->cond5(arr),two_dice_space)\nshow(\"点数合计等于10\"=>res5|>show_dice_emoji)\nprintln(\"\\n\")\nshow(\"点数合计等于10的概率\"=>length(res5)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"点数合计等于10\" => [[\"6️⃣\", \"4️⃣\"], [\"5️⃣\", \"5️⃣\"], [\"4️⃣\", \"6️⃣\"]]\n\n\"点数合计等于10的概率\" => 1//12\n```\n:::\n:::\n\n\n### 2.6 点数之和被5整除\n\n::: {.cell execution_count=8}\n``` {.julia .cell-code}\ncond6(arr::Array)::Bool=sum(arr)|>d->mod(d,5)==0\nres6=filter(arr->cond6(arr),two_dice_space)\nshow(\"点数之和被5整除\"=>res6|>show_dice_emoji)\nprintln(\"\\n\")\nshow(\"点数之和被5整除的概率\"=>length(res6)//two_dice_size)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\"点数之和被5整除\" => [[\"4️⃣\", \"1️⃣\"], [\"3️⃣\", \"2️⃣\"], [\"2️⃣\", \"3️⃣\"], [\"1️⃣\", \"4️⃣\"], [\"6️⃣\", \"4️⃣\"], [\"5️⃣\", \"5️⃣\"], [\"4️⃣\", \"6️⃣\"]]\n\n\"点数之和被5整除的概率\" => 7//36\n```\n:::\n:::\n\n\n",
"supporting": [
"1-dice_files"
],
Expand Down
15 changes: 9 additions & 6 deletions basic/1-dice.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ title: "1-basic-probability-dice "
```{julia}
emoji_dice1=["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣"]
emoji_dice2=["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣"]
show_dice_emoji(arr)=[[emoji_dice1[d[1]],emoji_dice2[d[2]]] for d in arr]
dice1=Vector(1:6)
dice2=Vector(1:6)
show(dice1)
Expand All @@ -18,7 +19,8 @@ show(dice1)
using PrettyTables
matrix=[[i,j] for i in dice1, j in dice2]
display(matrix)
emo_matrix=[[emoji_dice1[i],emoji_dice2[j]] for i in dice1, j in dice2]
display(emo_matrix)
two_dice_space=vec(matrix)
two_dice_size=length(two_dice_space)
"two_dice_size"=>two_dice_size
Expand All @@ -33,7 +35,8 @@ two_dice_size=length(two_dice_space)
```{julia}
cond1(arr::Array,cond_number=4)::Bool=*(arr...)==cond_number
res1=filter(arr->cond1(arr),two_dice_space)
show("两个骰子乘积为4"=>res1)
show("两个骰子乘积为4"=>show_dice_emoji(res1))
println("\n")
show("两个骰子乘积为4概率"=>length(res1)//two_dice_size)
```
Expand All @@ -50,7 +53,7 @@ show("两个骰子点数合计等于小于5的概率"=>length(res2)//two_dice_si
```{julia}
cond3(arr::Array)::Bool=sum(arr)>=10
res3=filter(arr->cond3(arr),two_dice_space)
show("点数合计大于等于10"=>res3)
show("点数合计大于等于10"=>show_dice_emoji(res3))
println("\n")
show("点数合计大于等于10的概率"=>length(res3)//two_dice_size)
```
Expand All @@ -59,7 +62,7 @@ show("点数合计大于等于10的概率"=>length(res3)//two_dice_size)
```{julia}
cond4(arr::Array)::Bool=arr[1]==arr[2]
res4=filter(arr->cond4(arr),two_dice_space)
show("两个骰子点数相同"=>res4)
show("两个骰子点数相同"=>res4|>show_dice_emoji)
println("\n")
show("两个骰子点数相同的概率"=>length(res4)//two_dice_size)
```
Expand All @@ -68,7 +71,7 @@ show("两个骰子点数相同的概率"=>length(res4)//two_dice_size)
```{julia}
cond5(arr::Array)::Bool=sum(arr)==10
res5=filter(arr->cond5(arr),two_dice_space)
show("点数合计等于10"=>res5)
show("点数合计等于10"=>res5|>show_dice_emoji)
println("\n")
show("点数合计等于10的概率"=>length(res5)//two_dice_size)
```
Expand All @@ -77,7 +80,7 @@ show("点数合计等于10的概率"=>length(res5)//two_dice_size)
```{julia}
cond6(arr::Array)::Bool=sum(arr)|>d->mod(d,5)==0
res6=filter(arr->cond6(arr),two_dice_space)
show("点数之和被5整除"=>res6)
show("点数之和被5整除"=>res6|>show_dice_emoji)
println("\n")
show("点数之和被5整除的概率"=>length(res6)//two_dice_size)
```
Expand Down

0 comments on commit 99d82c6

Please sign in to comment.