From the course: Coding Exercises: Scala

Unlock the full course today

Join today to access over 24,100 courses taught by industry experts.

Sierpinski Triangle

Sierpinski Triangle

(playful game music) (system chimes) (quirky tone plays) - [Instructor] The Sierpinski triangle is an interesting fractal. It starts by putting a triangle above two triangles that are beside each other. Successive iterations repeat the pattern with the fragment from the previous iteration. Your challenge is to implement the Sierpinski triangle. We've given you a bit of code to start with in the file 01_14b.scala. Now pause the video, come back when you've completed the challenge, and see how I did it. (upbeat retro video game music) (quirky tone plays) So here's the starting point that we've given you. We've defined a triangle here that you can build the Sierpinski triangle from. What we need to implement is the iterative fractal-building process. So, what I need to do is, on the first iteration when the depth is 1, I need to return just the triangle, and on the other iterations, I need to build from the…

Contents