-
https://www.codewars.com/kata/59377c53e66267c8f6000027 Alphabet war.
-
https://www.codewars.com/kata/597bb84522bc93b71e00007e String Merge!
-
https://www.codewars.com/kata/57f7796697d62fc93d0001b8 Double Trouble.
-
https://www.codewars.com/kata/586ec0b8d098206cce001141 Thinkful - List and Loop Drills: Inverse Slicer.
-
https://www.codewars.com/kata/58844f1a76933b1cd0000023 Simple Fun #8: Kill K-th Bit.
Started at 20:14 25.06.2020 Thursday June.
Finished at 23:25 25.06.2020 Thursday June. (3hrs 09minutes)
Last active
June 25, 2020 16:25
-
-
Save lbvf50mobile/cd5e027a4c50b5110e3b774c6b827de8 to your computer and use it in GitHub Desktop.
Just PHP FUN 033.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://www.codewars.com/kata/59377c53e66267c8f6000027 Alphabet war. | |
function alphabetWar($fight) | |
{ | |
$ans = ['Left side wins!', "Let's fight again!", "Right side wins!"]; | |
$hst = count_chars($fight); $lw = 0; $rw = 0; | |
foreach(['w'=>4,'p'=>3, 'b'=>2, 's'=>1] as $k=>$v) $lw += $v * $hst[ord($k)]; | |
foreach(['m'=>4,'q'=>3, 'd'=>2, 'z'=>1] as $k=>$v) $rw += $v * $hst[ord($k)]; | |
if($lw == $rw) return $ans[1]; | |
if($lw > $rw) return $ans[0]; | |
return $ans[2]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://www.codewars.com/kata/586ec0b8d098206cce001141 Thinkful - List and Loop Drills: Inverse Slicer. | |
function inverse_slice(array $items, int $a, int $b): array { | |
array_splice($items,$a,$b-$a); | |
return $items; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://www.codewars.com/kata/58844f1a76933b1cd0000023 Simple Fun #8: Kill K-th Bit. | |
function kill_kth_bit(int $n, int $k): int { | |
$x = str_split(decbin($n)); | |
if(1 == $x[count($x)-$k]) $x[count($x)-$k] = '0'; | |
return bindec(implode($x)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://www.codewars.com/kata/597bb84522bc93b71e00007e String Merge! | |
function stringMerge($s1, $s2, $l) { | |
return substr($s1,0,strpos($s1,$l)+1).substr($s2,strpos($s2,$l)+1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://www.codewars.com/kata/57f7796697d62fc93d0001b8 Double Trouble. | |
function trouble($x, $a) | |
{ | |
for( $i = 1; $i < count($x); $i += 1) | |
if($x[$i-1] + $x[$i] == $a){ | |
array_splice($x,$i,1); | |
$i -= 1; | |
} | |
return $x; | |
} | |
# ---------------------------------------------------------------------- | |
function trouble($x, $a) | |
{ | |
echo "Input ".implode(",",$x)." => $a \n"; | |
$l = count($x); | |
$dlt = []; $ans = []; $cnt = true; | |
for($s = 1; $s < $l && $cnt ; $s+=1) if($x[$s-1]+$x[$s] == $a) {$dlt[$s] = true; $cnt = false; } | |
if($cnt) return $x; | |
echo "Keys for delete".implode(",",array_keys($dlt))." \n"; | |
for($i = 0; $i < $l; $i+=1) if(!isset($dlt[$i])) array_push($ans,$x[$i]); | |
echo "Return array ".implode(",",$ans)." \n"; | |
return trouble($ans,$a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment