-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
261 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"label": "Advent of TypeScript 2023", | ||
"message": "7/25", | ||
"message": "8/25", | ||
"color": "orange" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0 3 6 9 12 15 | ||
1 3 6 10 15 21 | ||
10 13 16 21 30 45 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
import { task } from '@alexaegis/advent-of-code-lib'; | ||
import packageJson from '../package.json'; | ||
import { extrapolateSequence, parse } from './parse.js'; | ||
|
||
export const p1 = (_input: string): number => { | ||
return 0; | ||
const extrapolateNextInStack = (sequenceStack: number[][]): number[][] => { | ||
let carry = sequenceStack.last().last(); | ||
for (let i = sequenceStack.length - 1; i >= 0; i--) { | ||
carry = (sequenceStack[i]?.last() ?? 0) + carry; | ||
sequenceStack[i]?.push(carry); | ||
} | ||
return sequenceStack; | ||
}; | ||
|
||
await task(p1, packageJson.aoc); // 0 ~0ms | ||
export const p1 = (input: string): number => | ||
parse(input) | ||
.map(extrapolateSequence) | ||
.map(extrapolateNextInStack) | ||
.map((extrapolatedStack) => extrapolatedStack.first().last()) | ||
.sum(); | ||
|
||
await task(p1, packageJson.aoc); // 1938731307 ~1.57ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
import { task } from '@alexaegis/advent-of-code-lib'; | ||
import packageJson from '../package.json'; | ||
import { extrapolateSequence, parse } from './parse.js'; | ||
|
||
export const p2 = (_input: string): number => { | ||
return 0; | ||
const extrapolatePreviousInStack = (sequenceStack: number[][]): number[][] => { | ||
let carry = sequenceStack.last().first(); | ||
for (let i = sequenceStack.length - 1; i >= 0; i--) { | ||
carry = (sequenceStack[i]?.first() ?? 0) - carry; | ||
sequenceStack[i]?.unshift(carry); | ||
} | ||
return sequenceStack; | ||
}; | ||
|
||
await task(p2, packageJson.aoc); // 0 ~0ms | ||
export const p2 = (input: string): number => | ||
parse(input) | ||
.map(extrapolateSequence) | ||
.map(extrapolatePreviousInStack) | ||
.map((extrapolatedStack) => extrapolatedStack.first().first()) | ||
.sum(); | ||
|
||
await task(p2, packageJson.aoc); // 948 ~1.62ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const parse = (input: string): number[][] => | ||
input.lines(false).map((line) => line.splitToInt()); | ||
|
||
export const extrapolateSequence = (sequence: number[]): number[][] => { | ||
const sequenceStack: number[][] = [sequence]; | ||
while (sequenceStack.last().some((i) => i !== 0)) { | ||
sequenceStack.push( | ||
sequenceStack | ||
.last() | ||
.slideWindow(2, 1) | ||
.map(([left, right]) => right - left), | ||
); | ||
} | ||
return sequenceStack; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters