From e538b8536336a712c64fe9fa3e33a371f137ba41 Mon Sep 17 00:00:00 2001 From: nuo <49533950+nuoxoxo@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:27:25 +0200 Subject: [PATCH 1/3] upd. 1810 2212 --- src/includes/Aoc1810.tsx | 4 ++-- src/includes/Aoc2212.tsx | 5 ++--- src/styles/App.scss | 12 ++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/includes/Aoc1810.tsx b/src/includes/Aoc1810.tsx index fd44dcb..932e995 100644 --- a/src/includes/Aoc1810.tsx +++ b/src/includes/Aoc1810.tsx @@ -52,7 +52,7 @@ var Aoc1810 = () => { let offset = 100 if (lox + offset > hix && loy + offset > hiy) { - let temp:string[] = [' --- ' + i.toString() + ' --- '] + let temp:string[] = ['\n --- Step no. ' + i.toString() + ' --- \n'] // console.log(i) let r = loy - 1 @@ -102,7 +102,7 @@ var Aoc1810 = () => { {/* Part 1: {p1 ? p1 : "(empty)"} */} {/* Part 2: {p2 ? p2 : "(empty)"} */}
- {images ? images.map(line => line.join('\n')).join('\n\n') : "No data available."} + {images ? images.map(line => line.join('\n')).join('\n') : "No data available."}
diff --git a/src/includes/Aoc2212.tsx b/src/includes/Aoc2212.tsx index 49499fe..495e358 100644 --- a/src/includes/Aoc2212.tsx +++ b/src/includes/Aoc2212.tsx @@ -13,11 +13,10 @@ const denseSymbol = 'x'//symbolArr[Math.floor(Math.random() * symbolArr.length)] const density:number = 170 var Aoc2212 = () => { - const [lines, setLines] = useState([]) + const [lines, setLines] = useState([]) const [p1, setP1] = useState(0) const [p1Grid, setP1Grid] = useState([]) - const [p2, setP2] = useState(0) const [p2Grid, setP2Grid] = useState([]) const [P2Path, setP2Path] = useState([]) @@ -242,7 +241,7 @@ var Aoc2212 = () => { {lines ? ( <> {/*
*/} -
+
--- 2022 Day 12: Hill Climbing Algorithm --- Part 1: {p1} Part 2: {p2} diff --git a/src/styles/App.scss b/src/styles/App.scss index 2709a2b..11ad464 100644 --- a/src/styles/App.scss +++ b/src/styles/App.scss @@ -227,6 +227,8 @@ body { .playground-2212 { flex-direction: column; + color:$CREAM-YELLO; + @include animation-rainbow-rotate; } .playground-2212-alt { flex-direction: column; @@ -254,8 +256,14 @@ body { flex-direction: column; } -.res-field-2210-result { - font-size: $TextSize-05; +/* +.res-field-2212 { + justify-content: center; + align-items: center; +} +*/ + +.res-field-2210 { display: flex; flex-direction: column; } From 702d20adf25e1cd1904db7a3f2a3f0a4ef14dc9b Mon Sep 17 00:00:00 2001 From: nuo <49533950+nuoxoxo@users.noreply.github.com> Date: Wed, 20 Sep 2023 17:36:32 +0200 Subject: [PATCH 2/3] 1818 : init --- src/App.tsx | 2 ++ src/includes/Aoc1818.tsx | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/includes/Aoc1818.tsx diff --git a/src/App.tsx b/src/App.tsx index fd12fcd..0fa1110 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,6 +8,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 Aoc1818 from "./includes/Aoc1818"; import Aoc1810 from "./includes/Aoc1810"; // import Aoc1803 from "./includes/Aoc1803"; // New New import Aoc1802 from "./includes/Aoc1802"; @@ -33,6 +34,7 @@ const routes: { [key: string]: TargetRoute } = { 2003: Aoc2003, // 2011: Aoc2011, 1908: Aoc1908, + 1818: Aoc1818, 1810: Aoc1810, // 1803: Aoc1803, 1802: Aoc1802, diff --git a/src/includes/Aoc1818.tsx b/src/includes/Aoc1818.tsx new file mode 100644 index 0000000..114254d --- /dev/null +++ b/src/includes/Aoc1818.tsx @@ -0,0 +1,54 @@ +import { useState, useEffect } from "react" +import { + FetchData, + // LenNStrsFromLine, + // Deepcopy2DArray, +} from "../helpers/Helpers" + +const suffixes = ['in', 'alt'] +const choice = suffixes[Math.floor(Math.random() * suffixes.length)] +const URL:string = "https://raw.githubusercontent.com/nuoxoxo/in/main/aoc/1818." + choice + +var Aoc1818 = () => { + 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 ? ( + <> + +
+
+ --- 1818 Day 18: Settlers of The North Pole --- + {/* Part 1: {p1 ? p1 : "(empty)"} + Part 2: {p2 ? p2 : "(empty)"} */} +
+
+ +
+ { lines ? lines.join("\n") : "No data available." } +
+ + + ) : ( +

Loading data...

+ )} + + ) +} + +export default Aoc1818 From c7f821be84c39e8680014d0624747e22077ff598 Mon Sep 17 00:00:00 2001 From: nuo <49533950+nuoxoxo@users.noreply.github.com> Date: Wed, 20 Sep 2023 17:52:55 +0200 Subject: [PATCH 3/3] 1818 : looks good . to cleanup --- src/includes/Aoc1818.tsx | 116 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/src/includes/Aoc1818.tsx b/src/includes/Aoc1818.tsx index 114254d..8181ce0 100644 --- a/src/includes/Aoc1818.tsx +++ b/src/includes/Aoc1818.tsx @@ -11,6 +11,9 @@ const URL:string = "https://raw.githubusercontent.com/nuoxoxo/in/main/aoc/1818." var Aoc1818 = () => { const [lines, setLines] = useState([]) + const [p1, p1setter] = useState(0) + const [p2, p2setter] = useState(0) + const [image, setImage] = useState([]) const handleData = async () => { @@ -22,10 +25,114 @@ var Aoc1818 = () => { } } + const Solver = (limit: number, lines: string[]): [number, string[][]] => { + + if (lines === undefined || lines[0] === undefined) + return [] + let res:number = 0 + let g:string[][] = [] + for (let line of lines) { + let temp:string[] = [] + for (let c of line) { + temp.push(c) + } + g.push(temp) + } + let R:number = g.length + let C:number = g[0].length + let D:Record = {} + + let ll = -1 + let r, c + while (++ll < limit) { + // console.log(ll) + let temp:string[][] = [] + r = -1 + while (++r < R) { + let tmp:string[] = [] + c = -1 + while (++c < C) { + tmp.push(' ') + } + temp.push(tmp) + } + r = -1 + while (++r < R) { + c = -1 + while (++c < C) { + let [T, L] = [0, 0] + let dr = -2 + while (++dr < 2) { + let dc = -2 + while (++dc < 2) { + if (dr === 0 && dc === 0) + continue + let rr = r + dr + let cc = c + dc + if (rr < 0 || rr > R - 1 || cc < 0 || cc > C - 1) + continue + if (g[rr][cc] === '|') { + ++T + } else if (g[rr][cc] === '#') { + ++L + } + } + } + if (g[r][c] === '.') { + temp[r][c] = T > 2 ? '|' : '.' + } else if (g[r][c] === '|') { + temp[r][c] = L < 3 ? '|' : '#' + } else { + temp[r][c] = T > 0 && L > 0 ? '#' : '.' + } + } + } + r = -1 + while (++r < R) + g[r] = [...temp[r]] + let key:string = g.map(line => line.join('')).join('') + if (D.hasOwnProperty(key)) { + ll += Math.floor((limit - ll) / (ll - D[key])) * (ll - D[key]) + if (ll > limit -1) + break + } else { + D[key] = ll + } + let [T, L] = [0, 0] + r = -1 + while (++r < R) { + c = -1 + while (++c < C) { + if (g[r][c] === '|') { + ++T + } else if (g[r][c] === '#') { + ++L + } + } + } + // res = `iteration no. ${ll}, lumbers: ${L}, trees: ${T}, res: ${L * T}` + res = L * T + } + return [ res, g ] + } + + const Setter = () => { + let res1 = Solver(10, lines) + p1setter(res1[0]) + setImage(res1[1]) + let res2 = Solver(Math.floor(1e9), lines) + p2setter(res2[0]) + setImage(res2[1]) + } + useEffect(() => { handleData() }, []) + useEffect(() => { + Setter() + }, [lines]) + return ( <> {lines ? ( @@ -34,12 +141,15 @@ var Aoc1818 = () => {
--- 1818 Day 18: Settlers of The North Pole --- - {/* Part 1: {p1 ? p1 : "(empty)"} - Part 2: {p2 ? p2 : "(empty)"} */} + Part 1: {p1 ? p1 : "(empty)"} + Part 2: {p2 ? p2 : "(empty)"} +
+ { image ? image.join("\n") : "No data available." } +
-
+
{ lines ? lines.join("\n") : "No data available." }