diff --git a/2019/17/task.ts b/2019/17/task.ts index 9f4136f..60daae5 100644 --- a/2019/17/task.ts +++ b/2019/17/task.ts @@ -41,11 +41,18 @@ export async function taskTwo(input: string[]): Promise { if (right == '#') checkSum += 8 if ([1,2,4,8,15].includes(checkSum)) { intersections.push([x,y]) - } else if (checkSum != 3 && checkSum != 12) { - console.log(checkSum) + } + if ([1,2,4,8].includes(checkSum)) { + console.log('end') } } } + + console.log(rX, rY) + for (const r of grid) { + console.log(r) + } + console.log(intersections.length) @@ -58,6 +65,10 @@ export async function taskTwo(input: string[]): Promise { id: number, way: string[] } + + function splitPath(path: string): { r: 'false' } | { r: 'maybe', } { + + } } function buildGrid(nums: number[]): [string[], number[]] { diff --git a/2019/23/task.ts b/2019/23/task.ts index 5ed2f2e..7225edb 100644 --- a/2019/23/task.ts +++ b/2019/23/task.ts @@ -158,9 +158,9 @@ export async function taskTwo(input: string[]): Promise { const is: number[] = Array.from({length: 50}, () => 0) const relBases: number[] = Array.from({length: 50}, () => 0) const inputs: Queue[] = Array.from({length: 50}, () => new Queue()) - const outputs: number[][] = Array.from({length: 50}, () => []) + const outputs: number[][] = Array.from({length: 50}, () => []) let NAT = [-1, -1] - let lastNumbers + let lastNumbers = new Set() for (let unit = 0; unit < 50; unit++) { inputs[unit].push(unit) @@ -168,100 +168,116 @@ export async function taskTwo(input: string[]): Promise { while (true) { + let successfullIO = false for (let unit = 0; unit < 50; unit++) { - const i = is[unit] - if(lists[unit][i] != 99) { - const op = lists[unit][i] % 100 - switch (op) { - case 1: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) - lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c + b - is[unit]+=4 - break - - } - case 2: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) - lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c * b - is[unit]+=4 - break - } - case 3: { - if(inputs[unit].isEmpty()) { - lists[unit][getGoalIndex(i+1, getAtDigit(lists[unit][i], 100), unit)] = -1 - } else { - lists[unit][getGoalIndex(i+1, getAtDigit(lists[unit][i], 100), unit)] = inputs[unit].pop() + let breakOuter = false; + if(lists[unit][is[unit]] != 99) { + while (!breakOuter) { + const i = is[unit] + const op = lists[unit][i] % 100 + switch (op) { + case 1: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) + lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c + b + is[unit]+=4 + break + } - is[unit] += 2 - break - } - case 4: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - outputs[unit].push(c) - if (outputs[unit].length == 3) { - const goal = outputs[unit][0] - const x = outputs[unit][1] - const y = outputs[unit][2] - outputs[unit] = [] - if (goal == 255) { - NAT = [x,y] + case 2: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) + lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c * b + is[unit]+=4 + break + } + case 3: { + if(inputs[unit].isEmpty()) { + lists[unit][getGoalIndex(i+1, getAtDigit(lists[unit][i], 100), unit)] = -1 + breakOuter = true } else { - inputs[goal].push(x) - inputs[goal].push(y) + lists[unit][getGoalIndex(i+1, getAtDigit(lists[unit][i], 100), unit)] = inputs[unit].pop() + successfullIO = true } + is[unit] += 2 + break } - is[unit] += 2 - break - } - case 5: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) - if (c != 0) { - is[unit] = b - } else { - is[unit] += 3 + case 4: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + outputs[unit].push(c) + if (outputs[unit].length == 3) { + const goal = outputs[unit][0] + const x = outputs[unit][1] + const y = outputs[unit][2] + outputs[unit] = [] + if (goal == 255) { + NAT = [x,y] + } else { + inputs[goal].push(x) + inputs[goal].push(y) + } + } + successfullIO = true + is[unit] += 2 + break } - break - } - case 6: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) - if (c == 0) { - is[unit] = b - } else { - is[unit] += 3 + case 5: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) + if (c != 0) { + is[unit] = b + } else { + is[unit] += 3 + } + break + } + case 6: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) + if (c == 0) { + is[unit] = b + } else { + is[unit] += 3 + } + break + } + case 7: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) + lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c < b ? 1:0 + is[unit] += 4 + break + } + case 8: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) + lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c == b ? 1:0 + is[unit] += 4 + break + } + case 9: { + const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) + relBases[unit] += c + is[unit]+=2 + break + } + default: { + throw `${unit} ${i} ${lists[unit][i]}` } - break - } - case 7: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) - lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c < b ? 1:0 - is[unit] += 4 - break - } - case 8: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - const b = getVal(i+2, getAtDigit(lists[unit][i], 1000), unit) - lists[unit][getGoalIndex(i+3, getAtDigit(lists[unit][i], 10000), unit)] = c == b ? 1:0 - is[unit] += 4 - break - } - case 9: { - const c = getVal(i+1, getAtDigit(lists[unit][i], 100), unit) - relBases[unit] += c - is[unit]+=2 - break - } - default: { - throw i } } } + } + + if (!successfullIO) { + if (lastNumbers.has(NAT[1])) { + console.log(NAT[1]) + return + } + lastNumbers.add(NAT[1]) + inputs[0].push(NAT[0]) + inputs[0].push(NAT[1]) - } } diff --git a/2019/README.md b/2019/README.md index e6aab0e..399da12 100644 --- a/2019/README.md +++ b/2019/README.md @@ -1,4 +1,4 @@ # 2019 -![](https://img.shields.io/badge/stars%20⭐-46-yellow) +![](https://img.shields.io/badge/stars%20⭐-47-yellow) Puzzles not solved during event. \ No newline at end of file diff --git a/README.md b/README.md index ec91906..6ae1bcf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # My Advent of Code Solutions -![](https://img.shields.io/badge/Total%20stars%20⭐-470yellow) +![](https://img.shields.io/badge/Total%20stars%20⭐-471yellow) ## What language do I use? Whatever I feel like today. But it will most likely either be Java, Python, C++, Typescript or Haskell @@ -45,7 +45,7 @@ Whatever I feel like today. But it will most likely either be Java, Python, C++,

2019

-![](https://img.shields.io/badge/stars%20⭐-46yellow) +![](https://img.shields.io/badge/stars%20⭐-47-yellow)

2019