Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 23, 2020 15:04
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/f763a7af553774892093e36aa293ed3f to your computer and use it in GitHub Desktop.
Save lbvf50mobile/f763a7af553774892093e36aa293ed3f to your computer and use it in GitHub Desktop.
Just PHP FUN 057.
<?php
# https://www.codewars.com/kata/58644e8ddf95f81a38001d8d Make a square box!
function box(int $n): array {
if(0 == $n) return [];
if(1 == $n) return ['-'];
$ans = []; array_push($ans,str_repeat('-',$n));
$str = $n > 2 ? "-".str_repeat(' ',$n-2)."-" : "--";
for($i = 0; $i < $n - 2; $i += 1) array_push($ans,$str);
array_push($ans,str_repeat('-',$n));
return $ans;
}
<?php
# https://www.codewars.com/kata/5841f4fb673ea2a2ae000111 Series of integers from 0 to n.
function generate_integers(int $n): array {
return range(0,$n);
}

Just PHP FUN 057.

Started at 21:39 23.07.2020 Thursday July.
Finished at 22:04 23.07.2020 Thurday July (0hrs 25minutes)

<?php
# https://www.codewars.com/kata/5844a422cbd2279a0c000281 Debug the functions EASY
function multi($array) {
return array_product($array);
}
function add($array) {
return array_sum($array);
}
function reverse($string) {
return strrev($string);
}
<?php
# https://www.codewars.com/kata/57fafd0ed80daac48800019f Exclamation marks series #8: Move all exclamation marks to the end of the sentence.
function remove(string $s): string {
$x = str_replace('!','',$s,$n);
return $x.str_repeat('!',$n);
}
<?php
# https://www.codewars.com/kata/586efc2dcf7be0f217000619 String reverse slicing 101.
function reverse_slice(string $s): array {
$s = strrev($s); $ans = [];
for($i = 0; $i < strlen($s); $i+=1) array_push($ans,substr($s,$i));
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment