prettier
This commit is contained in:
parent
ff4203a58f
commit
94fc825a0b
@ -1,6 +1,6 @@
|
|||||||
import * as R from "remeda";
|
import * as R from "remeda";
|
||||||
import { readFile } from "../05/part1.js";
|
import { readFile } from "../05/part1.js";
|
||||||
import Victor from '@a-robu/victor';
|
import Victor from "@a-robu/victor";
|
||||||
|
|
||||||
const V = (...args) => new Victor(...args);
|
const V = (...args) => new Victor(...args);
|
||||||
|
|
||||||
@ -8,16 +8,16 @@ const readInput = (...args) =>
|
|||||||
readFile(...args)
|
readFile(...args)
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter((x) => x)
|
.filter((x) => x)
|
||||||
.map( l => l.split('').map( x => parseInt(x) ) );
|
.map((l) => l.split("").map((x) => parseInt(x)));
|
||||||
|
|
||||||
export function generateVisibilityGrid(forest) {
|
export function generateVisibilityGrid(forest) {
|
||||||
const size = forest.length;
|
const size = forest.length;
|
||||||
const visibility = Array(size).fill(null).map(
|
const visibility = Array(size)
|
||||||
() => Array(size).fill(false)
|
.fill(null)
|
||||||
);
|
.map(() => Array(size).fill(false));
|
||||||
|
|
||||||
// top
|
// top
|
||||||
const positions = R.range(size)(0).map( x => ({
|
const positions = R.range(size)(0).map((x) => ({
|
||||||
height: -1,
|
height: -1,
|
||||||
position: V(x, -1),
|
position: V(x, -1),
|
||||||
inc: V(0, 1),
|
inc: V(0, 1),
|
||||||
@ -25,7 +25,7 @@ export function generateVisibilityGrid(forest) {
|
|||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
positions.push(
|
positions.push(
|
||||||
...R.range(size)(0).map( x => ({
|
...R.range(size)(0).map((x) => ({
|
||||||
height: -1,
|
height: -1,
|
||||||
position: V(x, size),
|
position: V(x, size),
|
||||||
inc: V(0, -1),
|
inc: V(0, -1),
|
||||||
@ -33,14 +33,14 @@ export function generateVisibilityGrid(forest) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
positions.push(
|
positions.push(
|
||||||
...R.range(size)(0).map( x => ({
|
...R.range(size)(0).map((x) => ({
|
||||||
height: -1,
|
height: -1,
|
||||||
position: V(-1, x),
|
position: V(-1, x),
|
||||||
inc: V(1, 0),
|
inc: V(1, 0),
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
positions.push(
|
positions.push(
|
||||||
...R.range(size)(0).map( x => ({
|
...R.range(size)(0).map((x) => ({
|
||||||
height: -1,
|
height: -1,
|
||||||
position: V(size, x),
|
position: V(size, x),
|
||||||
inc: V(-1, 0),
|
inc: V(-1, 0),
|
||||||
@ -51,7 +51,7 @@ export function generateVisibilityGrid(forest) {
|
|||||||
if (Math.min(pos.x, pos.y) < 0) return true;
|
if (Math.min(pos.x, pos.y) < 0) return true;
|
||||||
if (Math.max(pos.x, pos.y) >= size) return true;
|
if (Math.max(pos.x, pos.y) >= size) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
while (positions.length) {
|
while (positions.length) {
|
||||||
const pos = positions.shift();
|
const pos = positions.shift();
|
||||||
@ -74,7 +74,7 @@ export const puzzleInput = readInput(import.meta.url, "input");
|
|||||||
export const sample = readInput(import.meta.url, "sample");
|
export const sample = readInput(import.meta.url, "sample");
|
||||||
|
|
||||||
function printMap(forest) {
|
function printMap(forest) {
|
||||||
forest.forEach( line => console.log(line.join(' ')) );
|
forest.forEach((line) => console.log(line.join(" ")));
|
||||||
return forest;
|
return forest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user