Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 1, 2020 14:01
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/d66f5d99eafd6e74ae5e79d95b3dfa18 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/d66f5d99eafd6e74ae5e79d95b3dfa18 to your computer and use it in GitHub Desktop.
Just PHP FUN 038.
<?php
# https://www.codewars.com/kata/5886d35d4703f125a6000008 Simple Fun #22: Is Smooth?
function is_smooth(array $arr): bool {
$s = count($arr); $li = $s - 1; $md = floor($s/2);
if(1 == $s%2) return $arr[0] == $arr[$li] && $arr[0] == $arr[$md];
$sm = $arr[$md] + $arr[$md-1];
return $arr[0] == $arr[$li] && $arr[0] == $sm;
}

Just PHP FUN 038.

Started at 17:16 01.07.2020 July Wednesday.
Finished at 21:00 01.07.2020 July Wednesday. (2hrs 44 minutes)

<?php
# https://www.codewars.com/kata/557af4c6169ac832300000ba Help the Fruit Guy.
function removeRotten($fruitBasket) {
if(!$fruitBasket || empty($fruitBasket)) return [];
return array_map(function($x){ return preg_replace('/rotten/','',strtolower($x));},$fruitBasket);
}
<?php
# https://www.codewars.com/kata/57ebdf944cde58f973000405 Reverse Letters in Sentence.
function reverser(string $sentence): string {
return preg_replace_callback('/\S+/',function($arr){
return strrev($arr[0]);}, $sentence);
}
<?php
# https://www.codewars.com/kata/5a995c2aba1bb57f660001fd Scrolling Text.
function scrollingText($text) {
$s = strlen($text); $txt = strtoupper($text); $ans = [];
for($i = 0; $i < $s; $i += 1){
array_push($ans,$txt); $txt = substr($txt,1).substr($txt,0,1);
}
return $ans;
}
<?php
# https://www.codewars.com/kata/5adadcb36edb07df5600092e Count up the points for the 7 Wonders board game! Easy version.
// Calculate how many points you would make in 7 Wonders from these science cards!
function sevenWondersScience(...$x){
// Do the code here
echo "Input :".implode(",",$x)." \n";
$a = array_sum(array_map(function($x){ return $x*$x;},$x));
$b = 0;
if(has_0($x)) {$b = 0; }
else { $b = min($x) * 7; }
echo "a = $a and b = $b, b/7 =".($b/7)." \n";
return $b + $a;
}
function has_0($x){ return array_search(0,$x) === false ? false : true; }
@lbvf50mobile
Copy link
Author

lbvf50mobile commented Jul 1, 2020

Input :0,0,1
a = 1 and b = 7, b/7 =1

Welcome to the REpeat:5,4,5
Min and max 4 and 5
a = 66 and b = 14, b/7 =2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment