We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This was a lot of fun. The approach that worked for me in case it's helpful to anyone:
2D array of bits as the buffer. Recursive function taking a triangle description (coordinates of top point and height). The base case fills in the triangle described. Otherwise, recurse to the 3 corners - each has half the height, the top one is the same point and the others are translated down and left/right by half the height. Initial call then is the depth and the large triangle with top at the first row, middle column, and full height.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Functions and Fractals: Sierpinski triangles
You are viewing a single comment's thread. Return to all comments →
This was a lot of fun. The approach that worked for me in case it's helpful to anyone:
2D array of bits as the buffer. Recursive function taking a triangle description (coordinates of top point and height). The base case fills in the triangle described. Otherwise, recurse to the 3 corners - each has half the height, the top one is the same point and the others are translated down and left/right by half the height. Initial call then is the depth and the large triangle with top at the first row, middle column, and full height.