Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for Support and Testing.
Download

Github repo cloud-examples: https://github.com/sagemath/cloud-examples

11080 views
License: MIT
def sierpinski(N): '''Generates the Sierpinski triangle by taking the modulo-2 of each element in Pascal's triangle''' return [([0] * (N // 2 - a // 2)) + [binomial(a, b) % 2 for b in range(a + 1)] + ([0] * (N // 2 - a // 2)) for a in range(0, N, 2)] @interact def _(N=slider([2 ** a for a in range(12)], label='Number of iterations', default=64), size=slider(1, 20, label='Size', step_size=1, default=9)): M = sierpinski(2 * N) matrix_plot(M, cmap='binary').show(figsize=[size, size])
Interact: please open in CoCalc