THANK YOU GURKE
This commit is contained in:
parent
1d79c15e2c
commit
6c7bc6c648
1 changed files with 43 additions and 5 deletions
|
@ -6,13 +6,12 @@ import { readInput } from "../utils.ts";
|
|||
class DayFour implements Solvable {
|
||||
input = readInput('04')
|
||||
|
||||
matrix: string[][] = this.input.trim().split('\n').map(line => line.split(''))
|
||||
|
||||
public part1(): Solvable {
|
||||
const matrix = this.matrix
|
||||
|
||||
const transpose = (m: string[][]) => m[0].map((_, i) => m.map(x => x[i]))
|
||||
|
||||
const matrix = this.input.trim().split('\n').map(line => line.split(''))
|
||||
|
||||
function lookAround(x: number, y: number) {
|
||||
const lookAround = (x: number, y: number) => {
|
||||
const allowed = {
|
||||
top: y >= 3,
|
||||
bottom: y <= matrix.length - 4,
|
||||
|
@ -77,6 +76,45 @@ class DayFour implements Solvable {
|
|||
}
|
||||
|
||||
public part2(): Solvable {
|
||||
const matrix = this.matrix
|
||||
|
||||
const checkMas = (x: number, y: number): boolean => {
|
||||
const allowed = (
|
||||
y >= 1 &&
|
||||
y <= matrix.length - 2 &&
|
||||
x >= 1 &&
|
||||
x <= matrix.length - 2
|
||||
)
|
||||
|
||||
if (allowed) {
|
||||
return (
|
||||
(
|
||||
matrix[y - 1][x - 1] === 'M' &&
|
||||
matrix[y + 1][x + 1] === 'S' ||
|
||||
matrix[y - 1][x - 1] === 'S' &&
|
||||
matrix[y + 1][x + 1] === 'M'
|
||||
)
|
||||
&&
|
||||
(
|
||||
matrix[y - 1][x + 1] === 'M' &&
|
||||
matrix[y + 1][x - 1] === 'S' ||
|
||||
matrix[y - 1][x + 1] === 'S' &&
|
||||
matrix[y + 1][x - 1] === 'M'
|
||||
)
|
||||
)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
let amountOfMatches = 0
|
||||
for (let y = 0; y < matrix.length; y++) {
|
||||
for (let x = 0; x < matrix.length; x++) {
|
||||
if (matrix[y][x] === 'A')
|
||||
if (checkMas(x, y)) amountOfMatches += 1
|
||||
}
|
||||
}
|
||||
|
||||
console.log(amountOfMatches)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue