Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 6, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/595117bc65255852d6c1b6c949215be8 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/595117bc65255852d6c1b6c949215be8 to your computer and use it in GitHub Desktop.
Just PHP FUN 042.
<?php
# https://www.codewars.com/kata/58cd9292bd0fd35781000186 Very Basic Inheritance.
class Beer extends Poison {
public function observe(){
return "Has foam.";
}
public function drink(){
return "Beer is not very good choise for daily drinking.";
}
}
class Wine extends Poison{
public function observe(){
return "Do has foam?";
}
public function drink(){
return "Baam.";
}
}
<?php
# https://www.codewars.com/kata/57d0fad6eca26073c3000023 PHP Functions - Default Arguments.
function multiply_with_defaults($a=1,$b=1){
return $a*$b;
}
function circle_area($r = 1){
$pi = 3.1415926535898;
return $pi * ($r**2);
}
function prank_replace($a, $b = 'hello', $c = 'goodbye'){
return str_replace($b,$c,$a);
}
<?php
# https://www.codewars.com/kata/592eaf848c91f248ca000012 Adding words - Part I.
class Arith {
public $count =
'zero – one 2 – two 3 – three 4 – four 5 – five 6 – six 7 – seven 8 – eight
9 – nine
10 – ten
11 – eleven
12 – twelve
13 – thirteen
14 – fourteen
15 – fifteen
16 – sixteen
17 – seventeen
18 – eighteen
19 – nineteen
20 – twenty';
function __construct($x) {
$a = str_replace("\n"," ",$this->count);
$a = array_values(array_filter(explode(" ",$a),function($x){return preg_match('/[a-z]+/',$x);}));
$this->count = $a;
$this->wrds = array_flip($a);
$this->lft = $x;
}
function add($x){
return $this->count[$this->wrds[$this->lft] + $this->wrds[$x]];
}
}
<?php
# https://www.codewars.com/kata/57aa218e72292d98d500240f Heron's formula.
function heron($a, $b, $c)
{
$s = round(($a+$b+$c)/2,12);
$x = round(sqrt($s*($s-$a)*($s-$b)*($s-$c)),12);
echo "($a,$b,$c) => $s $x \n";
return $x;
}
<?php
# https://www.codewars.com/kata/59ad7d2e07157af687000070 Pull your words together, man!
function sentencify($words){
return ucfirst(implode(" ", $words)).".";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment