Skip to content

Instantly share code, notes, and snippets.

Avatar
🧿
Focusing

Vitalii Honcharuk EXayer

🧿
Focusing
  • SoftHouseGroup
  • Vinnytsia, Ukraine
View GitHub Profile
@EXayer
EXayer / numberAbbreviation.php
Last active Feb 10, 2021 — forked from bcole808/numberAbbreviation.php
Shorten large numbers into abbreviations (i.e. 1,500 = 1.5k), (slightly optimized)
View numberAbbreviation.php
<?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 => ''];
@EXayer
EXayer / the_monty_hall_problem.js
Created Oct 9, 2020
The Monty Hall Problem - brute force proof
View the_monty_hall_problem.js
const CHANCE = 3;
function rollDoor() {
return Math.floor(Math.random() * CHANCE);
}
function randArr(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
@EXayer
EXayer / count_rectangles_inside_matrix.php
Created Jun 24, 2020
How many rectangles a matrix can fit?
View count_rectangles_inside_matrix.php
<?php
/**
* Counts all rectangles inside matrix by loop.
*
* For 3x3:
* *_*_* // 1x1 = 4
* *_*_* // 1x2 = 2
* * * * // 2x1 = 2
* // 2x2 = 1
View count_squares_in_matrix.php
<?php
/**
* Counts squares in matrix by loop.
*
* @param int $n
* @param int $m
* @return int
*/
function countSquares(int $m, int $n): int