Skip to content

Commit

Permalink
2019 day 23
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Dec 12, 2024
1 parent 51eff29 commit 89a6b04
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 90 deletions.
15 changes: 13 additions & 2 deletions 2019/17/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ export async function taskTwo(input: string[]): Promise<void> {
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)


Expand All @@ -58,6 +65,10 @@ export async function taskTwo(input: string[]): Promise<void> {
id: number,
way: string[]
}

function splitPath(path: string): { r: 'false' } | { r: 'maybe', } {

}
}

function buildGrid(nums: number[]): [string[], number[]] {
Expand Down
186 changes: 101 additions & 85 deletions 2019/23/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,110 +158,126 @@ export async function taskTwo(input: string[]): Promise<void> {
const is: number[] = Array.from({length: 50}, () => 0)
const relBases: number[] = Array.from({length: 50}, () => 0)
const inputs: Queue<number>[] = Array.from({length: 50}, () => new Queue<number>())
const outputs: number[][] = Array.from({length: 50}, () => [])
const outputs: number[][] = Array.from({length: 50}, () => [])
let NAT = [-1, -1]
let lastNumbers
let lastNumbers = new Set<number>()

for (let unit = 0; unit < 50; unit++) {
inputs[unit].push(unit)
}


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])


}
}

Expand Down
2 changes: 1 addition & 1 deletion 2019/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,7 +45,7 @@ Whatever I feel like today. But it will most likely either be Java, Python, C++,

<h3><a href="2019/README.md">2019</a></h3>

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

<h3><a href="2018/README.md">2019</a></h3>

Expand Down

0 comments on commit 89a6b04

Please sign in to comment.