ah, the mystery of the pyramids! examine the evidence!
each level is made of asterisks and spaces.
they printed spaces, stars, and a newline. but how many spaces and stars?
your example has 8 levels.
how many spaces?
1234567* = 7
123456*** = 6
12345***** = 5
1234******* = 4
123********* = 3
12*********** = 2
1************* = 1
***************= 0
|
the number of spaces start at 7 and decrease -1 each level.
7 = numberoflevels - 1. what a surpise! did you see that coming? i didn't.
how many stars?
1 = 1
123 = 3
12345 = 5
1234567 = 7
123456789 = 9
12345678901 = 11
1234567890123 = 13
123456789012345= 15
|
the number of stars start at 1 and increase +2 each level. odd numbers!
we can produce the same results!
// our important variables
numberoflevels = 8
spaces = numberoflevels - 1
stars = 1
// begin level loop
print spaces, print stars.
// change stuff
then get decrease the number of spaces and add some stars.
spaces = spaces - 1
stars = stars + 2
// check condition, end loop
repeat printing and changing the spaces and stars until we have done numberoflevels.
that's one way to build a pyramid. another way has to do with aliens. scary.
you know what to do next?