Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active July 21, 2020 16:20
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/a4e167f69746835d97e098d26eb4f099 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/a4e167f69746835d97e098d26eb4f099 to your computer and use it in GitHub Desktop.
Just PHP FUN 055.
<?php
# https://www.codewars.com/kata/56242b89689c35449b000059 draw me a chessboard.
function chessBoard($rows, $columns) {
$row = function($a,$b) use ($columns) {
for($i = 0, $ans = []; $i < $columns; $i += 1 ) array_push($ans, 0 == $i%2 ? $a : $b);
return $ans;
};
for($i = 0, $ans = []; $i < $rows; $i += 1) array_push($ans, 0 == $i%2 ? $row("O","X") : $row("X",'O'));
return $ans;
}
<?php
# https://www.codewars.com/kata/577ad961ae2807182f000c29 Count the Characters.
function count_char(string $s, string $c): int {
return substr_count(strtoupper($s),strtoupper($c));
}
<?php
# https://www.codewars.com/kata/588e2a1ad1140d31cb00008c Pairs of integers from m to n.
function generatePairs($m,$n){
$ans = [];
for($i = $m; $i <= $n; $i += 1)
for($j = $i; $j <= $n; $j += 1) array_push($ans,[$i,$j]);
return $ans;
}
<?php
# https://www.codewars.com/kata/58902f676f4873338700011f Lucky Bus Ticket.
function isLucky($ticket){
$x = preg_match('/^(\d{3})(\d{3})$/',$ticket, $matches);
if(!$x) return false;
$sum = function($x){ return array_sum(str_split($x));};
return $sum($matches[1]) == $sum($matches[2]);
}

Just PHP FUN 055.

Started at 22:21 21.07.2020 Tuesday July.
Finished at 23:19 21.07.2020 Tuesday July. (0hrs 58minutes)

<?php
# https://www.codewars.com/kata/589519d1f0902e01af000054 Perimeter sequence.
function perimeter_sequence(int $a, int $n): int {
return $a*4*$n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment