forked from benjamin-korobkin/Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathascii_bin_tree.py
More file actions
24 lines (19 loc) · 897 Bytes
/
ascii_bin_tree.py
File metadata and controls
24 lines (19 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#try again, no lists
# amount of dashes at top left is ((2^N) // 2) - 1
def ascii_tree(n):
counter = 1; # increment this to repeat lines. Without it,
#we only have the left-most parts of the tree.
tree=''; # empty tree
m = n # dummy var to decrement n while also preserving the og value thru n
while m >= 0:
dashes = (2**m//2)-1 # dashes at outer parts of each branch
height = 2**m//2 # starts at og height, gets cut in half every iteration
mid_dash = 0 # how many dashes between slashes? doubles in the for-loop iterations, but must be reset
for x in range(height//2):
tree +=(('-'*dashes)+'/'+('-'*mid_dash)+'\\'+('-'*dashes)) * counter + '\n'
dashes -= 1
mid_dash += 2
m -= 1;counter*=2
tree += '/\\' * (2**(n-1))
return tree
print(ascii_tree(5))