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.
If you know how to format the code better on this broken editor, please let me know.
If there is a way to update my submitted answer, please let me know
*
#!/bin/bashread tree_depth
xpos=(50)# Roots where we start the Ysfor((y=1; y<=63; y++));dofor((x=1; x<=100; x++));dochar=_
if(( tree_depth > printed ));then# if we need more depthlength=$((2**(4-printed)))b=y-offset-length
# b is the y coordinate from the point of view of the center of the Y we are drawingif(( b <= length ));then(( b < 0))&&b=0# Force vertical (to draw a Y instead of an X)for p in "${xpos[@]}";doif(( p-b == x || p+b == x ));thenchar=1# If b == length, we are finishing drawing this rank's Ys# So we save the x position for future Y roots((b== length ))&&new_xpos+=("$x")fidonefifiprintf %s "$char"doneif((b== length ));then# We finished drawing the Ys for this level# We set the new roots and the offset for coordinate computationxpos=("${new_xpos[@]}")new_xpos=()printed=$((printed+1))offset=$yfiechodone| tac
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 →
ITERATIVE version (ultra-compact)