123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { LoadInput } from "../common.ts";
- import * as util from "util";
- const tests = [
- "467..114..",
- "...*......",
- "..35..633.",
- "......#...",
- "617*......",
- ".....+.58.",
- "..592.....",
- "......755.",
- "...$.*....",
- ".664.598..",
- ];
- const testMap = BuildSchematicsMap(tests);
- let testParts = ParseSchematics(testMap);
- testParts = ValidateEngineParts(testParts);
- console.log(util.inspect(testParts, { breakLength: Infinity, depth: 256, colors: true }));
- function ParseSchematics(schematicsMap: string[][]): EnginePart[] {
- const engineParts: EnginePart[] = [];
-
- const schematicsPointer: Vector2 = {
- X: 0,
- Y: 0,
- };
- for(; schematicsPointer.Y < schematicsMap.length; schematicsPointer.Y++) {
-
- schematicsPointer.X = 0;
-
- const schematicsLine = schematicsMap[schematicsPointer.Y];
-
- let part: EnginePart|null = null;
- for(; schematicsPointer.X < schematicsMap[schematicsPointer.Y].length; schematicsPointer.X++) {
- const char = schematicsMap[schematicsPointer.Y][schematicsPointer.X];
-
- if (/\d/.test(char)) {
-
- if (part == null) { part = { PartNumber: 0, Coordinates: [] }; }
- if (part.PartNumber) {
-
- part.PartNumber = Number("" + part.PartNumber + char);
- }
- else {
-
- part.PartNumber = Number(char);
- }
-
- part.Coordinates.push({
- X: schematicsPointer.X,
- Y: schematicsPointer.Y,
- });
- }
-
- else {
-
- if(part != null) {
-
- engineParts.push(part);
- part = null;
- }
- }
- }
- }
- return engineParts;
- }
- function ValidateEngineParts(potentialParts: EnginePart[]): EnginePart[] {
- return [];
- }
- function BuildSchematicsMap(schematics: string[]): string[][] {
- return schematics.map((schematicsLine) => schematicsLine.split(''));
- }
- type EnginePart = {
- PartNumber: number,
- Coordinates: Vector2[],
- };
- type SchematicsSymbol = {
- Symbol: string,
- Coordinates: Vector2,
- };
- type Vector2 = {
- X: number,
- Y: number,
- };
|