From 9a4a856e2de8cad5224801d52e4649ad1f73b879 Mon Sep 17 00:00:00 2001 From: uxn Date: Tue, 19 Sep 2023 11:45:12 +0200 Subject: [PATCH 1/2] 1810 : init --- package-lock.json | 4 +-- src/App.tsx | 2 ++ src/includes/Aoc1810.tsx | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/includes/Aoc1810.tsx diff --git a/package-lock.json b/package-lock.json index aefb633..21608e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "io/gig", + "name": "io-gig", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "io/gig", + "name": "io-gig", "version": "0.0.0", "dependencies": { "react": "^18.2.0", diff --git a/src/App.tsx b/src/App.tsx index 4a5dc4c..5d01753 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import Aoc2105 from "./includes/Aoc2105"; // New import Aoc2003 from "./includes/Aoc2003"; // New New // import Aoc2011 from "./includes/Aoc2011"; // New New New import Aoc1908 from "./includes/Aoc1908"; +import Aoc1810 from "./includes/Aoc1810"; import Aoc1803 from "./includes/Aoc1803"; // New New import Aoc1802 from "./includes/Aoc1802"; import Aoc1608 from "./includes/Aoc1608"; @@ -30,6 +31,7 @@ const routes: { [key: string]: TargetRoute } = { 2003: Aoc2003, // 2011: Aoc2011, 1908: Aoc1908, + 1810: Aoc1810, 1803: Aoc1803, 1802: Aoc1802, 1502: Aoc1502, diff --git a/src/includes/Aoc1810.tsx b/src/includes/Aoc1810.tsx new file mode 100644 index 0000000..0a65402 --- /dev/null +++ b/src/includes/Aoc1810.tsx @@ -0,0 +1,53 @@ +import { useState, useEffect } from "react" +import { + FetchData, + // LenNStrsFromLine, + // Deepcopy2DArray, +} from "../helpers/Helpers" + +const URL: string = + "https://raw.githubusercontent.com/nuoxoxo/in/main/aoc/1810.0" + +var Aoc1810 = () => { + const [lines, setLines] = useState([]) + + const handleData = async () => { + + try { + const raws = await FetchData(URL) + setLines(raws) + } catch (error: any) { + console.error("Error fetching data: ", error) + } + } + + useEffect(() => { + handleData() + }, []) + + return ( + <> + {lines ? ( + <> + +
+
+ --- 2018 Day 10: The Stars Align --- + {/* Part 1: {p1 ? p1 : "(empty)"} */} + {/* Part 2: {p2 ? p2 : "(empty)"} */} +
+
+ +
+ { lines ? lines.join("\n") : "No data available." } +
+ + + ) : ( +

Loading data...

+ )} + + ) +} + +export default Aoc1810 From c0ff2c68edd13c452c52d29411eb6022055f0cda Mon Sep 17 00:00:00 2001 From: uxn Date: Tue, 19 Sep 2023 12:16:06 +0200 Subject: [PATCH 2/2] 1810 : done --- src/includes/Aoc1810.tsx | 64 ++++++++++++++++++++++++++++++++++++++-- src/styles/App.scss | 10 +++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/includes/Aoc1810.tsx b/src/includes/Aoc1810.tsx index 0a65402..c313ecf 100644 --- a/src/includes/Aoc1810.tsx +++ b/src/includes/Aoc1810.tsx @@ -5,11 +5,12 @@ import { // Deepcopy2DArray, } from "../helpers/Helpers" -const URL: string = +const URL: string = "https://raw.githubusercontent.com/nuoxoxo/in/main/aoc/1810.0" var Aoc1810 = () => { const [lines, setLines] = useState([]) + const [images, setImages] = useState([]) const handleData = async () => { @@ -21,25 +22,82 @@ var Aoc1810 = () => { } } + const Solver = () => { + let res:string[][] = [] + let A: number[][] = [] + for (let line of lines) { + let [x, y, dx, dy] = line.match(/-?\d+/g)!.map(Number) + A.push([x, y, dx, dy]) + } + + console.log(A) + + let i = -1 + while (++i < 10600) { // range is hand picked + let hix: number = Math.max(...A.map(([n, , ,]) => n)) + let lox: number = Math.min(...A.map(([n, , ,]) => n)) + let hiy: number = Math.max(...A.map(([, n, ,]) => n)) + let loy: number = Math.min(...A.map(([, n, ,]) => n)) + let offset = 100 + + if (lox + offset > hix && loy + offset > hiy) { + let temp:string[] = [' --- ' + i.toString() + ' --- '] + // console.log(i) + + let r = loy - 1 + // let s = '' // Bug + while (++r < hiy + 1) { + let c = lox - 1 + let s = '' + while (++c < hix + 1) { + const temp = A.map(([x, y, ,]) => [x, y]) + if (temp.some(([x, y]) => x === c && y === r)) { + s += '#' + } else { + s += '.' + } + } + // s += '\n' + temp.push(s) + } + // console.log(s) + res.push(temp) + } + let j = -1 + while (++j < A.length) { + A[j][0] += A[j][2] + A[j][1] += A[j][3] + } + } + setImages(res) + } + useEffect(() => { handleData() }, []) + useEffect(() => { + Solver() + }, [lines]) + return ( <> {lines ? ( <>
-
+
--- 2018 Day 10: The Stars Align --- {/* Part 1: {p1 ? p1 : "(empty)"} */} {/* Part 2: {p2 ? p2 : "(empty)"} */} +
+ {images ? images.map(line => line.join('\n')).join('\n') : "No data available."} +
- { lines ? lines.join("\n") : "No data available." } + {lines ? lines.join("\n") : "No data available."}
diff --git a/src/styles/App.scss b/src/styles/App.scss index 2c21d68..5c0013f 100644 --- a/src/styles/App.scss +++ b/src/styles/App.scss @@ -246,6 +246,16 @@ body { flex-direction: column; } +.res-field-1810 { + display: flex; + flex-direction: column; +} + +.res-field-1810-image { + font-size: 3px; + text-align: center; +} + .res-field-2210-image { font-size: $TextSize-05; display: flex;