From 8ca9a75099381ba420838fc7bf258fedbfbec02c Mon Sep 17 00:00:00 2001 From: Dallin Stevens Date: Wed, 3 Dec 2025 21:25:02 -0700 Subject: [PATCH 1/3] day 04 --- .../communitySolutions/04/dallinstevens.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/content/communitySolutions/04/dallinstevens.md diff --git a/src/content/communitySolutions/04/dallinstevens.md b/src/content/communitySolutions/04/dallinstevens.md new file mode 100644 index 0000000..8d149ae --- /dev/null +++ b/src/content/communitySolutions/04/dallinstevens.md @@ -0,0 +1,56 @@ +--- +descriptions: ["deno"] +--- + +### 2025 Solution Deno + +```Deno +class Elf { + effeciency: number; + timeLeftOnPresent: number = 0; + hasPresent: boolean = false; + + constructor(effeciency: number) { + this.effeciency = effeciency; + } + + processPresent() { + this.timeLeftOnPresent -= this.effeciency; + if (this.timeLeftOnPresent <= 0) { + this.hasPresent = false; + } + } + + assignPresent(presentTime: number) { + this.timeLeftOnPresent = presentTime + this.effeciency; // one minute to grab present regardless of efficiency + this.hasPresent = true; + } +} + +if (import.meta.main) { + const presents = (await Deno.readTextFile("presents.txt")).split(" "); + + const elves = [new Elf(1.4), new Elf(0.7), new Elf(1.1), new Elf(1.0)]; + + let time = 0; + let elvesStillWorking = true; + + while (presents.length > 0 || elvesStillWorking) { + + elvesStillWorking = false; + for (const elf of elves) { + if (!elf.hasPresent && presents.length !== 0) { + const p = presents.shift(); + elf.assignPresent(Number(p)); + elvesStillWorking = true; + } + else if (elf.hasPresent) { + elf.processPresent(); + elvesStillWorking = true; + } + } + time++; + } + console.log(time); +} +``` From 570cc5d307772730259668735d8bb86972ec40d0 Mon Sep 17 00:00:00 2001 From: Dallin Stevens Date: Wed, 10 Dec 2025 23:03:52 -0700 Subject: [PATCH 2/3] update 05 with fix --- .../communitySolutions/04/dallinstevens.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/content/communitySolutions/04/dallinstevens.md b/src/content/communitySolutions/04/dallinstevens.md index 8d149ae..01199a3 100644 --- a/src/content/communitySolutions/04/dallinstevens.md +++ b/src/content/communitySolutions/04/dallinstevens.md @@ -4,7 +4,9 @@ descriptions: ["deno"] ### 2025 Solution Deno -```Deno +```ts +const EPSILON = 1e-9; + class Elf { effeciency: number; timeLeftOnPresent: number = 0; @@ -14,9 +16,9 @@ class Elf { this.effeciency = effeciency; } - processPresent() { + processPresent() { this.timeLeftOnPresent -= this.effeciency; - if (this.timeLeftOnPresent <= 0) { + if (this.timeLeftOnPresent <= EPSILON) { this.hasPresent = false; } } @@ -36,7 +38,6 @@ if (import.meta.main) { let elvesStillWorking = true; while (presents.length > 0 || elvesStillWorking) { - elvesStillWorking = false; for (const elf of elves) { if (!elf.hasPresent && presents.length !== 0) { @@ -44,12 +45,14 @@ if (import.meta.main) { elf.assignPresent(Number(p)); elvesStillWorking = true; } - else if (elf.hasPresent) { + if (elf.hasPresent) { elf.processPresent(); elvesStillWorking = true; } - } - time++; + } + if (elvesStillWorking) { + time++; + } } console.log(time); } From 4175c649c9e192649c01bbf5b1f01e6f3e4e0f31 Mon Sep 17 00:00:00 2001 From: Dallin Stevens Date: Wed, 10 Dec 2025 23:06:21 -0700 Subject: [PATCH 3/3] add output --- src/content/communitySolutions/04/dallinstevens.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/content/communitySolutions/04/dallinstevens.md b/src/content/communitySolutions/04/dallinstevens.md index 01199a3..e2123e5 100644 --- a/src/content/communitySolutions/04/dallinstevens.md +++ b/src/content/communitySolutions/04/dallinstevens.md @@ -4,6 +4,12 @@ descriptions: ["deno"] ### 2025 Solution Deno +### Output + +``` +Total Time: 2803 +``` + ```ts const EPSILON = 1e-9;