Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 12, 2020 17:38
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/73cb9872973f2d14424132b9aef28318 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/73cb9872973f2d14424132b9aef28318 to your computer and use it in GitHub Desktop.
Just PHP FUN 074.
<?php
# https://www.codewars.com/kata/56dbeec613c2f63be4000be6 Moves in squared strings (III)
function diag1Sym($s) {
$x = explode("\n",$s);
$z = array_map('str_split',$x);
$size = count($z);
for($i = 0; $i < $size; $i+=1)
for($j = $i+1; $j < $size; $j+=1){
$tmp = $z[$i][$j];
$z[$i][$j] = $z[$j][$i];
$z[$j][$i] = $tmp;
}
return implode("\n",array_map('implode',$z));
}
function rot90Clock($s) {
$x = explode("\n",$s);
$z = array_map('str_split',$x);
$size = count($z);
$ans = [];
for($r = 0; $r < $size; $r +=1){
$ans[] = [];
for($c = 0; $c < $size; $c += 1){
$ans[$r][$c] = $z[ $size - $c - 1][$r];
}
}
return implode("\n",array_map('implode',$ans));
}
function selfieAndDiag1($s) {
$dg = diag1Sym($s);
$x1 = explode("\n",$s); $x2 = explode("\n",$dg);
$z = array_map(function($x){ return $x[0]."|".$x[1];},array_map(null,$x1,$x2));
return implode("\n",$z);
}
function oper($fct, $s) {
return call_user_func ( $fct, $s );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment