Skip to content

Instantly share code, notes, and snippets.

@mRoca
Last active March 25, 2022 11:32
Show Gist options
  • Save mRoca/de4257cb524f2c0781ae7777c7cca58c to your computer and use it in GitHub Desktop.
Save mRoca/de4257cb524f2c0781ae7777c7cca58c to your computer and use it in GitHub Desktop.
<?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