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.
# For me, it was important to realize that the tree is a representation of powers of 2 (in several ways).## For example:## -> The height of each level (iteration) is a power of two (32, 16, 8, 4, 2).# -> The number of 'y's in every level is a power of two (1, 2, 4, 8, 16).# -> The number of '1's in every line is a power of two.# ...# ...# Then, we just have to figure out how to build a function that draws a level depending on **"2 to the power of n"** (iteration over N).# If we approach it this way, the implementation of the function doesn't exceed 20 lines, and the total script with the loop will not exceed the 30 lines...# In my case, I just created a basic function named print_pattern_i and called it in a for loop 5 times.# Something like this:print_pattern_i(){iteration=$1# ... (content of the function)}foriin{6..1}doprint_pattern_i$idone
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 - Recursive Trees - Bash!
You are viewing a single comment's thread. Return to all comments →