From 66fa2c4424f86a3b6985491a24a694cf5c673476 Mon Sep 17 00:00:00 2001
From: didier amyot
Date: Wed, 20 Dec 2023 20:53:37 -0500
Subject: [PATCH] added docs
---
advent-of-code/day11.ts | 100 +++++++++++++++++++
docs/index.html | 213 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 309 insertions(+), 4 deletions(-)
create mode 100644 advent-of-code/day11.ts
diff --git a/advent-of-code/day11.ts b/advent-of-code/day11.ts
new file mode 100644
index 0000000..878dc97
--- /dev/null
+++ b/advent-of-code/day11.ts
@@ -0,0 +1,100 @@
+const mock_input: string = `...#......
+.......#..
+#.........
+..........
+......#...
+.#........
+.........#
+..........
+.......#..
+#...#.....`;
+
+
+function replaceGalaxiesWithNumber(input: string): [string, number]{
+ let i = 0;
+ while(input.indexOf("#") !== -1){
+ input = input.replace("#", i);
+ i ++;
+ }
+ return [input, i];
+}
+
+function findEmptyRows(input: string): number[]{
+ let ret = [];
+ let i = 0;
+ for(const row of input.split("\n")){
+ if(row.match(/\d/g) === null ){
+ ret.push(i);
+ }
+ i++;
+ }
+ return ret;
+}
+
+function extractCol(input: string, idx: number): string{
+ let ret = "";
+ const rowLength = input.indexOf("\n") + 1;
+ for(let i = idx; i < input.length; i += rowLength){
+ ret += input.charAt(i)
+ }
+ return ret;
+}
+
+function findEmptyColumns(input: string): number[]{
+ const numberOfCols = input.indexOf("\n");
+ const ret: number[] = [];
+ for(let i = 0; i < numberOfCols - 1; i ++){
+ if(extractCol(input, i).match(/\d/g) === null){
+ ret.push(i);
+ }
+ }
+ return ret;
+}
+
+function getGalaxyCoordinates(universe: string, galaxy: number): [number, number]{
+ const dist = universe.indexOf(galaxy.toString());
+ const numberOfCols = universe.indexOf("\n") + 1;
+ return [dist % numberOfCols, Math.floor(dist / numberOfCols)]
+}
+
+function isBetween(x: number, minOrMax1: number, minOrMax2: number): boolean{
+ if(minOrMax1 == minOrMax2){
+ return false;
+ }
+ if(minOrMax1 > minOrMax2){
+ return isBetween(x, minOrMax2, minOrMax1);
+ }
+ const min_ = minOrMax1;
+ const max_ = minOrMax2;
+ return min_ < x && x < max_;
+}
+
+function distanceBetweenGalaxies(universe: string,
+ galaxy1: number,
+ galaxy2: number,
+ expandedRows: number[],
+ expandedColumns: number[]){
+ const [g1x, g1y] = getGalaxyCoordinates(universe, galaxy1);
+ const [g2x, g2y] = getGalaxyCoordinates(universe, galaxy2);
+ expandedRows.filter(x => isBetween(x, g1x, g2x)).length
+ return Math.abs(g1x - g2x)
+ + Math.abs(g1y - g2y)
+ + expandedRows.filter(x => isBetween(x, g1x, g2x)).length
+ + expandedColumns.filter(x => isBetween(x, g1y, g2y)).length
+}
+
+const [universe, nbrGalaxies] = replaceGalaxiesWithNumber(mock_input)
+console.log(universe)
+console.log("ho lala")
+
+const expandedRows = findEmptyRows(universe);
+const expandedColumns = findEmptyColumns(universe);
+console.log(expandedColumns)
+console.log(expandedRows)
+// console.log(distanceBetweenGalaxies(universe, 4, 8, expandedRows, expandedColumns));
+// console.log(distanceBetweenGalaxies(universe, 0, 6, expandedRows, expandedColumns));
+console.log(distanceBetweenGalaxies(universe, 2, 5, expandedRows, expandedColumns));
+// console.log(distanceBetweenGalaxies(universe, 7, 8, expandedRows, expandedColumns));
+
+
+console.log("fenni")
diff --git a/docs/index.html b/docs/index.html
index 7e0f4fa..dd9daee 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -162,6 +162,12 @@
#dateOfBirth
+
+ #currentAge
+
+
@@ -281,11 +287,35 @@
+ class=" toggle-sibling">
Point
-
+ ▸
+
+
@@ -1235,6 +1265,55 @@ has a name (first and last) and a date of birth.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns the current age of the player in years.
+
+ currentAge()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1501,7 +1580,7 @@ has a name (first and last) and a date of birth.
▸
-
setNumberOfGoals(goals)
+
setNumberOfGoals(numberOfGoals, goals)
@@ -1511,7 +1590,7 @@ has a name (first and last) and a date of birth.
Set the total number of goal scored by the player
-
setNumberOfGoals(goals:
number)
+
setNumberOfGoals(numberOfGoals: any, goals:
number)
@@ -1526,6 +1605,14 @@ has a name (first and last) and a date of birth.
Parameters
+
+
+ numberOfGoals (any)
+
+
+
+
+
goals (number)
@@ -2205,6 +2292,124 @@ représenté par deux coordonnées x et y.
+
Instance Members
+
+
+
+
+
+
+
+
+
+ Retoure la coordonée X du point.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ number:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Retoure la coordonée Y du point.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ number:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+