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 | |
<?php | |
function max($tab) { | |
$result = 0; | |
for ($i = 0; count($tab); $i++) { | |
if ($tab[$i] > $result) { | |
$result = $tab[$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
// La recherche dichotomique en JS | |
// ENTREE -> Algo -> SORTIE | |
// ENTREE: dictionnaire + le mot à chercher | |
// SORTIE: -1 OU position | |
// cf. Code in Game / HackerRank | |
// dummyIndexOf 1s -> 200000 2s -> 400000 |
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
/* ###### CONSTANT ###### */ | |
var BILLS = [200, 100, 50, 20, 10, 5, 2, 1] // ARRAY of bills with really cheap bills like coins | |
/* ###### SMART ALGORITHM ###### */ | |
var cash_machine = function (amount) { // FUNCTION | |
var i = 0; // iterator | |
while (amount > 0) { // check if their is still money to give for the customer | |
if (BILLS[i] <= amount) { // try with the larger bill | |
console.log("Cash Machine give me a bill of " + BILLS[i] + "€"); // GIVE ME MY MONEY!!! | |
amount = amount - BILLS[i]; // reduce the amount of money we still have to gave for the customer |
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
/* ###### CONSTANT ###### */ | |
var BILLS = [200, 100, 50, 20, 10, 5, 2, 1] // ARRAY of bills with really cheap bills like coins | |
/* ###### SMART ALGORITHM ###### */ | |
var cash_machine = function (amount) { // FUNCTION | |
var i = 0; // iterator | |
while (amount > 0) { // check if their is still money to give for the customer | |
if (BILLS[i] <= amount) { // try with the larger bill | |
console.log("Cash Machine give me a bill of " + BILLS[i] + "€"); // GIVE ME MY MONEY!!! | |
amount = amount - BILLS[i]; // reduce the amount of money we still have to gave for the customer |
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
/* | |
* Factorial | |
* n! = 1 * 2 * .. * n | |
* | |
* 5! = 5 * 4 * 3 * 2 * 1 = 120 | |
*/ | |
// MATHS: | |
// 0! = 1 | |
// n! = n * (n - 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
/* | |
* INPUT: a number N | |
* | |
* OUPUT: f(N) where f is the fibonacci function : | |
* | |
* 0 1 1 2 3 5 8 13 21 34 .. | |
* | |
* f(0) => 0 | |
* f(1) => 1 | |
* f(2) => 0 + 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
// Definition of Map function | |
function Map(arr, func) { | |
m_arr = []; | |
for (var i = 0; i < arr.length; ++i) | |
m_arr.push(func(arr[i])); | |
return m_arr; | |
} | |
// Definition of Filter function | |
function Filter(arr, func) { |
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
// PROTOTYPE // | |
// setTimeout(Function, Number); | |
/////////////// | |
// Example | |
// 1. | |
setTimeout( | |
// first parameter | |
// (which is an anonymous function without parameter) |
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
/* | |
* Triangle | |
* | |
* INPUT: | |
* - a number N | |
* | |
* OUPUT: (eg for N=5) | |
* # | |
* ## | |
* ### |
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
var T = []; | |
T[0] = 0; | |
T[1] = 1; | |
for (var i = 2; i < 100; i++) { | |
T[i] = T[i-2] + T[i-1]; | |
} | |
function fib(x) { |