PageSourceSearch

https://fast-check.dev/assets/js/7553b32f.0f3f279c.js

js fast-check.dev collected 2026-10-02 04:23:14 UTC 17,461 bytes, 174 lines download raw bytes

1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["32523"],{94187(e,t,r){r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>p,frontMatter:()=>n,metadata:()=>a,toc:()=>d});var a=r(27921),o=r(61058),s=r(24801);r(89949),r(23932);let n={title:"Advent of PBT 2024 \xb7 Day 2",authors:["dubzzz"],tags:["advent-of-pbt","advent-of-pbt-2024"]},i,l={authorsImageUrls:[void 0]},d=[];function c(e){let t={p:"p",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:"Christmas is at risk! In their rush to meet tight deadlines, Santa\u2019s elves accidentally introduced bugs into critical algorithms. If these issues aren\u2019t discovered in time, Christmas could be delayed for everyone worldwide!"}),"\n",(0,o.jsx)(t.p,{children:"Your mission is to troubleshoot these black-box algorithms using the power of fast-check."}),"\n",(0,o.jsx)(t.p,{children:"The clock is ticking. Santa just pinged you with your next challenge: he\u2019s worried that some children might be receiving duplicate responses \u2014 and possibly double the gifts! Santa suspects something is wrong with the way duplicates are handled by elves. Can you investigate and ensure everyone gets exactly what they deserve? \u{1F384}\u{1F527}"})]})}function p(e={}){let{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},30306(e,t,r){r.d(t,{p:()=>c});var a=r(61058),o=r(13706),s=r(35558),n=r(77658),i=r(75312);function l(e){let{functionName:t,signature:r,signatureExtras:s,snippet:l,day:d}=e,c=(0,o.useId)(),p=`stackblitz-${c}`,u=(0,o.useRef)(null),h=[...(s??[]).map(e=>`declare ${e}`),`declare function ${r}`,`export default ${t}`].join("\n"),m=["import { test, expect } from 'vitest';","import fc from 'fast-check';",`import ${t} from './advent.js';`,"",...(s??[]).map(e=>`// declare ${e}`),`// declare function ${r}`,"test('helping Santa', () => {","  fc.assert(fc.property(fc.constant('noop'), (noop) => {","  }));","})"].join("\n");return(0,o.useEffect)(()=>{let e=u.current;if(null!==e)return(async()=>{let t={name:`advent-of-pbt-day${d}`,private:!0,scripts:{test:"vitest"},devDependencies:{"fast-check":"latest",typescript:"latest",vitest:"latest"},stackblitz:{installDependencies:!0,startCommand:"npx vitest --watch --reporter=verbose"}};await i.A.embedProject(e,{title:`Advent of PBT - Day ${d}`,description:"Advent of PBT puzzle powered by Vitest",template:"node",files:{"advent.js":l,"advent.d.ts":h,"advent.test.ts":m,"package.json":JSON.stringify(t,null,2)}},{height:600,openFile:"advent.test.ts",hideExplorer:!0,view:"editor"})})(),()=>{e.innerHTML=""}},[l,h,m,d]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{ref:u,id:p}),(0,a.jsx)(n.A,{type:"note",children:(0,a.jsxs)("p",{children:["Can\u2019t access the online playground? Prefer to run it locally?",(0,a.jsx)("br",{}),"No problem! You can download the source file"," ",(0,a.jsx)("a",{download:`advent-day-${String(d).padStart(2,"0")}.mjs`,href:`data:application/octet-stream;base64,${btoa(Array.from(new TextEncoder().encode(l),e=>String.fromCharCode(e)).join(""))}`,children:"here"}),"."]})})]})}let d="answer";function c(e){let{day:t,buggyAdvent:r,snippet:i,buggyAdventSurcharged:c,referenceAdvent:p,postAdvent:u=e=>e,parser:h,placeholderForm:m,functionName:f,signature:b,signatureExtras:v}=e,y=null,g=`aopbt24-day${t}`;return{AdventPlaygroundOfTheDay:function(){return(0,a.jsx)(l,{functionName:f,signature:b,signatureExtras:v,snippet:i,day:t})},FormOfTheDay:function(){let[,e]=(0,o.useState)(Symbol()),t=null===y?function(){try{let e=localStorage.getItem(g);if(null===e)return null;let t=h(e);if(void 0===t||(0,s.isEqual)(u((c??r)(...t)),u(p(...t))))return null;return e}catch(e){return null}}():null;return(0,a.jsxs)(a.Fragment,{children:[null!==t&&(0,a.jsxs)(n.A,{type:"tip",icon:"\u{1F389}",title:"Congratulations",children:[(0,a.jsx)("p",{children:"You solved this puzzle!"}),(0,a.jsx)("p",{children:(0,a.jsx)("a",{href:`https://bsky.app/intent/compose?text=${encodeURIComponent(`Just solved the #AdventOfPBT puzzle made by @fast-check.dev \xb7 \u{1F449} Join the challenge: ${window.location.href}`)}`,target:"_blank",rel:"noreferrer noopener",children:"Share your success on Bluesky \u{1F389}"})})]}),null!==y&&(0,a.jsx)(n.A,{type:"danger",children:(0,a.jsx)("p",{children:y})}),(0,a.jsxs)("form",{onSubmit:t=>{!function(e){e.preventDefault();try{let t=function(e){let t=e.currentTarget.elements;if(!(d in t))throw Error(`No ${JSON.stringify(d)} field attached to the form`);let r=t[d].value;if("string"!=typeof r)throw Error(`${JSON.stringify(d)} field attached to the form must be of type string`);return r}(e),a=h(t);if(void 0===a){y="Malformed inputs provided!";return}if((0,s.isEqual)(u((c??r)(...a)),u(p(...a)))){y="The input you provided seems to be working well: Santa is looking for a bug!";return}y=null,localStorage.setItem(g,t)}catch(e){y=`Malformed inputs provided!
2${e.message}`}}(t),e(Symbol())},children:[(0,a.jsx)("textarea",{name:d,style:{width:"100%",...null!==t?{backgroundColor:"lightgreen"}:{}},rows:5,defaultValue:t??void 0,placeholder:`Example of answer:
3${m}`}),(0,a.jsx)("br",{}),(0,a.jsx)("button",{type:"submit",children:"Submit"})]})]})}}}},23932(e,t,r){r.d(t,{A:()=>n});var a=r(61058),o=r(13706);let s=!1;function n({url:e}){return((0,o.useLayoutEffect)(()=>{"u">typeof HTMLElement&&function(){if(!s){s=!0;class e extends HTMLElement{static properties={url:{type:String}};#e;#t=!1;constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML=`
4    <style>
5      :host {
6        --bluesky-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
7        --bluesky-font-size: 16px;
8          --bluesky-text-color: #333;
9        --bluesky-handle-color: #888;
10        --bluesky-footer-text-color: rgb(111, 134, 159);
11          --bluesky-bg-color: #fff;
12        --bluesky-hover-bg: #f0f0f0;
13        --bluesky-spacing-xs: 5px;
14        --bluesky-spacing-sm: 8px;
15        --bluesky-spacing-md: 10px;
16        --bluesky-spacing-lg: 15px;
17        --bluesky-avatar-size: 24px;
18        --bluesky-avatar-bg: #e0e0e0;
19  
20        /* Comments Structure */
21        --bluesky-reply-border-width: 2px;
22  
23        /* Footer */
24        --bluesky-footer-font-size: 15px;
25        --bluesky-icon-size: 18px;
26        --bluesky-border-color: #e0e0e0;
27  
28      }
29  
30      /* Container Styles */
31      .comments {
32        font-family: var(--bluesky-font-family);
33          font-size: var(--bluesky-font-size);
34          background-color: var(--bluesky-bg-color);
35        border: 1px solid var(--bluesky-border-color);
36        color: var(--bluesky-text-color);
37      }
38  
39      /* Comment Structure */
40      .comment {
41        border-bottom: 1px solid var(--bluesky-border-color);
42        padding-top: var(--bluesky-spacing-lg);
43      }
44  
45      .comment.reply {
46        border-left: var(--bluesky-reply-border-width) solid var(--bluesky-border-color);
47        margin-left: var(--bluesky-spacing-lg);
48      padding-top: var(--bluesky-spacing-xs);
49      }
50  
51      .comment:last-child {
52        border-bottom: none;
53      }
54  
55    .comment-content {
56      padding: var(--bluesky-spacing-xs) 0;
57    }
58  
59      .avatar {
60        width: var(--bluesky-avatar-size);
61        height: var(--bluesky-avatar-size);
62        border-radius: 50%;
63        object-fit: cover;
64        border: 1px solid var(--bluesky-border-color);
65      }
66  
67      .default-avatar {
68        width: var(--bluesky-avatar-size);
69        height: var(--bluesky-avatar-size);
70        border-radius: 50%;
71        background-color: var(--bluesky-avatar-bg);
72      }
73  
74      .comment-header {
75        display: flex;
76        align-items: center;
77        gap: var(--bluesky-spacing-md);
78        padding: 0 var(--bluesky-spacing-lg);
79      }
80  
81  
82      .comment-footer {
83        display: flex;
84        justify-content: space-between;
85        align-items: center;
86        margin-bottom: var(--bluesky-spacing-xs);
87        font-size: var(--bluesky-footer-font-size);
88        color: var(--bluesky-footer-text-color);
89        padding: var(--bluesky-spacing-xs);
90      }
91  
92      .comment-footer div {
93        display: flex;
94        align-items: center;
95        gap: var(--bluesky-spacing-xs);
96      }
97  
98      .comment-link {
99        display: flex;
100        flex-direction: column;
101        color: inherit;
102        text-decoration: none;
103        padding: 0 var(--bluesky-spacing-lg);
104      }
105  
106      .profile-link {
107        color: var(--bluesky-text-color);
108          font-weight: 600;
109        text-decoration: none;
110      }
111  
112      .timestamp-link,
113      .handle-link {
114        color: var(--bluesky-handle-color);
115        text-decoration: none;
116      }
117  
118      .comment-link:hover,
119      .comment-footer:hover {
120        background-color: var(--bluesky-hover-bg);
121      }
122  
123      .profile-link:hover {
124          text-decoration: underline;
125      }
126  
127      .handle {
128        color: var(--bluesky-handle-color);
129      }
130  
131      .comment-footer svg {
132        width: var(--bluesky-icon-size);
133        height: var(--bluesky-icon-size);
134        color: var(--bluesky-footer-text-color);
135      }
136    </style>
137    <div class="comments"></div>
138      `,this.#e=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&!this.#t&&(this.#r(),this.#t=!0,this.#e.disconnect())})},{threshold:.1})}connectedCallback(){this.#e.observe(this)}disconnectedCallback(){this.#e.disconnect()}async #r(){let e=this.getAttribute("url");if(e)try{let t=await this.#a(e);if(!t)throw Error("Failed to resolve AT URI");let r=await this.#o(t);this.#s(r)}catch(e){this.shadowRoot.querySelector(".comments").innerHTML="<p>Error loading comments.</p>"}else this.shadowRoot.querySelector(".comments").innerHTML="<p>No Bluesky URL provided.</p>"}async #a(e){if(e.startsWith("at:"))return e;if(!e.startsWith("https://bsky.app/"))return;let t=new URL(e).pathname.split("/"),r=t[2],a=t[4];if(r&&a){if(!r.startsWith("did:")){let e=this.#n(`handle:${r}`);if(e)r=e;else try{let e=`https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(r)}`,t=await fetch(e);if(!t.ok)throw Error("Failed to resolve handle");let a=await t.json();if(!a.did)return;this.#i(`handle:${r}`,a.did,86400),r=a.did}catch(e){console.error(`[error] Failed to resolve handle: ${e.message||e}`);return}}return`at://${r}/app.bsky.feed.post/${a}`}}#i(e,t,r=86400){let a=Date.now()+1e3*r;localStorage.setItem(e,JSON.stringify({value:t,expiry:a}))}#n(e){let t=localStorage.getItem(e);if(!t)return null;let{value:r,expiry:a}=JSON.parse(t);return Date.now()>a?(localStorage.removeItem(e),null):r}async #o(e){let t=`https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(e)}`,r=await fetch(t);if(!r.ok)throw Error("Failed to fetch replies");return(await r.json()).thread}#s(e,t=null){let r=t||this.shadowRoot.querySelector(".comments");e&&e.replies&&e.replies.length>0?e.replies.sort((e,t)=>
138new Date(e.post.record.createdAt).getTime()-new Date(t.post.record.createdAt).getTime()).forEach(e=>{this.#l(e,r,!1)}):this.shadowRoot.querySelector(".comments").innerHTML=`<p><a href=${JSON.stringify(this.getAttribute("url"))} target="_blank" rel="noopener">Add the first comment</a></p>`}#d(e){let t=document.createElement("div");return t.textContent=e,t.innerHTML}#l(e,t,r=!1){if(e?.post?.author&&e.post.record){let a;if("\u{1F4CC}"===e.post.record.text.trim())return;let o=document.createElement("div");o.classList.add("comment"),r&&o.classList.add("reply");let s=e.post.author.handle,n=`https://bsky.app/profile/${e.post.author.did}`,i=`https://bsky.app/profile/${e.post.author.did}/post/${e.post.uri.split("/").pop()}`,l=new Date(e.post.record.createdAt),d=l.toLocaleString(),c=this.#c(l),p=e.post?.author?.avatar.replace("/img/avatar/","/img/avatar_thumbnail/"),u=e.post.author.displayName||s,h=e.post.likeCount||0,m=e.post.repostCount||0,f=e.post.replyCount||0;a=p?`<img src="${p}" alt="${s}'s avatar" class="avatar" part="avatar"/>`:'<div class="default-avatar" part="avatar"></div>',o.innerHTML=`
139          <div class="comment-header" part="comment-header">
140            ${a}
141            <div>
142              <a href="${n}" target="_blank" class="profile-link">${this.#d(u)}</a>
143              <span class="handle"><a href="${n}" target="_blank" class="handle-link">@${this.#d(s)}</a></span> -
144              <a href="${i}" target="_blank" rel="ugc" title="${d}" class="timestamp-link">${c}</a>
145            </div>
146          </div>
147          <div class="comment-body" part="comment-body">
148            <a href="${i}" target="_blank" rel="nofollow noopener" class="comment-link">
149              <div class="comment-content" part="comment-content">
150                ${this.#d(e.post.record.text)}
151              </div>
152              <div class="comment-footer" part="comment-footer">
153                <div>
154                  <svg viewBox="0 0 24 24">
155                    <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M2.002 6a3 3 0 0 1 3-3h14a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3H12.28l-4.762 2.858A1 1 0 0 1 6.002 21v-2h-1a3 3 0 0 1-3-3V6Zm3-1a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h2a1 1 0 0 1 1 1v1.234l3.486-2.092a1 1 0 0 1 .514-.142h7a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-14Z"></path>
156                  </svg>
157                  <span>${f}</span>
158                </div>
159                <div>
160                  <svg viewBox="0 0 24 24">
161                    <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M17.957 2.293a1 1 0 1 0-1.414 1.414L17.836 5H6a3 3 0 0 0-3 3v3a1 1 0 1 0 2 0V8a1 1 0 0 1 1-1h11.836l-1.293 1.293a1 1 0 0 0 1.414 1.414l2.47-2.47a1.75 1.75 0 0 0 0-2.474l-2.47-2.47ZM20 12a1 1 0 0 1 1 1v3a3 3 0 0 1-3 3H6.164l1.293 1.293a1 1 0 1 1-1.414 1.414l-2.47-2.47a1.75 1.75 0 0 1 0-2.474l2.47-2.47a1 1 0 0 1 1.414 1.414L6.164 17H18a1 1 0 0 0 1-1v-3a1 1 0 0 1 1-1Z"></path>
162                  </svg>
163                  <span>${m}</span>
164                </div>
165                <div>
166                  <svg viewBox="0 0 24 24">
167                    <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M16.734 5.091c-1.238-.276-2.708.047-4.022 1.38a1 1 0 0 1-1.424 0C9.974 5.137 8.504 4.814 7.266 5.09c-1.263.282-2.379 1.206-2.92 2.556C3.33 10.18 4.252 14.84 12 19.348c7.747-4.508 8.67-9.168 7.654-11.7-.541-1.351-1.657-2.275-2.92-2.557Zm4.777 1.812c1.604 4-.494 9.69-9.022 14.47a1 1 0 0 1-.978 0C2.983 16.592.885 10.902 2.49 6.902c.779-1.942 2.414-3.334 4.342-3.764 1.697-.378 3.552.003 5.169 1.286 1.617-1.283 3.472-1.664 5.17-1.286 1.927.43 3.562 1.822 4.34 3.764Z"></path>
168                  </svg>
169                  <span>${h}</span>
170                </div>
171              </div>
172            </a>
173          </div>
174        `,t.appendChild(o),e.replies&&e.replies.length>0&&e.replies.sort((e,t)=>new Date(e.post.record.createdAt).getTime()-new Date(t.post.record.createdAt).getTime()).forEach(e=>{this.#l(e,o,!0)})}}#c(e){let t=Math.floor((new Date().getTime()-e)/1e3),r=Math.floor(t/60),a=Math.floor(r/60),o=Math.floor(a/24);return o>0?`${o}d`:a>0?`${a}h`:r>0?`${r}m`:`${t}s`}}customElements.define("bluesky-comments",e)}}()},[]),e)?(0,a.jsx)("bluesky-comments",{url:e}):null}},89949(e,t,r){r.d(t,{l:()=>o,S:()=>a});let{AdventPlaygroundOfTheDay:a,FormOfTheDay:o}=(0,r(30306).p)({day:2,buggyAdvent:function(e){let t={};return e.filter(e=>!t[e.id]&&(t[e.id]=!0,!0))},snippet:function(e){let t={};return e.filter(e=>!t[e.id]&&(t[e.id]=!0,!0))},referenceAdvent:function(e){let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},parser:function(e){let t=[];for(let r of e.split("\n")){let e=JSON.parse(r);if("string"!=typeof e)throw Error('Each line of the answer should follow the pattern: "quoted-string-being-the-id"');t.push({id:e})}return[t]},placeholderForm:'"first-id"\n"second-id-with\\xA0fancy\\ncharacters\\u{1f431}"\n"with escaped \\" double quotes"',functionName:"dropLettersFromDuplicatedSenders",signature:"function dropLettersFromDuplicatedSenders(letters: Letter[]): Letter[];",signatureExtras:["type Letter = { id: string };"]})},27921(e){e.exports=JSON.parse('{"permalink":"/blog/2024/12/02/advent-of-pbt-day-2","source":"@site/blog/2024-12-02-advent-of-pbt-day-2/index.md","title":"Advent of PBT 2024 \xb7 Day 2","description":"Christmas is at risk! In their rush to meet tight deadlines, Santa\u2019s elves accidentally introduced bugs into critical algorithms. If these issues aren\u2019t discovered in time, Christmas could be delayed for everyone worldwide!","date":"2024-12-02T00:00:00.000Z","tags":[{"inline":true,"label":"advent-of-pbt","permalink":"/blog/tags/advent-of-pbt"},{"inline":true,"label":"advent-of-pbt-2024","permalink":"/blog/tags/advent-of-pbt-2024"}],"readingTime":1.82,"hasTruncateMarker":true,"authors":[{"name":"Nicolas Dubien","title":"fast-check maintainer","url":"https://github.com/dubzzz","socials":{"bluesky":"https://bsky.app/profile/nicolas.dubien.me","github":"https://github.com/dubzzz","linkedin":"https://www.linkedin.com/in/nicolas-dubien-623a9342/"},"imageURL":"/img/_/avatar_48_dubzzz.jpg","key":"dubzzz","page":null}],"frontMatter":{"title":"Advent of PBT 2024 \xb7 Day 2","authors":["dubzzz"],"tags":["advent-of-pbt","advent-of-pbt-2024"]},"unlisted":false,"prevItem":{"title":"Advent of PBT 2024 \xb7 Day 3","permalink":"/blog/2024/12/03/advent-of-pbt-day-3"},"nextItem":{"title":"Advent of PBT 2024 \xb7 Day 1","permalink":"/blog/2024/12/01/advent-of-pbt-day-1"}}')}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.