Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 22, 2020 16:25
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/03bde68ea6b2bf1636e77b654fba6595 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/03bde68ea6b2bf1636e77b654fba6595 to your computer and use it in GitHub Desktop.
Just PHP FUN 109.
<?php
# https://www.codewars.com/kata/5970fc389f4a1ce8de000061 Drawing a cube.
Class Draw
{
public static function drawCube(int $n)
{
if( 0 == $n) return "";
if( 1 == $n) return "#\n";
if( 2 == $n) return " ##\n###\n##\n";
$answer = [];
$ln = str_repeat("#",$n);
$dt = "#". str_repeat("*",$n-2) . "#";
$fc = "#". str_repeat(" ",$n-2) . "#";
$answer[] = str_repeat(" ",$n-1). $ln;
for($i = 0; $i < $n - 2; $i++)
$answer[] = str_repeat(" ",$n - 2 - $i).$dt.str_repeat("*", $i)."#";
$answer[] = $ln . str_repeat("*", $n - 2) . "#";
for($i = 0; $i < $n - 2; $i++)
$answer[] = $fc.str_repeat(" ",$n - 3 - $i)."#";
$answer[] = $ln;
return implode("\n",$answer);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment