Using Pascal's triangle to draw fractals
Triangles are a particular matrix type. Each line contains exactly as many nonzero elements as the line index in the matrix. Here is a sample triangle depicted as a vector of vectors in Clojure:
[[1 0 0 0 0 0 0] [1 1 0 0 0 0 0] [1 1 1 0 0 0 0] [1 1 1 1 0 0 0] [1 1 1 1 1 0 0] [1 1 1 1 1 1 0] [1 1 1 1 1 1 1]]
Now, we can simply omit the zeros altogether and get a real triangle, graphically speaking:
[[1] [1 1] [1 1 1] [1 1 1 1] [1 1 1 1 1] [1 1 1 1 1 1] [1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1]]
Pascal's triangle is a matrix whose elements are computed as the sum of the elements that are directly above it and the element to the left of the elements that are directly above it. The very first element is 1
. This matrix ...
Get Clojure Data Structures and Algorithms Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.