Generate Pascal's Triangle

for((r=1;r<10;r++));do v=1;echo -n "$v ";for((c=1;c<$r;c++));do v2=$(($(echo "$v*($r-$c)/$c")));echo -n "$v2 ";v=$v2;done;echo;done
http://en.wikipedia.org/wiki/Pascal%27s_triangle This one's for bartonski. Enjoy. 132 characters. I'm sure we can do better. Note: after row 64 we overflow integer maths.
Sample Output
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 

0
By: flatcap
2011-02-10 18:38:04

What Others Think

ok... you win...
glaudiston · 506 weeks and 6 days ago
For a better formatted output: (ignore the " , is a try to get a correct view in comment.) { y="$({ x="$({ for((r=1;r<10;r++));do v=1;echo -n "$v ";for((c=1;c<$r;c++));do v2=$(($(echo "$v*($r-$c)/$c")));echo -n "$v2 ";v=$v2;done;echo;done; })"; echo -e "$x" | tail -n1; })"; }; echo -e "$x" | while read l; do j=$((1+${#y}-${#l}/2)); echo "$(while ((i++ <= j)); do echo -n " ";done;)$l";done " 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
glaudiston · 506 weeks and 6 days ago
First time i am facing this same issue,so just click this site and get the one of the simple best solution to find the set this device how do i fix connections for bluetooth audio devices and wireless displays in windows 10 now finally just one a single click this website and learn more about.
KGF123 · 23 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: