Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 30, 2020 19:15
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/019ebcb27e40762d8d26dad117daca66 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/019ebcb27e40762d8d26dad117daca66 to your computer and use it in GitHub Desktop.
Just PHP FUN 063.
<?php
# https://www.codewars.com/kata/57d4e99bec16701a67000033 Hëävÿ Mëtäl Ümläüts.
function heavyMetalUmlauts($boringText) {
$cheatsheet = [
'A' => 'Ä', 'E' => 'Ë', 'I' => 'Ï', 'O' => 'Ö', 'U' => 'Ü', 'Y' => 'Ÿ',
'a' => 'ä', 'e' => 'ë', 'i' => 'ï', 'o' => 'ö', 'u' => 'ü', 'y' => 'ÿ'
];
return preg_replace_callback('/[aoeuiy]/i', fn($x) => $cheatsheet[$x[0]], $boringText);
}
<?php
# https://www.codewars.com/kata/581c6b075cfa83852700021f Fun with lists: indexOf.
function index_of($head, $value) {
$answer = -1;
for($i = 0; $head; $i+=1, $head = $head->next) if($head->data === $value ) {
$answer = $i; break;
}
return $answer;
}

Just PHP FUN 063.

Started at 22:02 30.07.2020 Thursday July.
Finished at 02:15 31.07.2020 Friday July. (4hrs 13minutes)

<?php
# https://www.codewars.com/kata/5798bb604be912fb6700008c Object-Oriented PHP #4 - People, people, people (Practice).
class Person{
const species = "Homo Sapiens";
public $name, $age, $occupation;
public function __construct($name, $age, $occupation){
$this->name = $name; $this->age = $age; $this->occupation = $occupation;
}
public function introduce(){ return "Hello, my name is $this->name"; }
public function describe_job(){ return "I am currently working as a(n) $this->occupation"; }
public function greet_extraterrestrials($x){ return "Welcome to Planet Earth $x!"; }
}
<?php
# https://www.codewars.com/kata/5706be574f2c297a7b00060d Chuck Norris VI - Shopping with Chuck.
function price($start, $soil, $age) {
$x = [
'Barely used' => 0.1,
'Seen a few high kicks' => 0.25,
'Blood stained' => 0.3,
'Heavily soiled' => 0.5
];
if( !(is_numeric($start) && array_key_exists(strval($soil),$x) && is_int($age)) ) return 'Chuck is bottomless!';
$start = $start * ((1+ $x[$soil])**$age);
return sprintf('$%.2f',$start);
}
# ----------------------------------------------------------------------------------------------------
function price($start, $soil, $age) {
$x = [
'Barely used' => 0.1,
'Seen a few high kicks' => 0.25,
'Blood stained' => 0.3,
'Heavily soiled' => 0.5
];
if( !(is_numeric($start) && array_key_exists(strval($soil),$x) && is_int($age)) ) return 'Chuck is bottomless!';
for($i = 0; $i < $age; $i +=1) $start = $start + $start * $x[$soil];
return sprintf('$%.2f',$start);
}
<?php
# https://www.codewars.com/kata/579893057cb7a1be7900030d Object-Oriented PHP #3 - Class Constants and Static Methods.
class CurrentUSPresident{
const name = "Barack Obama";
public static function greet($name) {
return "Hello $name, my name is ".CurrentUSPresident::name.", nice to meet you!";
}
}
@lbvf50mobile
Copy link
Author

lbvf50mobile commented Jul 30, 2020

<?php 
# https://www.codewars.com/kata/579735144be912fd220001d8 Object-Oriented PHP #1 - Classes, Public Properties and Methods
class President{
  public $name = "Barack Obama";
  public function greet($name) {
    return "Hello $name, my name is ".$this->name.", nice to meet you!";
  }
  
  
}
$us_president = new President();
$president_name =  $us_president->name;
$greetings_from_president = $us_president->greet("Donald");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment