Skip to content

Instantly share code, notes, and snippets.

@empet
Created March 19, 2024 12:23
Show Gist options
  • Save empet/3e0cca30c68a49a8791915d0b0e81576 to your computer and use it in GitHub Desktop.
Save empet/3e0cca30c68a49a8791915d0b0e81576 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2baeacfb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"meanval11and10 (generic function with 1 method)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Distributions, Random\n",
"function count10_11()\n",
" Random.seed!(rand(UInt))\n",
" bits = rand(Bernoulli(0.5), 100)\n",
" pairs = [bits[k:k+1] for k in 1:99]\n",
" na = length(filter(x->sum(x)==2, pairs))\n",
" nb = length(filter(x->x==[1, 0], pairs))\n",
" return (na, nb)\n",
"end\n",
"\n",
"function meanval11and10(;N=1000)\n",
" sA=Int[] #Alice\n",
" sB=Int[] #Bob \n",
" \n",
" for _ in 1:N\n",
" na, nb = count10_11()\n",
" push!(sA, na)\n",
" push!(sB, nb)\n",
" end \n",
" mean(sA), mean(sB) #mean for number of na, resp nb, in N experiments of counting\n",
"end "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ae538d18",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(25.13, 24.63)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"meanval11and10(;N=10^2)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "2fd9f86e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(24.688, 24.721)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"meanval11and10(;N=10^3)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "4383b396",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(24.8128, 24.7367)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"meanval11and10(;N=10^4)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "c6d17787",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(24.75928, 24.75502)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"meanval11and10(;N=10^5)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "b2d64a7a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"24.75"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"99/4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5720b82c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.9.0",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment