Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 10, 2020 18:18
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/fbd71c181f982d87b98323dcdc10899b to your computer and use it in GitHub Desktop.
Save lbvf50mobile/fbd71c181f982d87b98323dcdc10899b to your computer and use it in GitHub Desktop.
Just PHP FUN 046.
<?php
# https://www.codewars.com/kata/57ab3d89bb9944b733000a32 T.T.T.28: Crow drink water(乌鸦喝水).
function drink_water($bottle_height, $bottle_radius, $water_height, $crow_mouth, $little_stones) {
$x = $bottle_height - $crow_mouth - $water_height;
echo "$x \n";
$btl = 3.14 * ($bottle_radius**2) * $bottle_height;
$nose = 3.14 * ($bottle_radius**2) * $crow_mouth;
$wtr = 3.14 * ($bottle_radius**2) * $water_height;
echo "$btl $nose $wtr \n";
$v = $x * 3.14159265359 * ($bottle_radius**2);
$ans = [];
while($v > 0 && !empty($little_stones) ) {
$x = array_shift($little_stones);
$v -= $x;
array_push($ans, $x);
}
#var_dump($little_stones);
echo "$v \n";
if($v <= 0) return $ans;
return "The crow is dead.";
}
<?php
# https://www.codewars.com/kata/580435ab150cca22650001fb Find the lucky numbers.
function filter_lucky(array $a): array {
return array_values(array_filter($a,function($x){ return preg_match('/7/',$x);}));
}
<?php
# https://www.codewars.com/kata/595aa94353e43a8746000120 Lost number in number sequence.
function findDeletedNumber(array $arr, array $mixedArr): int {
return array_values(array_diff($arr, $mixedArr))[0] ?? 0;
}

Just PHP FUN 046.

Started at 21:27 10.07.2020 Friday July.
Finished at 23:45 10.07.2020 (2hrs 18minutes)

<?php
# https://www.codewars.com/kata/57fafb6d2b5314c839000195 Exclamation marks series #7: Remove words from the sentence if it contains one exclamation mark.
function remove(string $s): string {
$x = explode(" ",$s);
$x = array_filter($x,function($x){
return 1 != substr_count($x,'!');});
$x = implode(" ",$x);
return $x;
}
<?php
# https://www.codewars.com/kata/57faf32df815ebd49e000117
# Exclamation marks series #5: Remove all exclamation marks from the end of words.
function remove(string $s): string {
return implode(" ",array_map(function($x){ return rtrim($x,"! ");},explode(" ",$s)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment