Login Register






[Golfing] Pascal's Triangle filter_list
Author
Message
[Golfing] Pascal's Triangle #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:
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.

Reply

RE: [Golfing] Pascal's Triangle #2
I should learn Pascal, and then do this in Pascal.


(11-02-2018, 02:51 AM)Skullmeat Wrote: Ok, there no real practical reason for doing this, but that's never stopped me.

Reply

RE: [Golfing] Pascal's Triangle #3
(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 Tongue
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.

Reply

RE: [Golfing] Pascal's Triangle #4
(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.

Novel idea, but shit language for a golfing challenge Tongue

Brainfuck it is then Tongue


(11-02-2018, 02:51 AM)Skullmeat Wrote: Ok, there no real practical reason for doing this, but that's never stopped me.

[+] 1 user Likes Blink's post
Reply