Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHi committed Dec 12, 2023
1 parent b631f91 commit 7db0087
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
26 changes: 26 additions & 0 deletions Typescript/2023/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Typescript/2023/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
},
"dependencies": {
"data-structure-typed": "^1.48.9",
"fast-memoize": "^2.5.2",
"gauss-shoelace": "^0.1.3",
"lodash": "^4.17.21",
"lodash-decorators": "^6.0.1",
"nunjucks": "^3.2.4",
"ts-2d-geometry": "^6.3.2"
}
Expand Down
31 changes: 25 additions & 6 deletions Typescript/2023/src/days/day12/day12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ export function SolvePartOne(): number {
export function SolvePartTwo(): number {
const readings: Reading[] = parseReadings(true);
let combinationPossibilities = 0;
readings.forEach((reading) => (combinationPossibilities = combinationPossibilities + getPossibleCombinations(reading)));

readings.forEach((reading, i) => {
const start = performance.now();
combinationPossibilities = combinationPossibilities + getPossibleCombinations(reading);
const end = performance.now();
const executionTime = end - start;
console.log(`Execution time for Reading, ${i}: ${executionTime / 1000} seconds`);
});
return combinationPossibilities;
}

Expand Down Expand Up @@ -94,7 +101,7 @@ function parseGroups(input: string): Group[] {

function getPossibleCombinations(reading: Reading): number {
const valid: string[] = [];
const combinatios: string[] = generateCombinations(reading.rawData);
const combinatios: string[] = getCombinations(reading.rawData);
combinatios.forEach((c) => {
const split = getSpringGroupLengths(c);
let isValid = true;
Expand Down Expand Up @@ -135,16 +142,28 @@ function getSpringGroupLengths(input: string): number[] {
return groupLengths;
}

function generateCombinations(input: string, currentIndex: number = 0, currentCombination: string = ""): string[] {
//Split into two for . and #? Cache?
function getCombinations(input: string, currentIndex: number = 0, currentCombination: string = ""): string[] {
if (currentIndex === input.length) {
return [currentCombination];
}
const char = input[currentIndex];
if (char === "?") {
const combinationsWithHash = generateCombinations(input, currentIndex + 1, currentCombination + "#");
const combinationsWithDot = generateCombinations(input, currentIndex + 1, currentCombination + ".");
const combinationsWithHash = getCombinations(input, currentIndex + 1, currentCombination + "#");
const combinationsWithDot = getCombinations(input, currentIndex + 1, currentCombination + ".");
console.log("Combs with has");
console.log(combinationsWithHash);
console.log("Combs with dot");
console.log(combinationsWithDot);
return combinationsWithHash.concat(combinationsWithDot);
} else {
return generateCombinations(input, currentIndex + 1, currentCombination + char);
return getCombinations(input, currentIndex + 1, currentCombination + char);
}
}

// ???.### 1,1,3
// .??..??...?##. 1,1,3
// ?#?#?#?#?#?#?#? 1,3,1,6
// ????.#...#... 4,1,1
// ????.######..#####. 1,6,5
// ?###???????? 3,2,1
7 changes: 1 addition & 6 deletions Typescript/2023/src/days/day12/sample.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1
???.### 1,1,3
2 changes: 1 addition & 1 deletion Typescript/2023/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ if (day === 1) {
console.log("Day 11 Part 02: " + SolvePartTwoD11());
} else if (day === 12) {
console.log("Day 12 Part 01: " + SolvePartOneD12());
console.log("Day 12 Part 02: " + SolvePartTwoD12());
//console.log("Day 12 Part 02: " + SolvePartTwoD12());
}

0 comments on commit 7db0087

Please sign in to comment.