Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 1, 2020 14:32
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/d54e14d1eebfd4dd5c9be490aed1db18 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/d54e14d1eebfd4dd5c9be490aed1db18 to your computer and use it in GitHub Desktop.
Just PHP FUN 012.
<?php
# https://www.codewars.com/kata/5a651865fd56cb55760000e0 Array Leaders (Array Series #3).
function arrayLeaders($numbers) {
$size = count($numbers); $answer = [];
$sum = 0;
for($j = $size - 1; $j >= 0; $j -= 1){
if($numbers[$j] > $sum) array_unshift($answer,$numbers[$j]);
$sum += $numbers[$j];
}
return $answer;
}
<?php
# https://www.codewars.com/kata/542c0f198e077084c0000c2e Count the divisors of a number.
function divisors($n) {
$sum = 0;
for($i = 1; $i <= $n; $i += 1)
if(0 == $n%$i) $sum +=1 ;
return $sum;
}
<?php
# https://www.codewars.com/kata/554e4a2f232cdd87d9000038 Complementary DNA.
function DNA_strand($dna) {
$mp = ["A"=>"T","T"=>"A","C"=>"G","G"=>"C"];
return implode(array_map(function($x) use($mp){ return $mp[$x];},str_split($dna)));
}
# ----------------------------------------------------------
function DNA_strand($dna) {
return strtr($dna,"ATCG","TAGC");
}

Just PHP FUN 012.

Started at 01.06.2020 19:23 Monday June.
Finished at 01.06.2020 21:31 Monday June. (2hrs 08minutes)

<?php
# https://www.codewars.com/kata/5a523566b3bfa84c2e00010b Minimize Sum Of Array (Array Series #1).
function minSum($arr) {
sort($arr); $sum = 0;
$i = 0; $j = count($arr) - 1;
while( $i < $j){
$sum += $arr[$i] * $arr[$j];
$i += 1; $j -= 1;
}
return $sum;
}
<?php
# https://www.codewars.com/kata/56e9e4f516bcaa8d4f001763 Sum of numbers from 0 to N.
class SequenceSum {
public function showSequence($count) {
if($count < 0) return "$count<0";
if(0 == $count) return "0=0";
$sum = ($count*(1+$count))/2;
$line = implode(range(0,$count),"+");
return "$line = $sum";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment