try{let e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},s=(new e.Error).stack;s&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="f4642652-8577-4019-a6d0-edcfc5c38ca5",e._sentryDebugIdIdentifier="sentry-dbid-f4642652-8577-4019-a6d0-edcfc5c38ca5")}catch(e){}(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[376],{80231:(e,s,n)=>{"use strict";n.r(s),n.d(s,{default:()=>R});var a=n(84573),r=n(66601),t=n(5406);let i={MAX_RACES:10,WIN_CHANCES:.2,INJURY_CHANCES:.2};function l(e){let{races:s,wins:n,isInjured:r}=e;return(0,a.jsxs)("div",{className:"flex flex-row justify-center gap-2 my-4",children:[(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Races:"})," ",s,"/",i.MAX_RACES]}),(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Wins:"})," ",n]}),(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Status:"})," ",r?(0,a.jsx)("span",{className:"text-red-500",role:"status","aria-label":"Player is injured",children:"Injured"}):(0,a.jsx)("span",{className:"text-green-500",role:"status","aria-label":"Player is healthy",children:"Healthy"})]})]})}function c(e){let{onRace:s,onReset:n,isDisabled:r}=e;return(0,a.jsxs)("div",{className:"mx-auto flex flex-row gap-2",children:[(0,a.jsx)(t.T,{variant:r?"bordered":"solid",color:"primary",onPress:s,disabled:r,"aria-label":"Start a new race",children:"Race"}),(0,a.jsx)(t.T,{variant:r?"solid":"bordered",color:"secondary",onPress:n,"aria-label":"Reset the game",children:"Reset"})]})}function o(e){let{wins:s,races:n,isInjured:r}=e;return n{s({type:"RACE"})},[]),a=(0,r.useCallback)(()=>{s({type:"RESET"})},[]),t=(0,r.useMemo)(()=>e.isInjured?"injured":e.races>=i.MAX_RACES?"completed":"active",[e.isInjured,e.races]);return{...e,race:n,reset:a,gameStatus:t}}(),m="active"!==h;return(0,a.jsxs)("div",{className:"border border-black rounded-lg p-4 my-4 flex flex-col gap-2",children:[(0,a.jsx)("h2",{className:"text-xl font-bold mb-2",children:"Game 1: Single Player"}),(0,a.jsxs)("p",{children:["You're a skier. You can participate in up to ",i.MAX_RACES," ","races."]}),(0,a.jsxs)("p",{children:["In each race, you have a ",100*i.WIN_CHANCES,"% chance of winning, but also a ",100*i.INJURY_CHANCES,"% chance of getting injured. If you get injured, you can't participate in any more races."]}),(0,a.jsx)("p",{children:"How many races do you expect to win?"}),(0,a.jsx)(l,{races:e,wins:s,isInjured:n}),(0,a.jsxs)("div",{className:"mx-auto flex flex-col md:flex-row gap-2 justify-center",children:[(0,a.jsx)(c,{onRace:t,onReset:d,isDisabled:m}),!m&&(0,a.jsx)("span",{className:"max-w-xs text-sm text-gray-500",children:"Keep playing until ten races: something interesting is likely to happen soon..."})]}),(0,a.jsx)(o,{wins:s,races:e,isInjured:n})]})}let u={races:0,wins:0,isInjured:!1};function x(e,s){switch(s.type){case"RACE":if(e.isInjured||e.races>=i.MAX_RACES)return e;let n=Math.random(){if(s.injured)return s;let n=Math.random(){e>=h.MAX_RACES||(s(e=>e+1),a(e=>l(h.ALICE,e)),i(e=>l(h.BOB,e)))},[e,l]),o=(0,r.useCallback)(()=>{s(0),a({wins:0,injured:!1}),i({wins:0,injured:!1})},[]),d=e>=h.MAX_RACES;return{races:e,aliceStats:n,bobStats:t,race:c,reset:o,isGameOver:d}}();return(0,a.jsxs)("div",{className:"border border-black rounded-lg p-4 my-4 flex flex-col gap-2",children:[(0,a.jsx)(m,{}),(0,a.jsx)(f,{races:e,aliceStats:s,bobStats:n}),(0,a.jsx)(p,{onRace:t,onReset:i,isGameOver:l}),(0,a.jsx)(N,{isGameOver:l,aliceStats:s,bobStats:n})]})}let b={MAX_RACES:20,NUM_PLAYERS:100,ALICE_WIN_CHANCES:.2,ALICE_INJURY_CHANCES:.1,BOB_WIN_CHANCES:.15,BOB_INJURY_CHANCES:.01};function A(e){let{player:s}=e;return(0,a.jsx)("div",{className:"w-4 h-4 rounded-full ".concat(s.isInjured?"bg-red-500":"bg-green-500"),title:"".concat(s.name," - Wins: ").concat(s.wins).concat(s.isInjured?" (Injured)":""),role:"img","aria-label":"".concat(s.name," - ").concat(s.wins," wins").concat(s.isInjured?", Injured":", Healthy")})}function C(e){let{name:s,stats:n}=e;return(0,a.jsxs)("div",{children:[(0,a.jsxs)("p",{className:"font-bold",children:[s,"s"]}),(0,a.jsxs)("p",{className:"text-sm",children:[(0,a.jsxs)("b",{children:["Wins: ",n.totalWins," "]})," (average per skier:"," ",n.averageWins.toFixed(2),")"]})]})}function y(e){let{onRace:s,onReset:n,isTheRaceOn:r}=e;return(0,a.jsxs)("div",{className:"flex gap-2 justify-center",children:[(0,a.jsx)(t.T,{color:"primary",variant:r?"solid":"faded",onPress:s,"aria-label":"Start next race",children:"Race"}),(0,a.jsx)(t.T,{variant:r?"faded":"solid",color:"secondary",onPress:n,"aria-label":"Reset game",children:"Reset"})]})}function w(){let{races:e,alicePlayers:s,bobPlayers:n,aliceStats:t,bobStats:i,race:l,reset:c}=function(){let[e,s]=(0,r.useState)(0),[n,a]=(0,r.useState)([]),t=(0,r.useCallback)(()=>{let e=[];for(let s=0;s{a(t())},[t]);let i=(0,r.useCallback)(()=>{s(e=>e+1),a(e=>{let s=e.map(e=>{if(e.isInjured)return e;let s="Alice"===e.name?b.ALICE_INJURY_CHANCES:b.BOB_INJURY_CHANCES;return{...e,isInjured:Math.random()!e.isInjured);if(0===n.length)return s;let a=Math.random()*n.reduce((e,s)=>e+("Alice"===s.name?b.ALICE_WIN_CHANCES:b.BOB_WIN_CHANCES),0),r=n[0];for(let e of n)if((a-="Alice"===e.name?b.ALICE_WIN_CHANCES:b.BOB_WIN_CHANCES)<=0){r=e;break}return s.map(e=>e.id===r.id?{...e,wins:e.wins+1}:e)})},[]),l=(0,r.useCallback)(()=>{s(0),a(t())},[t]),c=(0,r.useMemo)(()=>n.filter(e=>"Alice"===e.name),[n]),o=(0,r.useMemo)(()=>n.filter(e=>"Bob"===e.name),[n]),d=(0,r.useCallback)(e=>{let s=e.reduce((e,s)=>e+s.wins,0),n=e.filter(e=>e.isInjured).length;return{totalWins:s,averageWins:s/(b.NUM_PLAYERS/2),injuredCount:n,injuredPercentage:n/(b.NUM_PLAYERS/2)*100}},[]),u=(0,r.useMemo)(()=>d(c),[c,d]),x=(0,r.useMemo)(()=>d(o),[o,d]),h=e>=b.MAX_RACES;return{races:e,players:n,alicePlayers:c,bobPlayers:o,aliceStats:u,bobStats:x,isGameOver:h,race:i,reset:l}}(),o=e>=b.MAX_RACES;return(0,a.jsxs)("div",{className:"flex flex-col gap-2 border border-black rounded-lg p-4 my-4",children:[(0,a.jsx)("h2",{className:"text-xl font-bold mb-2",children:"Game 3: Population of Skiers"}),(0,a.jsxs)("p",{children:["Now we have ",b.NUM_PLAYERS," skiers:"," ",b.NUM_PLAYERS/2," Alices and ",b.NUM_PLAYERS/2," ","Bobs."]}),(0,a.jsxs)("p",{children:["Each Alice has a ",100*b.ALICE_WIN_CHANCES,"% chance of winning and a ",100*b.ALICE_INJURY_CHANCES,"% chance of injury per race, and each Bob has a ",100*b.BOB_WIN_CHANCES,"% chance of winning and a ",100*b.BOB_INJURY_CHANCES,"% chance of injury per race."]}),(0,a.jsxs)("p",{children:["Play the game for at least ",b.MAX_RACES,", noticing how Alices are likely to win more races at the beginning but fewer as the game progresses. So,"," ",(0,a.jsx)("b",{children:"it would be a mistake to think that Alice's strategy is better just because it grows faster at the beginning."})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 my-4",children:[(0,a.jsxs)("p",{className:"text-center",children:[(0,a.jsx)("strong",{children:"Races:"})," ",e,o&&(0,a.jsx)("span",{className:"text-sm ml-1",children:"(minimum races reached)"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4 justify-items-center text-center",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(C,{name:"Alice",stats:t}),(0,a.jsx)("div",{className:"mx-auto flex flex-wrap gap-1 mt-2 max-w-[200px]",children:s.map(e=>(0,a.jsx)(A,{player:e},e.id))}),(0,a.jsxs)("p",{className:"mt-2 w-full text-center text-tiny",children:["Injury status: (",t.injuredPercentage.toFixed(0),"% injured)"]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(C,{name:"Bob",stats:i}),(0,a.jsx)("div",{className:"mx-auto flex flex-wrap gap-1 mt-2 max-w-[200px]",children:n.map(e=>(0,a.jsx)(A,{player:e},e.id))}),(0,a.jsxs)("p",{className:"mt-2 w-full text-center text-tiny",children:["Injury status: (",i.injuredPercentage.toFixed(0),"% injured)"]})]})]})]}),(0,a.jsx)(y,{onRace:l,onReset:c,isTheRaceOn:e<10})]})}var E=n(31057),_=n(24716),S=n.n(_),I=n(78927);function R(){let e=(0,a.jsxs)("div",{className:"flex flex-col gap-2 mb-4 text-center",children:[(0,a.jsx)("h1",{children:"Skiing"}),(0,a.jsxs)("p",{className:"text-sm text-gray-500 mx-auto max-w-[80%]",children:["Three quick games to help you understand the concept of"," ",(0,a.jsx)(S(),{href:"/books/ergodicity",children:"ergodicity"}),"."]})]}),s=I.b.find(e=>"Ergodicity"===e.title);return(0,a.jsxs)("div",{className:"max-w-2xl mx-auto flex flex-col gap-4",children:[e,(0,a.jsx)(d,{}),(0,a.jsx)(g,{}),(0,a.jsx)(w,{}),s&&(0,a.jsx)(E.j,{book:s})]})}},95746:(e,s,n)=>{Promise.resolve().then(n.bind(n,80231))}},e=>{var s=s=>e(e.s=s);e.O(0,[915,8206,4445,5406,5507,224,3477,7763,2041,8927,1057,1004,6306,7358],()=>s(95746)),_N_E=e.O()}]);