![]() |
|
[Golfing] Pascal's Triangle - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [Golfing] Pascal's Triangle (/Thread-Golfing-Pascal-s-Triangle) |
[Golfing] Pascal's Triangle - Inori - 05-31-2017 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: 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 bytesCode: ->t{10.times{p (t<<[1,*t[-1].each_cons(2).map{|s|s.sum},1])[-2]}}[[[1]]]Spoiler: Multi-statement; Ruby - 68 bytesCode: 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. RE: [Golfing] Pascal's Triangle - Blink - 06-02-2017 I should learn Pascal, and then do this in Pascal. RE: [Golfing] Pascal's Triangle - Inori - 06-03-2017 (06-02-2017, 04:55 AM)Ender Wrote: I should learn Pascal, and then do this in Pascal. Novel idea, but shit language for a golfing challenge
RE: [Golfing] Pascal's Triangle - Blink - 06-03-2017 (06-03-2017, 02:53 AM)Inori Wrote:(06-02-2017, 04:55 AM)Ender Wrote: I should learn Pascal, and then do this in Pascal. Brainfuck it is then
|