User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 363,440 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,205 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser:

Pascal's Triangle

Join Date: Oct 2007
Posts: 169
Reputation: sarehu is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 11
sarehu's Avatar
sarehu sarehu is offline Offline
Junior Poster

Re: Pascal's Triangle

  #5  
May 5th, 2008
That's because J is deliberately cryptic and hides all the hard work behind pre-written combinators and functions, in this case ! being "choose". Given the equivalent of these two defined in Haskell:

comb n k = foldl' (\x y -> ((n - x + 1) * y) `div` x) 1 [1..k]

table f xs ys = foldr ((:) . (`map` ys) . f) [] xs

Then producing Pascal's triangle is as simple as join (table comb) [0..] .

But overall a much simpler solution is
iterate (\xs -> zipWith (+) (0:xs) (xs++[0])) [1]
Reply With Quote  
All times are GMT -4. The time now is 2:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC