Created
April 11, 2019 04:14
-
-
Save naderghanbari/0f55f838992416f426d4bfb37f2770e8 to your computer and use it in GitHub Desktop.
Pascal Triangle in Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nextRow(r: Stream[Long]) = | |
(0L #:: r).sliding(2).map(_.sum).toStream :+ 1L | |
val pascal = | |
continually(empty).scanLeft(Stream(1L)) { (r, _) => nextRow(r) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment