Compare commits
2 Commits
9f9b14fb7b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dc8ec1ca17 | |||
| eb0ae6d56b |
48
2024/23/index2.ts
Normal file
48
2024/23/index2.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt', 'utf8');
|
||||
|
||||
const connections: { [key: string]: Array<string> }= {};
|
||||
|
||||
input.split("\n").forEach((conn: string) => {
|
||||
const [c1, c2] = conn.split('-');
|
||||
connections[c1] = [c2, ...(connections[c1] || [])]
|
||||
connections[c2] = [c1, ...(connections[c2] || [])]
|
||||
});
|
||||
|
||||
let nets: Set<string> = new Set;
|
||||
|
||||
for (let key in connections) {
|
||||
const conns = connections[key];
|
||||
conns.forEach((c2) => {
|
||||
connections[c2].forEach((c3) => {
|
||||
if (connections[c3].includes(key)) {
|
||||
const arr = [key, c2, c3];
|
||||
arr.sort();
|
||||
nets.add(arr.join(','));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
while (nets.size > 1) {
|
||||
const nextNets: Set<string> = new Set;
|
||||
for (let net of nets) {
|
||||
const cps = net.split(',');
|
||||
for (let i in connections) {
|
||||
if (cps.includes(i)) {
|
||||
continue;
|
||||
}
|
||||
const conns = connections[i];
|
||||
if (cps.every((id) => conns.includes(id))) {
|
||||
const newNet = [...cps, i];
|
||||
newNet.sort();
|
||||
nextNets.add(newNet.join(','));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nets = nextNets;
|
||||
}
|
||||
|
||||
console.log(nets);
|
||||
44
2024/25/index.ts
Normal file
44
2024/25/index.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt', 'utf8');
|
||||
|
||||
const keyLocks = input.split("\n\n");
|
||||
|
||||
const keys: number[][] = [];
|
||||
const locks: number[][] = [];
|
||||
|
||||
keyLocks.forEach((s: string) => {
|
||||
const rows = s.split("\n");
|
||||
const isKey = rows[0] === '.....';
|
||||
const columns: number[] = [-1, -1, -1, -1, -1];
|
||||
rows.forEach((row: string) => {
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i] === '#') {
|
||||
columns[i]++;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isKey) {
|
||||
keys.push(columns);
|
||||
} else {
|
||||
locks.push(columns);
|
||||
}
|
||||
});
|
||||
|
||||
let matches = 0;
|
||||
|
||||
for (let lock of locks) {
|
||||
keyLoop:
|
||||
for (let key of keys) {
|
||||
for (let i in lock) {
|
||||
if (lock[i] + key[i] >= 6) {
|
||||
continue keyLoop;
|
||||
}
|
||||
}
|
||||
matches++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(locks);
|
||||
console.log(keys);
|
||||
console.log(matches);
|
||||
Reference in New Issue
Block a user