Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 2, 2020 16:35
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/9299ed232f7345619a0da7c42ee929bf to your computer and use it in GitHub Desktop.
Save lbvf50mobile/9299ed232f7345619a0da7c42ee929bf to your computer and use it in GitHub Desktop.
Just PHP FUN 013.
<?php
# https://www.codewars.com/kata/5467e4d82edf8bbf40000155 Descending Order.
function descendingOrder(int $n): int {
$array = array_map("intval",str_split($n));
rsort($array);
return intval(implode($array));
}
<?php
# https://www.codewars.com/kata/54ba84be607a92aa900000f1 Isograms.
function isIsogram($string) {
$s = strtolower($string);
$arr = str_split($s);
$unique = array_unique($arr);
return $arr == $unique;
}

Just PHP FUN 013.

Started at 02.06.2020 at 21:18 June Tuesday.
Finished at 02.06.2020 at 23:33 June Tuesday. (2hrs 15minutes)

<?php
# https://www.codewars.com/kata/5d9f95424a336600278a9632 Sum of powers of 2.
// return an array of numbers (that are a power of 2)
// for which the input "n" is the sum
function powers($n) {
$str = decbin($n); $answer = [];
$arr = str_split($str); $arr = array_reverse($arr);
foreach($arr as $i=>$x)
if("1" == $x) array_push($answer, pow(2,$i));
return $answer;
}
<?php
# Unsolved yet.
# https://www.codewars.com/kata/5b0c0ec907756ffcff00006e Floating-point Approximation (III).
function quadratic($a, $b, $c) {
$descr = $b*$b - 4*$a*$c;
$x1 = (-1*$b + $descr)/(2*$a);
$x2 = (-1*$b - $descr)/(2*$a);
$x1 = abs($x1); $x2 = abs($x2);
echo "Roots are: $x1 and $x2\n";
return $x2;
}
<?php
# https://www.codewars.com/kata/56dbe0e313c2f63be4000b25 Moves in squared strings (I).
function vertMirror($s) {
$arr = explode("\n",$s);
return implode("\n",array_map("strrev",$arr));
}
function horMirror($s) {
$arr = explode("\n",$s);
return implode("\n",array_reverse($arr));
}
function oper($fct, $s) {
return $fct($s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment