Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 30, 2020 16:36
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/9bd648231b996825a47de145cf03ab26 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/9bd648231b996825a47de145cf03ab26 to your computer and use it in GitHub Desktop.
Just PHP FUN 037.
<?php
# https://www.codewars.com/kata/57ed30dde7728215300005fa Bumps in the Road.
function bump($x) {
$x1 = count_chars($x);
$z = $x1[ord('n')];
$ans = $z <= 15 ? "Woohoo!" : "Car Dead";
echo "$x => $z : $ans\n";
return $ans;
}
<?php
# https://www.codewars.com/kata/5acbc3b3481ebb23a400007d Determine if the poker hand is flush.
function checkIfFlush($cards)
{
return 1 == count(array_unique(array_map(function($x){ return $x[strlen($x)-1];},$cards)));
}
<?php
# https://www.codewars.com/kata/5b715fd11db5ce5912000019 Ball and Cups.
function cupAndBalls($b, $arr) {
$x = [0,0,0,0];
$x[$b] = 1;
foreach($arr as $v){
list($p1,$p2) = $v;
$tmp = $x[$p1];
$x[$p1] = $x[$p2];
$x[$p2] = $tmp;
}
return array_search(1,$x);
}
<?php
# https://www.codewars.com/kata/5b096efeaf15bef812000010 nth Floyd line.
function nth_floyd($n) : int {
$l = 1; $h = 50000;
while($l < $h){
$mid = ($l + $h) >> 1;
$midval = ((1+$mid)*$mid)/2;
$prv = ((1+$mid-1)*($mid-1))/2;
echo "$l <== $mid ==> $h \n [n: $n, midval: $midval] \n";
echo ($prv <= $n && $n <= $midval)." equal \n";
if($prv < $n && $n <= $midval) {
echo "Equal!; \n";
return $mid;
}
if($n < $midval){ $h = $mid - 1;}
else{ $l = $mid + 1;}
}
return $l;
}
<?php
# https://www.codewars.com/kata/5aff237c578a14752d0035ae Predict your age!
function predictAge(...$x){
$x = array_map(function($x){return $x*$x;},$x);
$x = array_sum($x);
return floor(sqrt($x)/2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment