Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 3, 2020 16: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/e11ed4bf2be180d866929cbec0a3944a to your computer and use it in GitHub Desktop.
Save lbvf50mobile/e11ed4bf2be180d866929cbec0a3944a to your computer and use it in GitHub Desktop.
Just PHP FUN 040.
<?php
# https://www.codewars.com/kata/558f9f51e85b46e9fa000025 Difference Of Squares.
function difference_of_squares(int $n): int {
return abs(array_sum(array_map(function($x){return $x**2;}, range(1,$n))) - array_sum(range(1,$n))**2) ;
}
<?php
# https://www.codewars.com/kata/58f0ba42e89aa6158400000e Folding your way to the moon.
function fold_to($distance) {
if(0 > $distance) return null;
$x = 0.0001; $ans = 0;
while($x < $distance){
$x *= 2; $ans += 1;
}
return $ans;
}
<?php
# https://www.codewars.com/kata/58279e13c983ca4a2a00002a Coding Meetup #2 - Higher-Order Functions Series - Greet developers.
function greet_developers($a) {
return array_map(function(&$x){
$x['greeting'] = "Hi {$x['first_name']}, what do you like the most about {$x['language']}?";
return $x;
},$a);
}

Just PHP FUN 040.

Started at 21:25 03.07.2020 Friday July.
Finished at 23:17 03.07.2020 Friday July. (1hr 52minues)

<?php
# https://www.codewars.com/kata/570523c146edc287a50014b1 Especially Joyful Numbers.
function number_joy(int $n): bool {
$sum = array_sum(str_split("$n")); $rev = intval(strrev("$sum"));
return 0 != $sum && 0 == $n % $sum && $n == $sum * $rev;
}
<?php
# https://www.codewars.com/kata/57faefc42b531482d5000123 Exclamation marks series #3: Remove all exclamation marks from sentence except at the end.
function remove(string $s): string {
return str_replace("!","",$s).preg_replace('/.*[^!]+(!*)$/','$1',$s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment