-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from hildjj/day25
Day 25
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
schemata = (lock / key)|.., "\n"| | ||
|
||
lock = "#####" "\n" rows:row+ { return {type: 'lock', rows, h: []}} | ||
|
||
key = rows:row+ { return { type: 'key', rows: rows.slice(0, -1), h: []}} | ||
|
||
row = @[#.]+ "\n" |
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,45 @@ | ||
import { type MainArgs, parseFile } from './lib/utils.ts'; | ||
|
||
interface KeyLock { | ||
type: 'key' | 'lock'; | ||
rows: string[][]; | ||
h: number[]; | ||
} | ||
type Parsed = KeyLock[]; | ||
|
||
function fits(key: number[], lock: number[]): boolean { | ||
for (let i = 0; i < 5; i++) { | ||
if (key[i] + lock[i] > 5) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function part1(inp: Parsed): number { | ||
for (const i of inp) { | ||
for (let col = 0; col < 5; col++) { | ||
let tot = 0; | ||
for (let row = 0; row < i.rows.length; row++) { | ||
if (i.rows[row][col] === '#') { | ||
tot++; | ||
} | ||
} | ||
i.h.push(tot); | ||
} | ||
} | ||
let count = 0; | ||
for (const key of inp.filter(({ type }) => type === 'key')) { | ||
for (const lock of inp.filter(({ type }) => type === 'lock')) { | ||
if (fits(key.h, lock.h)) { | ||
count++; | ||
} | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
export default async function main(args: MainArgs): Promise<[number]> { | ||
const inp = await parseFile<Parsed>(args); | ||
return [part1(inp)]; | ||
} |
Submodule inputs
updated
from cc618e to 3f1c03
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 @@ | ||
export default [3397]; |