Skip to content

Instantly share code, notes, and snippets.

View sedera-tax's full-sized avatar

Razafindrakoto Yannick Sedera Aina sedera-tax

View GitHub Profile
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:
@sedera-tax
sedera-tax / palindrome.js
Last active April 1, 2021 07:01
check if string is palindrome or not
function isPalindrome(str)
{
var tab = str.split('');
tab.reverse();
var strReverse = tab.join('');
if (str.toLowerCase() === strReverse.toLowerCase()) {
return true;
}
return false;
}
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++;
}
@sedera-tax
sedera-tax / car.dart
Last active January 20, 2021 11:04
DART POO
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());
@sedera-tax
sedera-tax / main.dart
Last active January 20, 2021 14:02
DART Base
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}');
@sedera-tax
sedera-tax / makePipeline.php
Created January 15, 2021 14:45
Make_pipeline
<?php
class Pipeline
{
public static function make_pipeline()
{
return $result = function($arg) use ($funcs)
{
foreach($funcs as $func)
{
if(!isset($value))
@sedera-tax
sedera-tax / leagueTable.php
Created January 15, 2021 13:55
6. League Table
<?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
@sedera-tax
sedera-tax / thesaurus.php
Created January 15, 2021 13:51
5. Thesaurus A thesaurus contains words and synonyms for each word. Below is an example of a data structure that defines a thesaurus: array("buy" => array("purchase"), "big" => array("great", "large")) Implement the function getSynonyms, which accepts a word as a string and returns all synonyms for that word in JSON format, as in the example be…
<?php
class Thesaurus
{
private $thesaurus;
function __construct(array $thesaurus)
{
$this->thesaurus = $thesaurus;
}
@sedera-tax
sedera-tax / quadraticEquation.php
Created January 15, 2021 13:41
3. Quadratic Equation Implement the function findRoots to find the roots of the quadratic equation: ax2 + bx + c = 0. The function should return an array containing both roots in any order. If the equation has only one solution, the function should return that solution as both elements of the array. The equation will always have at least one sol…
<?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];
@sedera-tax
sedera-tax / mergeNames.php
Created January 15, 2021 13:40
2. Merge Names Implement the unique_names function. When passed two arrays of names, it will return an array containing the names that appear in either or both arrays. The returned array should have no duplicates. For example, calling unique_names(['Ava', 'Emma', 'Olivia'], ['Olivia', 'Sophia', 'Emma']) should return ['Emma', 'Olivia', 'Ava', '…
<?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