Skip to content

Instantly share code, notes, and snippets.

@naderghanbari
Created April 11, 2019 04:14
Show Gist options
  • Save naderghanbari/0f55f838992416f426d4bfb37f2770e8 to your computer and use it in GitHub Desktop.
Save naderghanbari/0f55f838992416f426d4bfb37f2770e8 to your computer and use it in GitHub Desktop.
Pascal Triangle in Scala
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