try{let e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e16b9cb7-ee5b-409e-9ed3-794eaacbe7b4",e._sentryDebugIdIdentifier="sentry-dbid-e16b9cb7-ee5b-409e-9ed3-794eaacbe7b4")}catch(e){}(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4807],{8115:(e,t,a)=>{Promise.resolve().then(a.bind(a,31076))},31076:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>h});var r=a(84573),s=a(66601),n=a(5406),l=a(54499);let c=(0,l.createServerReference)("40b4e10fb20db799217bcd3da039c2c4ca2a5c8a44",l.callServer,void 0,l.findSourceMapURL,"addScore"),i=(0,l.createServerReference)("4098d4ea6887d8236e047e0e43e1de8378b432ce5d",l.callServer,void 0,l.findSourceMapURL,"getTopScores");var o=a(92217),d=a(44781),m=a(36821),x=a(77969);let u=[{name:"China",population:1411},{name:"United States",population:340.1},{name:"Indonesia",population:281},{name:"Brazil",population:212},{name:"Russia",population:143.8},{name:"Japan",population:124.5},{name:"Egypt",population:114.26},{name:"Vietnam",population:100.4},{name:"Germany",population:83.2},{name:"Thailand",population:71.6}],p=m.z.record(m.z.object({min:m.z.string().min(1,"Required").regex(/^\d*\.?\d*$/,"Must be a number"),max:m.z.string().min(1,"Required").regex(/^\d*\.?\d*$/,"Must be a number")}).refine(e=>{let t=parseFloat(e.min),a=parseFloat(e.max);return!isNaN(t)&&!isNaN(a)},{message:"Both values must be numbers"}));function h(){let[e,t]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1),[o,m]=(0,s.useState)({}),[h,f]=(0,s.useState)(!1),[b,v]=(0,s.useState)(""),[g,y]=(0,s.useState)([]),[j,N]=(0,s.useState)(!1),[w,S]=(0,s.useState)(null),[R,C]=(0,s.useState)(!1),{register:F,handleSubmit:M,formState:{errors:_,isValid:k},setValue:O}=(0,d.mN)({resolver:(0,x.u)(p),mode:"onChange"}),I=async()=>{N(!0);try{let e=await i({game:"confidence-intervals",limit:10});e.success&&e.data&&y(e.data.map(e=>({...e,createdAt:e.createdAt.toISOString()})))}catch(e){console.error("Failed to fetch top scores:",e)}finally{N(!1)}};(0,s.useEffect)(()=>{I()},[]);let T=(e,t,a)=>{let r=a.replace(/[^\d.]/g,"");O("".concat(e,".").concat(t),r)},E=e=>{let t={},a=0;u.forEach(r=>{let s=e[r.name];if(!s)return;let[n,l]=[parseFloat(s.min),parseFloat(s.max)].sort((e,t)=>e-t),c=l-n,i=r.population>=n&&r.population<=l;!i&&a++;let o=i?Math.max(0,(1-c/l)*200):0;t[r.name]={score:o,isCorrect:i,interval:c}});let r=a>1,s=r?0:Object.values(t).reduce((e,t)=>{let{score:a}=t;return e+a},0);return{individualScores:t,totalScore:s,hasLost:r}},L=(e,t)=>u.map(a=>{let r=t[a.name],s=e[a.name];return"".concat(a.name,":\n Guessed: ").concat(r.min,"-").concat(r.max,"\n Actual: ").concat(a.population,"\n Score: ").concat(s.score.toFixed(0),"\n ").concat(s.isCorrect?"✓":"✗")}).join("\n\n"),D=async e=>{C(!0);try{let{individualScores:a,totalScore:r,hasLost:s}=E(e);m(a),t(!0);let n=s?0:Object.values(a).reduce((e,t)=>{let{score:a}=t;return e+a},0),l=await c({game:"confidence-intervals",player:b||"anon",score:n});if(!l.success)return void console.error("Failed to save score:",l.error);l.data&&S(l.data.id),await new Promise(e=>setTimeout(e,1e3)),await I()}catch(e){console.error("Failed to process score:",e)}finally{C(!1)}},P=()=>Object.values(o).filter(e=>!e.isCorrect).length<=1;return(0,r.jsxs)("div",{className:"container mx-auto max-w-3xl text-center",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold mb-4",children:"Confidence Intervals"}),(0,r.jsxs)("p",{className:"mx-auto mb-4 text-sm text-gray-600",children:["For each country, enter your 90% confidence interval for its population",(0,r.jsx)("b",{children:"in millions"}),". ",(0,r.jsx)("i",{children:"Note: I use 2023-24 data."})]}),(0,r.jsxs)("p",{className:"mx-auto mb-4 text-sm text-gray-600",children:["If more than 10% of your guesses are wrong, your score is 0. Otherwise, the narrower the intervals you entered, the higher your score."," ",(0,r.jsx)("span",{className:"font-bold",children:"Careful, 90% confidence interval means you can afford at most one mistake!"})]}),(0,r.jsxs)("form",{onSubmit:M(D),className:"space-y-4",children:[(0,r.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 max-w-3xl mx-auto",children:u.map(t=>{var s,n,l,c,i,d;return(0,r.jsxs)("div",{className:"flex items-center p-3 rounded-lg ".concat(a&&_[t.name]?"bg-red-50 border border-red-200":!e||(null==(s=o[t.name])?void 0:s.isCorrect)?"bg-gray-50":"bg-red-50"),children:[(0,r.jsx)("div",{className:"w-28 text-sm font-medium text-center",children:t.name}),(0,r.jsxs)("div",{className:"flex gap-2 justify-end w-[140px]",children:[(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("div",{className:"text-xs text-gray-500 mb-1 text-center",children:"min"}),(0,r.jsx)("input",{type:"text",placeholder:"Min",className:"border rounded p-1.5 w-16 text-sm text-center ".concat(a&&(null==(n=_[t.name])?void 0:n.min)?"border-red-500":""),...F("".concat(t.name,".min"),{onChange:e=>T(t.name,"min",e.target.value)}),disabled:e}),a&&(null==(l=_[t.name])?void 0:l.min)&&(0,r.jsx)("div",{className:"absolute -bottom-4 left-0 text-xs text-red-500 text-center w-full",children:"Required"})]}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("div",{className:"text-xs text-gray-500 mb-1 text-center",children:"max"}),(0,r.jsx)("input",{type:"text",placeholder:"Max",className:"border rounded p-1.5 w-16 text-sm text-center ".concat(a&&(null==(c=_[t.name])?void 0:c.max)?"border-red-500":""),...F("".concat(t.name,".max"),{onChange:e=>T(t.name,"max",e.target.value)}),disabled:e}),a&&(null==(i=_[t.name])?void 0:i.max)&&(0,r.jsx)("div",{className:"absolute -bottom-4 left-0 text-xs text-red-500 text-center w-full",children:"Required"})]})]}),e&&(0,r.jsxs)("div",{className:"flex justify-end ml-auto w-[120px]",children:[(0,r.jsxs)("div",{className:"w-16",children:[(0,r.jsx)("div",{className:"text-xs text-gray-500 mb-1 text-center",children:"actual"}),(0,r.jsxs)("div",{className:"text-center text-sm",children:[t.population.toFixed(0),"M"]})]}),(0,r.jsxs)("div",{className:"w-12 ml-2",children:[(0,r.jsx)("div",{className:"text-xs text-gray-500 mb-1 text-center",children:"score"}),(0,r.jsx)("div",{className:"text-center text-sm",title:"Score for this guess",children:(null==(d=o[t.name])?void 0:d.score).toFixed(0)})]})]})]},t.name)})}),(0,r.jsx)("div",{className:"mt-6 text-center",children:e?(0,r.jsx)("div",{className:"space-y-2",children:(0,r.jsxs)("div",{className:"text-lg",children:["Total Score:"," ",(Object.values(o).filter(e=>!e.isCorrect).length<=1?Object.values(o).reduce((e,t)=>{let{score:a}=t;return e+a},0):0).toFixed(1)," ",(0,r.jsx)("p",{className:"mx-auto mt-2 max-w-xs text-sm text-gray-500 text-balance",children:P()?"Congratulations! Most players are overconfident and lose!":"No worries. The large majority of players are also overconfident and lose! This is an exercise to better understand that 90% confidence means choosing LARGE intervals."})]})}):(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"flex flex-row items-center justify-center gap-4 w-full max-w-sm mx-auto",children:[(0,r.jsx)("input",{type:"text",placeholder:"Your name (optional)",className:"w-full border rounded p-2 text-sm",value:b,onChange:e=>v(e.target.value)}),(0,r.jsx)(n.T,{type:"button",color:"primary",variant:k?"solid":"flat",onPress:()=>{l(!0),M(D)()},isLoading:R,isDisabled:R,className:"w-full",children:R?"Processing...":"Reveal Answers"}),a&&!k&&(0,r.jsx)("p",{className:"mt-2 text-sm text-red-500",children:"Please fill in all fields with valid numbers"})]})})})]}),e&&(0,r.jsxs)("div",{className:"mt-8",children:[(0,r.jsx)("h2",{className:"text-xl font-bold mb-4",children:"Top Scores"}),(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)("table",{className:"min-w-full border border-gray-200",children:[(0,r.jsx)("thead",{className:"bg-gray-50",children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Rank"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Player"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Score"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Date"})]})}),(0,r.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:g.map((e,t)=>(0,r.jsxs)("tr",{className:"".concat(t%2==0?"bg-white":"bg-gray-50"," ").concat(e.id===w?"bg-blue-50":""),children:[(0,r.jsx)("td",{className:"px-4 py-2 text-sm",children:e.id===w?"*":t+1}),(0,r.jsx)("td",{className:"px-4 py-2 text-sm",children:e.player}),(0,r.jsx)("td",{className:"px-4 py-2 text-sm",children:e.score.toFixed(1)}),(0,r.jsx)("td",{className:"px-4 py-2 text-sm",children:new Date(e.createdAt).toLocaleDateString()})]},e.id))})]})}),j&&(0,r.jsx)("p",{className:"mt-2 text-sm text-gray-500",children:"Loading scores..."})]})]})}},54499:(e,t,a)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),!function(e,t){for(var a in t)Object.defineProperty(e,a,{enumerable:!0,get:t[a]})}(t,{callServer:function(){return r.callServer},createServerReference:function(){return n},findSourceMapURL:function(){return s.findSourceMapURL}});let r=a(51744),s=a(43636),n=a(96521).createServerReference},92217:(e,t,a)=>{"use strict";a.d(t,{Z:()=>s});var r=a(54499);let s=(0,r.createServerReference)("404474be0fd23db44b0027d93c3bb4a392b1dead74",r.callServer,void 0,r.findSourceMapURL,"sendEmail")}},e=>{var t=t=>e(e.s=t);e.O(0,[915,8206,5406,6149,1004,6306,7358],()=>t(8115)),_N_E=e.O()}]);