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
def count_Primes_nums(n): | |
ctr = 0 | |
for num in range(n): | |
if num <= 1: | |
continue | |
for i in range(2, num): | |
if (num % i) == 0: | |
break | |
else: |
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
function isPalindrome(str) | |
{ | |
var tab = str.split(''); | |
tab.reverse(); | |
var strReverse = tab.join(''); | |
if (str.toLowerCase() === strReverse.toLowerCase()) { | |
return true; | |
} | |
return false; | |
} |
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
function sleepTracker($heartRateLog) { | |
$res = [0,0,0,0,0,0]; | |
$awake = 0; | |
$rem = 0; | |
$ls = 0; | |
$ds = 0; | |
foreach ($heartRateLog as $h) { | |
if ($h >= 90 && $h <= 100) { | |
$awake++; | |
} |
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
void main() { | |
Car myCar = new Car('March', 'Nissan', 'blue', 5, false); | |
print(myCar.toString()); | |
myCar.setColor('red'); | |
print(myCar.toString()); | |
print(myCar.getIsSUV()); | |
Car suvCar = new Car('Juke', 'Nissan', 'black', 7, true); | |
print(suvCar.toString()); |
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
enum ColorsKit {black, white, red, blue} | |
void main() { | |
ColorsKit realMadrid = ColorsKit.white; | |
ColorsKit liverpool = ColorsKit.red; | |
print(realMadrid); | |
print(liverpool); | |
String x = 'Yannick'; | |
print('Bonjour ${x}'); |
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 Pipeline | |
{ | |
public static function make_pipeline() | |
{ | |
return $result = function($arg) use ($funcs) | |
{ | |
foreach($funcs as $func) | |
{ | |
if(!isset($value)) |
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 | |
/* | |
The LeagueTable class tracks the score of each player in a league. After each game, the player records their score with the recordResult function. | |
The player's rank in the league is calculated using the following logic: | |
1)The player with the highest score is ranked first (rank 1). The player with the lowest score is ranked last. | |
2)If two players are tied on score, then the player who has played the fewest games is ranked higher. | |
3)If two players are tied on score and number of games played, then the player who was first in the list of players is ranked higher. | |
Implement the playerRank function that returns the player at the given rank. For example: $table = new LeagueTable(array('Mike', 'Chris', 'Arnold')); $table->recordResult('Mike', 2); $table->recordResult('Mike', 3); $table->recordResult('Arnold', 5); $table->recordResult('Chris', 5); echo $table->playerRank(1); All players have the same score. However, Arnold and Chris have played fewer games than Mike, and as Chris is |
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 Thesaurus | |
{ | |
private $thesaurus; | |
function __construct(array $thesaurus) | |
{ | |
$this->thesaurus = $thesaurus; | |
} |
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 | |
/** | |
* @return array An array of two elements containing roots in any order | |
*/ | |
function findRoots($a, $b, $c) | |
{ | |
$delta = ($b * $b) - 4 * ($a * $c); | |
$x = (- $b - sqrt($delta)) / (2 * $a); | |
$y = (- $b + sqrt($delta)) / (2 * $a); | |
return [$x, $y]; |
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 unique_names(array $array1, array $array2) : array | |
{ | |
return array_unique(array_merge($array1, $array2)); | |
} | |
$names = unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']); | |
echo join(', ', $names); // should print Emma, Olivia, Ava, Sophia |
NewerOlder