[Challenge] Seeing Stars (and a Diamond)
Posted: Sun Sep 20, 2009 6:33 pm
Write a script to generate stars in a diamond pattern as shown below. The width of the diamond should be determined by user input. Both Web scripts and command-line scripts are acceptable.
Example 1: seven stars wide
All lines should contain stars. If the width is even, the first and last lines will contain two stars each.
Example 2: six stars wide
If you want more of a challenge, write a variation with one or more of these constraints:
Edit: This post was recovered from search engine cache.
Example 1: seven stars wide
Code: Select all
*
***
*****
*******
*****
***
* Example 2: six stars wide
Code: Select all
**
****
******
****
** - Use only two variables (not including user-submitted variables).
- Use only one loop with no conditions in the loop body and only one condition in the loop header.
Edit: This post was recovered from search engine cache.