Last active
March 25, 2022 11:32
-
-
Save mRoca/de4257cb524f2c0781ae7777c7cca58c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* Usage : php staircase.php 4 | |
* | |
* # | |
* ## | |
* ### | |
* #### | |
*/ | |
function drawStaircase(int $n): void | |
{ | |
for ($i = 1; $i <= $n; $i++) { | |
echo str_pad(str_repeat('#', $i), $n, ' ', STR_PAD_LEFT) . "\n"; | |
} | |
} | |
$n = (int)($argv[1] ?? 0); | |
if ($n <= 0) { | |
throw new \InvalidArgumentException('You must provide a valid "n" number'); | |
} | |
drawStaircase($n); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment