Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 12, 2020 15:51
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/9bfb9fd7328921411dc534c0a5077f1c to your computer and use it in GitHub Desktop.
Save lbvf50mobile/9bfb9fd7328921411dc534c0a5077f1c to your computer and use it in GitHub Desktop.
Just PHP FUN 022.
<?php
# https://www.codewars.com/kata/578553c3a1b8d5c40300037c Ones and Zeros.
function binaryArrayToNumber($arr) {
return bindec(implode('',$arr));
}
<?php
# https://www.codewars.com/kata/590e03aef55cab099a0002e8 Incrementer.
# https://www.codewars.com/users/Dzienny
function incrementer($nums) {
foreach($nums as $i=>&$n) $n = ($n + $i + 1)%10;
return $nums;
}
#-------------------------------------------------
function incrementer($nums) {
foreach($nums as $i=>$v) $nums[$i] = ($nums[$i]+($i+1))%10;
return $nums;
}

Just PHP FUN 022.

Started at 22:00 12.06.2020 Friday June.
Finished at 22:45 12.06.2020 Friday June. (0hrs 45minutes)

<?php
# https://www.codewars.com/kata/5901f361927288d961000013 Product of Array Items.
function product($a) {
if(empty($a)) return null;
return array_product($a);
}
<?php
# https://www.codewars.com/kata/59dd2c38f703c4ae5e000014 Numbers in strings.
function solve($s) {
return max(array_filter(explode(' ',preg_replace('/[a-z]/',' ',$s))));
}
<?php
# https://www.codewars.com/kata/598d91785d4ce3ec4f000018 Word values.
function word_value(array $a): array {
$ans = [];
foreach($a as $i=>$v){
$sum = 0;
foreach(str_split(preg_replace('/[^a-z]/',"",$v)) as $c) $sum += ($i+1) * (ord($c)+1 - ord('a'));
array_push($ans,$sum);
}
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment