Pascal's triangle: Difference between revisions

Content added Content deleted
Line 783: Line 783:
end</lang>
end</lang>
=={{header|Scala}}==
=={{header|Scala}}==
Simple recursive implementation:
Simple recursive row definition:
<lang scala>
<lang scala>
def tri(rows:Int):List[Int] = { rows match {
def tri(rows:Int):List[Int] = { rows match {
Line 791: Line 791:
}
}
</lang>
</lang>
Funtion to pretty print it:
Funtion to pretty print r rows:
<lang scala>
<lang scala>
def prettytri(r:Int) = (1 to r) foreach {n=>print(" "*(r-n)); tri(n) map (c=>print(c+" ")); println}
def prettytri(r:Int) = (1 to r) foreach {n=>print(" "*(r-n)); tri(n) map (c=>print(c+" ")); println}