Skip to content

Instantly share code, notes, and snippets.

@nobsun
Created June 11, 2013 23:25
Show Gist options
  • Save nobsun/5761702 to your computer and use it in GitHub Desktop.
Save nobsun/5761702 to your computer and use it in GitHub Desktop.
Data.List.mapAccumR のつかいどころ ref: http://qiita.com/items/389da409cabceebd8ab7
import Data.List (mapAccumR)
pascal :: [[Integer]]
pascal = [1] : [f cs | cs <- pascal ]
where
f xs = snd $ mapAccumR g xs' xs'
where xs' = 0:xs
g (y:ys) z = (ys, y+z)
comb :: Int -> Int -> Integer
comb = (!!) . (pascal !!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment