Come for the quick hacks, stay for the epiphanies. PerlMonks

### American Flag?

 on Oct 02, 2001 at 00:18 UTC Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've tried and failed at this. An ASCII representation of an American Flag. But, here's the catch. Make it proportionate to the real flag with the right amount of stars and stripes in the right locations. I.e. Star configuration of 5 rows of 6 stars and 4 rows of 5 stars starting and ending with a row of 6 stars and alternating with a row of 5 stars:
```*   *   *   *   *   *
*   *   *   *   *
*   *   *   *   *   *
*   *   *   *   *
*   *   *   *   *   *
*   *   *   *   *
*   *   *   *   *   *
*   *   *   *   *
*   *   *   *   *   *
Start and end with red (dark) stripe. And have stripes red/whi/red/whi/red/whi/red beside the union (as a standard flag) See http://www.counterclaim.com/flags/USFlag800.gif for a proper flag and help me figure this thing out. It's driving me nuts. And of course, it must be obfuscated (smaller the better).

Replies are listed 'Best First'.
Re: American Flag?
by blakem (Monsignor) on Oct 02, 2001 at 02:04 UTC
Here was my contribution from a few weeks ago.
Note: chipmunk deserves nearly all of the credit (or blame) for this one.

```use LWP::Simple;print+(get"http://3467251276/?node=112874")=~/(\*.*?)<
+/s

-Blake

Re: American Flag?
by dragonchild (Archbishop) on Oct 02, 2001 at 00:41 UTC
If you're trying to make it completely proportional to an American flag in ASCII, you're going to fail. There are 7 stripes that are on level with the stars, but 9 lines of starts. How're you going to solve that?

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

It is possible indeed, if you consider acceptable a flag which is 117 ASCII lines long, with stars 7 lines "tall" and stripes 9 lines "tall".

Here's how. First, let's roughly split the flag into its areas:

```+-----------+--------------+
| A         |       B      |
|           |              |
|           |              |
|           |              |
+-----------+--------------+
|          C               |
|                          |
|                          |
+--------------------------+

Let's consider the height only. Area A is made of 9 rows of stars, area B is made of 7 stripes, Area C is made of 6 stripes.

Let x be the height of each star row, y be the height of each stripe, h the total height of the flag.

Then we have:

9x = 7y
13y = h

Where the first equation shows that 9 rows of stars must be as long as 7 stripes, the second shows that the flag is 13 stripes high.

With some simple algebraic operations we have:

x = 7h / 117
y = h / 13

Now, if we let h = 117, which is the minimum value satisfying these integer equations, we have that each row of stars must be 7 lines high and each stripe must be 9 characters high.

Doing this, areas A and B will both be 63 lines, area C will be 54 lines.

It is slightly imperfect because the flag has some space before the first row of stars and after the last, but it can work if each star is draw with a pattern like (dots instead of spaces for clarity, background and foreground swapped for clarity):

```..............
......XX......
..XX..XX..XX..
....XXXXXX....
....XX..XX....
..XX......XX..
..............

With a flag this big, one could even consider ASCII antialiasing :-)

Determining the length in characters, considering that the average font is not contained in a square cell, is left as an exercise. Drawing the star I considered each "pixel" being a couple of ASCII characters, this roughly gives a square using many fixed width fonts.

Area A could be 77 (7 characters each star * 11 columns) characters wide, out of a total width of 192 characters. This still gives a viewable image on a 1024x768 screen using a font with a 5x6 grid.

In conclusion, it is a rather interesting problem, which has lots of room for obfuscation, just think of the symmetry of one star for example, and the fact that it can be easily represented by an encoded bitmap.

-- TMTOWTDI

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://115956]
Approved by erzuuli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-02-27 22:42 GMT
Voting Booth?
My favourite way to spend a leap day ...

Results (26 votes). Check out past polls.