[Golfing] Pascal's Triangle 05-31-2017, 05:47 AM
#1
First off, sorry for the recent inactivity. I'm still in the middle of culminating/exam period, so I have barely any time for anything that isn't school (though there's something cool you guys might like coming out of it). Formalities aside, I decided to tinker with a script I made while not paying attention in maths (but it's kind of related?), so I thought it would make a good challenge.
The task: write a program that prints 10 rows of Pascal's Triangle (in any format including any array notation, like below). The values for which are below:
My original refactor made the script a one-liner, but I made another, slightly shorter version that uses multiple statements.
Bonus points if you can pull it off in J or APL, because that shit is super weird but really cool.
The task: write a program that prints 10 rows of Pascal's Triangle (in any format including any array notation, like below). The values for which are below:
Code:
[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]My original refactor made the script a one-liner, but I made another, slightly shorter version that uses multiple statements.
Spoiler: One-liner; Ruby - 72 bytes
Code:
->t{10.times{p (t<<[1,*t[-1].each_cons(2).map{|s|s.sum},1])[-2]}}[[[1]]]Spoiler: Multi-statement; Ruby - 68 bytes
Code:
t=[[1]];10.times{t<<[1,*t[-1].each_cons(2).map{|s|s.sum},1];p t[-2]}Bonus points if you can pull it off in J or APL, because that shit is super weird but really cool.
(This post was last modified: 05-31-2017, 05:49 AM by Inori.)
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.

















![[+]](https://sinister.li/images/modern/collapse_collapsed.png)

