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.
declare-Amatrixgrid(){for((i=0;i<$1;i++))dofor((j=0;j<$2;j++));domatrix[$i,$j]="_"donedone}print(){for((i=0;i<$1;i++))dofor((j=0;j<$2;j++));doprintf"%s"${matrix[$i,$j]}doneprintf"\n"done}fractal(){localr=$1localc=$2localitr=$3localdepth=$(($4-1))if((depth==0));thenreturn0;fi#make the trunkfor((i=0;i<$itr;i++));domatrix[$(($r-$i)),$c]="1"done#left diagonalfor((i=0;i<$itr;i++));domatrix[$(($r-$itr-$i)),$(($c-$i-1))]="1";done#rightdiagonalfor((i=0;i<$itr;i++));domatrix[$(($r-$itr-$i)),$(($c+$i+1))]="1";done#makeYinleftdiagonalfractal$(($r-2*$itr))$(($c-$itr))$(($itr/2))$depth#makeYinrightdiagonalfractal$(($r-2*$itr))$(($c+$itr))$(($itr/2))$depth}main(){ROWS=63COLS=100grid$ROWS$COLSreaddepthfractal624916$(($depth+1))print$ROWS$COLS}main
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 →