Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 8, 2020 16:24
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/3691c5777e844d9c980fbb9d8a0bfbf1 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/3691c5777e844d9c980fbb9d8a0bfbf1 to your computer and use it in GitHub Desktop.
Just PHP FUN 018.
<?php
# https://www.codewars.com/kata/58aa68605aab54a26c0001a6 Simple Fun #144: Distinct Digit Year.
function distinctDigitYear($year) {
$year += 1;
$distincts = function($x){
$array = str_split($x);
$uniq = array_unique($array);
return count($array) == count($uniq);
};
while(!$distincts($year)) $year += 1;
return $year;
}
<?php
# https://www.codewars.com/kata/58acfe4ae0201e1708000075 Simple Fun #152: Invite More Women?
function invite_more_women(array $a): bool {
return array_sum($a) > 0;
}

Just PHP FUN 018.

Started at 21:40 08.06.2020 Monday June.
Finished at 23:24 08.02.2020 Monday June. (1hr 44minutes)

<?php
# https://www.codewars.com/kata/581e476d5f59408553000a4b Fun with lists: length.
function length($head) {
$length = 0;
while($head){
$head = $head->next;
$length += 1;
}
return $length;
}
<?php
# https://www.codewars.com/kata/58845748bd5733f1b300001f Simple Fun #10: Range Bit Counting.
function range_bit_count(int $a, int $b): int {
$x = range($a,$b);
return array_reduce($x,function($a, $x){
echo "$a and $x =>".decbin($x)." \n";
return $a + substr_count(decbin($x),1);},0);
}
<?php
# https://www.codewars.com/kata/5bb804397274c772b40000ca Stacked Balls - 2D.
function ($n) {
if( 0 == $n) return 0;
if( 1 == $n) return 1;
return round(sqrt((3/4)*($n-1)*($n-1))+1,3);
}
@lbvf50mobile
Copy link
Author

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