Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/content/communitySolutions/04/dallinstevens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
descriptions: ["deno"]
---

### 2025 Solution Deno

### Output

```
Total Time: 2803
```

```ts
const EPSILON = 1e-9;

class Elf {
effeciency: number;
timeLeftOnPresent: number = 0;
hasPresent: boolean = false;

constructor(effeciency: number) {
this.effeciency = effeciency;
}

processPresent() {
this.timeLeftOnPresent -= this.effeciency;
if (this.timeLeftOnPresent <= EPSILON) {
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;
}
if (elf.hasPresent) {
elf.processPresent();
elvesStillWorking = true;
}
}
if (elvesStillWorking) {
time++;
}
}
console.log(time);
}
```