Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 13, 2020 16:09
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/5d538e99c34865da228d9924ddf4eb8a to your computer and use it in GitHub Desktop.
Save lbvf50mobile/5d538e99c34865da228d9924ddf4eb8a to your computer and use it in GitHub Desktop.
Just PHP FUN 023.
<?php
# https://www.codewars.com/kata/5667e8f4e3f572a8f2000039 Mumbling.
function accum($s) {
$ans = []; $s = strtolower($s);
foreach(str_split($s) as $i=>$v) array_push($ans, ucfirst(str_repeat($v,$i+1)));
return implode("-",$ans);
}
<?php
# https://www.codewars.com/kata/5d076515e102162ac0dc514e Baby shark lyrics generator.
function babySharkLyrics() {
$do = str_repeat(" doo", 6); $ans = '';
$x = ['Baby shark','Mommy shark','Daddy shark','Grandma shark','Grandpa shark',"Let's go hunt"];
foreach($x as $v) $ans .= str_repeat($v.",".$do."\n",3)."$v!\n";
return $ans."Run away,…";
}
<?php
# https://www.codewars.com/kata/59b844528bcb7735560000a0 Nice Array.
function isNice($arr) {
$hist = [];
echo "Input: ".implode(", ",$arr)."\n";
foreach($arr as $v) $hist[$v] = true;
foreach($arr as $v){
$a = isset($hist[$v-1]);
$b = isset($hist[$v+1]);
echo "Now it is $v; ".($v-1)."=".intval($a)."; ".($v+1)."=".intval($b)."; \n";
if( !($a||$b)) return false;
}
if(empty($arr)) return false;
return true;
}
<?php
# https://www.codewars.com/kata/561046a9f629a8aac000001d Array comparator.
function match_arrays(array $a, array $b): int {
return count(array_intersect($a,$b));
}
<?php
# https://www.codewars.com/kata/58ba6fece3614ba7c200017f Numerical Palindrome #1.
function palindrome($num) {
if(!is_int($num)) return "Not valid";
if($num < 0 ) return "Not valid";
$x = strval($num);
return $x == strrev($x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment