Coach,
I know what you are looking for is a quick solution to your problem so you can move on. There are plenty of images of Pascal's Triangle that can be found on google or web apps that generate them. Since you are student and your job is to learn, I will tell you how I would do it programmatically if it were me.

The first thing I would do is ask how many rows the user wanted to generate. This will tell me two pieces of valuable information. The first is what the largest number in the triangle will be. If you are not sure why this is, I will remind you of the relationship between Pascal's Triangle and combinatorials (C = N choose K). The second piece of information is how many leading units you need for the first row. What do you mean by unit you ask - read on.

The next thing I would do is determine the length of the largest number in the triangle. This will become 1 unit. Every value (space or number) will be this wide. This will make the triangle look as smooth as possible (assuming monospace font).

Finally, I would start filling in each row. Filling up the leading white space units and then placing each number. Each number will need to be centered in the unit - probably using sprintf. If the triangle still does not look smooth it is probably a result of imperfect centering. You may be able to remedy this by varying which side to leave the extra space on (round robin, random, odd/even, etc).

You probably already have your solution and have moved on but if you would like to really spend some time learning perl - please feel free to ask questions and we will help you out as best as we can.

Cheers - L~R


In reply to Re: Equilateral Pascal's Triangle in perltex by Limbic~Region
in thread Equilateral Pascal's Triangle in perltex by Coach

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.