Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 9, 2020 16:05
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/120cfa744f02e2c9119d8a696fb09b7f to your computer and use it in GitHub Desktop.
Save lbvf50mobile/120cfa744f02e2c9119d8a696fb09b7f to your computer and use it in GitHub Desktop.
Just PHP FUN 045.
<?php
# https://www.codewars.com/kata/5636840bd87777688b00006c Basics - Generators #1.
function generator() {
for($i = 1; ;$i += 1) if( $z = yield $i) $i = $z - 1;
}
-------------------------------------------------------------------------------
function generator() {
$x = 1;
while(true){
$z = yield $x;
if($z){
$x = $z;
} else{
$x += 1;
}
}
}

Just PHP FUN 045.

Started at 22:22 09.07.2020 July Thursday. Finished at 23:05 09.07.2020 July Thursday (0rhs 43 minutes)

<?php
# https://www.codewars.com/kata/5637ead70013386e30000027 Multiplication - Generators #2.
function generator($a) {
for($i = 1; ; $i+=1) yield "$a x $i = ".$a*$i;
}
<?php
# https://www.codewars.com/kata/598ab63c7367483c890000f4 String Task.
function string_task(string $s): string {
$s = strtolower($s); $s = preg_replace('/[aoyeui]/','',$s);
return $s = preg_replace('/./','.$0',$s);
}
# https://www.codewars.com/kata/580a41b6d6df740d6100030c Alan Partridge III - London.
function alan(array $a): string {
$x = array_count_values($a);
foreach(['Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams Parkway'] as $v)
if(! $x[$v]) return 'No, seriously, run. You will miss it.';
return 'Smell my cheese you mother!';
<?php
# https://www.codewars.com/kata/5808c8eff0ed4210de000008 Alan Partridge I - Partridge Watch.
function part(array $a): string {
$z = ['Partridge','PearTree','Chat','Dan','Toblerone','Lynn','AlphaPapa','Nomad'];
$x = count($a) - count(array_diff($a,$z));
if( 0 == $x) return 'Lynn, I\'ve pierced my foot on a spike!!';
return 'Mine\'s a Pint'.str_repeat('!',$x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment