The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.
···
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
by Dirk Meijer
I recently showed a friend what an amazing language Ruby was, by quickly
programming up a script to calculate Fibonacci's Sequence, and his first
response was: "Can you do Pascal's Triangle?" So I did, which proved harder
than expected.
For those not familiar with Pascal's Triangle, it is very similar to Fibonacci's
Sequence. It's a pyramid of numbers. The outside of the pyramid is all ones, the
other numbers are the sum of the two numbers above, like this:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
The input and output should be as follows:
$ ruby pp_pascal.rb 10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
A number should be given as command-line argument. This is the amount of rows
the triangle has. For the output, there should be spacing between the numbers
based on the size of the numbers with the most digits, so it will look like a
proper triangle.
Good luck!
[Editor's Note: If you are working through Chris Pine's Learn to Program, you
can do this problem using only things you learned in the first eight chapters.
Since he doesn't teach how to grab the row count in those pages though, just add
this as the first line of your program: `rows = ARGV[0].to_i]`. After that,
the rows variable will hold the number of rows to print. --JEG2]