/php-dynamic-pyramid

A simple way to generate dynamic pyramid without PHP looping functions (for, foreach, while) via CLI.

Primary LanguagePHPMIT LicenseMIT

PHP Dynamic Pyramid

Challenge yout self?

Can you write only 5 lines of php code to make output like this?

  • 5 lines of code
  • without for, forach, & while
  • dynamic level
*******************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************

Given Up?

You can run it via terminal or command line:

Set your working directory to ./php-dynamic-pyramid
type php php-dynamic-pyraid.php then enter

or open it via browser.

The Goal

To simulate of using native php recursive function without using for, foreach, & while.

Sample output:

*******************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************

0.0052859783172607

One-side-up pyramid:

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************

0.0028870105743408

One-side-bottom pyramid:

*******************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *

0.0045459270477295