This file contains hidden or 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 | |
class Game | |
{ | |
private $doors = ['car', 'goat', 'goat']; | |
public function play($strategy) | |
{ | |
shuffle($this->doors); |
This file contains hidden or 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 | |
function removeNb($n) { | |
$exclude = []; | |
$sum = $n * ($n + 1) / 2; | |
for ($i = 1; $i < $n; $i++) { | |
for ($j = $i + 1; $j <= $n; $j++) { | |
if (array_key_exists($i, $exclude) || array_key_exists($j, $exclude)) { | |
continue; |
This file contains hidden or 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
// A multithreading example in C# | |
using System; | |
using System.Collections.Generic; | |
using System.Threading; | |
namespace MultiThreadingApp | |
{ | |
class Concurrency | |
{ |
This file contains hidden or 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 | |
$test = [1, [2, [3, 4], [5]]]; | |
function flatten($input, $result) { | |
foreach ($input as $val) { | |
if (is_array($val)) { | |
$result = flatten($val, $result); | |
} else { | |
array_push($result, $val); |
This file contains hidden or 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 | |
$opp = ['north' => 'south', 'south' => 'north', 'east' => 'west', 'west' => 'east']; | |
$test = ['north', 'north', 'west', 'east', 'south', 'north']; // North, North | |
$index = 0; | |
if (count($test) == 0) { | |
return '[]'; |
This file contains hidden or 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
$n = $argv[1]; | |
$file = fopen('text.txt', 'r'); | |
$map = []; | |
while (! feof($file)) { | |
$line = explode(" ", fgets($file)); | |
foreach ($line as $word) { | |
$map[$word] = isset($map[$word]) ? $map[$word] + 1 : 1; | |
} |
This file contains hidden or 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 | |
// Run by calling 'php staircase.php <number>' | |
function staircase(int $size) { | |
if ($size == 0) { | |
return 1; | |
} else if ($size < 0) { | |
return 0; | |
} else { | |
return staircase($size - 1) + staircase($size - 2) + staircase($size - 3); |
This file contains hidden or 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 | |
// Run by calling 'php palindrome.php <number>' | |
function palindrome(int $num) | |
{ | |
if ($num < 0) { | |
return false; | |
} | |
$input = str_split((string)$num); | |
for ($i = 0; $i < (count($input) / 2); $i++) { |
This file contains hidden or 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 | |
// Usage: php 3-29-kata.php <source string> <target string> | |
echo "The LevenshteinDistance of " . $argv[1] . " and " . $argv[2] . " is " . getLevenshteinDistance($argv[1], $argv[2]) . ".\n"; | |
function getLevenshteinDistance($source, $target) { | |
$sLength = strlen($source); | |
$tLength = strlen($target); | |
if ($sLength == 0) { |
This file contains hidden or 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 | |
$passwordLimit = 50; | |
$message = "Welcome to the eNotes password generator! \n"; | |
$passwordGenerator = new passwordGenerator($passwordLimit); | |
$passwordGenerator->start(); | |
class passwordGenerator { | |
protected $passwordArray = []; |