Pascal's triangle: Difference between revisions

add E example
(add E example)
Line 292:
foreach(i ; [16]) writef(sierpinski(i)) ;
}</lang>
 
=={{header|E}}==
 
So as not to bother with text layout, this implementation generates a HTML fragment. It uses a single mutable array, appending one 1 and adding to each value the preceding value.
 
<lang e>def pascalsTriangle(n, out) {
def row := [].diverge(int)
out.print("<table style='text-align: center; border: 0; border-collapse: collapse;'>")
for y in 1..n {
out.print("<tr>")
row.push(1)
def skip := n - y
if (skip > 0) {
out.print(`<td colspan="$skip"></td>`)
}
for x => v in row {
out.print(`<td>$v</td><td></td>`)
}
for i in (1..!y).descending() {
row[i] += row[i - 1]
}
out.println("</tr>")
}
out.print("</table>")
}</lang>
 
<lang e>def out := <file:triangle.html>.textWriter()
try {
pascalsTriangle(15, out)
} finally {
out.close()
}
makeCommand("yourFavoriteWebBrowser")("triangle.html")</lang>
 
 
 
=={{header|Factor}}==