View numberAbbreviation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shorten large numbers into abbreviations (i.e. 1,500 = 1.5k) | |
* | |
* @param int $number Number to shorten | |
* @return String A number with a symbol | |
*/ | |
function numberAbbreviation($number) { | |
$abbrevs = [1000000000000 => 'T', 1000000000 => 'B', 1000000 => 'M', 1000 => 'K', 1 => '']; |
View the_monty_hall_problem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CHANCE = 3; | |
function rollDoor() { | |
return Math.floor(Math.random() * CHANCE); | |
} | |
function randArr(arr) { | |
return arr[Math.floor(Math.random() * arr.length)]; | |
} |
View count_rectangles_inside_matrix.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Counts all rectangles inside matrix by loop. | |
* | |
* For 3x3: | |
* *_*_* // 1x1 = 4 | |
* *_*_* // 1x2 = 2 | |
* * * * // 2x1 = 2 | |
* // 2x2 = 1 |
View count_squares_in_matrix.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Counts squares in matrix by loop. | |
* | |
* @param int $n | |
* @param int $m | |
* @return int | |
*/ | |
function countSquares(int $m, int $n): int |