added docs
This commit is contained in:
1 parent
279d501098
commit
66fa2c4424
2 files changed
+309
-4
No files matched your search
@@ -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")
|
||||||
+209
-4
@@ -162,6 +162,12 @@
|
|||||||
#dateOfBirth
|
#dateOfBirth
|
||||||
</a></li>
|
</a></li>
|
||||||
|
|
||||||
|
<li><a
|
||||||
|
href='#hockeyplayerstatisticscurrentage'
|
||||||
|
class='regular pre-open'>
|
||||||
|
#currentAge
|
||||||
|
</a></li>
|
||||||
|
|
||||||
<li><a
|
<li><a
|
||||||
href='#hockeyplayerstatisticssetnumberofplayedgames'
|
href='#hockeyplayerstatisticssetnumberofplayedgames'
|
||||||
class='regular pre-open'>
|
class='regular pre-open'>
|
||||||
@@ -281,11 +287,35 @@
|
|||||||
|
|
||||||
<li><a
|
<li><a
|
||||||
href='#point'
|
href='#point'
|
||||||
class="">
|
class=" toggle-sibling">
|
||||||
Point
|
Point
|
||||||
|
<span class='icon'>▸</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<div class='toggle-target display-none'>
|
||||||
|
|
||||||
|
|
||||||
|
<ul class='list-reset py1-ul pl1'>
|
||||||
|
<li class='h5'><span>Instance members</span></li>
|
||||||
|
|
||||||
|
<li><a
|
||||||
|
href='#pointgetx'
|
||||||
|
class='regular pre-open'>
|
||||||
|
#getX
|
||||||
|
</a></li>
|
||||||
|
|
||||||
|
<li><a
|
||||||
|
href='#pointgety'
|
||||||
|
class='regular pre-open'>
|
||||||
|
#getY
|
||||||
|
</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
@@ -1235,6 +1265,55 @@ has a name (first and last) and a date of birth.</p>
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='border-bottom' id='hockeyplayerstatisticscurrentage'>
|
||||||
|
<div class="clearfix small pointer toggle-sibling">
|
||||||
|
<div class="py1 contain">
|
||||||
|
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
|
||||||
|
<span class='code strong strong truncate'>currentAge()</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix display-none toggle-target">
|
||||||
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p>Returns the current age of the player in years.</p>
|
||||||
|
|
||||||
|
<div class='pre p1 fill-light mt0'>currentAge()</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1501,7 +1580,7 @@ has a name (first and last) and a date of birth.</p>
|
|||||||
<div class="clearfix small pointer toggle-sibling">
|
<div class="clearfix small pointer toggle-sibling">
|
||||||
<div class="py1 contain">
|
<div class="py1 contain">
|
||||||
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
|
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
|
||||||
<span class='code strong strong truncate'>setNumberOfGoals(goals)</span>
|
<span class='code strong strong truncate'>setNumberOfGoals(numberOfGoals, goals)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix display-none toggle-target">
|
<div class="clearfix display-none toggle-target">
|
||||||
@@ -1511,7 +1590,7 @@ has a name (first and last) and a date of birth.</p>
|
|||||||
|
|
||||||
<p>Set the total number of goal scored by the player</p>
|
<p>Set the total number of goal scored by the player</p>
|
||||||
|
|
||||||
<div class='pre p1 fill-light mt0'>setNumberOfGoals(goals: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</div>
|
<div class='pre p1 fill-light mt0'>setNumberOfGoals(numberOfGoals: any, goals: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1526,6 +1605,14 @@ has a name (first and last) and a date of birth.</p>
|
|||||||
<div class='py1 quiet mt1 prose-big'>Parameters</div>
|
<div class='py1 quiet mt1 prose-big'>Parameters</div>
|
||||||
<div class='prose'>
|
<div class='prose'>
|
||||||
|
|
||||||
|
<div class='space-bottom0'>
|
||||||
|
<div>
|
||||||
|
<span class='code bold'>numberOfGoals</span> <code class='quiet'>(any)</code>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class='space-bottom0'>
|
<div class='space-bottom0'>
|
||||||
<div>
|
<div>
|
||||||
<span class='code bold'>goals</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code>
|
<span class='code bold'>goals</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code>
|
||||||
@@ -2205,6 +2292,124 @@ représenté par deux coordonnées x et y.</p>
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class='py1 quiet mt1 prose-big'>Instance Members</div>
|
||||||
|
<div class="clearfix">
|
||||||
|
|
||||||
|
<div class='border-bottom' id='pointgetx'>
|
||||||
|
<div class="clearfix small pointer toggle-sibling">
|
||||||
|
<div class="py1 contain">
|
||||||
|
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
|
||||||
|
<span class='code strong strong truncate'>getX()</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix display-none toggle-target">
|
||||||
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p>Retoure la coordonée X du point.</p>
|
||||||
|
|
||||||
|
<div class='pre p1 fill-light mt0'>getX(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
||||||
|
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='border-bottom' id='pointgety'>
|
||||||
|
<div class="clearfix small pointer toggle-sibling">
|
||||||
|
<div class="py1 contain">
|
||||||
|
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
|
||||||
|
<span class='code strong strong truncate'>getY()</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="clearfix display-none toggle-target">
|
||||||
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p>Retoure la coordonée Y du point.</p>
|
||||||
|
|
||||||
|
<div class='pre p1 fill-light mt0'>getY(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
||||||
|
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user