Jump to content

Pyramid of Asterix


Vivid Lust

Recommended Posts

lol, reminds of the times i was in class and had to do this horrible job in Java, VB.NET, C++, bweh :S

 

for ($i = 1; $i <= 41; $i++) {
   for ($j = 0; $j < $i; $j++) {
       echo '*';
   }
   echo '<br />';
}

 

this will give you something like:

 

*

**

***

..

 

to get something like this:

 

      *

      **

    ***

 

you will most presumably need a table, as in php you don't have something like:

 

drawer.pos(x, y)

Link to comment
https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599310
Share on other sites

[pre]                    *

                  ***

                 *****

                *******

               *********

              ***********

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

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

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

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

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

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

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

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

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

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

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

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

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

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

*****************************************[/pre]

 

:P

Link to comment
https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599312
Share on other sites

for ($x = 0; $x < 21; $x++)
{
    $spacer = str_repeat(" ", (21 - $x));
    $stars = str_repeat("*", ($x*2)+1);
    print $spacer . $stars . $spacer . "\n";
}

 

 

Lol... you'd need to use a fixed sized font for it to display, and if it's for a webpage - perhaps use &NBSP; instead of a space! 

 

Link to comment
https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599317
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.