Skip to content

Instantly share code, notes, and snippets.

@elishaukpong
Last active August 8, 2021 12:34
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 elishaukpong/38788616791b06ae481ea9dd9ae9cd90 to your computer and use it in GitHub Desktop.
Save elishaukpong/38788616791b06ae481ea9dd9ae9cd90 to your computer and use it in GitHub Desktop.
Solution to the Staircase problem
<!-- Staircase detail
This is a staircase of size 4:
#
##
###
####
Its base and height are both equal to . It is drawn using # symbols and spaces. The last line is not preceded by any spaces.
Print a staircase of size n using # symbols and spaces.
Note: The last line must have 0 spaces in it. -->
function staircase($n) {
for($i = 0; $i < $n; $i++){
$printHashChecker = $i;
if($i !== $n - 1){
for($spaceToPrint = ($n - ($i + 1)); $spaceToPrint > 0; $spaceToPrint--){
echo " ";
}
}
if($printHashChecker != 0){
for($printHashChecker; $printHashChecker > 0; $printHashChecker--){
echo "#";
}
}
echo "# \n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment