Last active
August 20, 2017 12:40
-
-
Save 0xcrypto/7e4f496f21f11ddb383dba97bba57c15 to your computer and use it in GitHub Desktop.
This question was asked to me in an interview.
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
#!/usr/bin/env php | |
<?php | |
error_reporting(false); | |
$n = $ne = isset($argv[1]) ? $argv[1] : 5; | |
if(!intval($ne) || $ne < 1) { | |
echo "Usage: asteriskhill.php [height]\n"; | |
echo "height can be any integer above 0\n"; | |
exit(1); | |
} | |
for($i = 0; $i < $ne; $i++) { | |
for($j = 0; $j < $n; $j++) | |
echo " "; | |
for($j = 0; $j <= $i; $j++) | |
echo "*"; | |
echo "\n"; | |
$n--; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment