Last active
August 8, 2021 12:34
-
-
Save elishaukpong/38788616791b06ae481ea9dd9ae9cd90 to your computer and use it in GitHub Desktop.
Solution to the Staircase problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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