Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Pascal's Triangle (Scala)
- object Solution {
- def main(args: Array[String]) {
- val row = io.Source.stdin.getLines
- .take(1)
- .map(_.trim.toInt)
- .next()
- def triangle(row: Int): Unit = {
- def doT(row: Int, prev: List[Int]): Unit = {
- if (row == 0) return
- val next = prev.sliding(2, 1)
- .map(pair => pair.sum)
- .toList
- println (next mkString " ")
- doT(row - 1, (0 :: next) :+ 0)
- }
- doT(row, List(1))
- }
- triangle(row)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement