Skip to content

Instantly share code, notes, and snippets.

@0xcrypto
Last active August 20, 2017 12:40
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 0xcrypto/7e4f496f21f11ddb383dba97bba57c15 to your computer and use it in GitHub Desktop.
Save 0xcrypto/7e4f496f21f11ddb383dba97bba57c15 to your computer and use it in GitHub Desktop.
This question was asked to me in an interview.
#!/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