Skip to main content
a new make-tree function from @kealist
Source Link

Rebol

With a dialect to display the symbols. To change the tree size, just change the parameter of make-tree.

make-tree: [func 3[int space/local 1tr] asterisk[
 3 spacetr: lfcopy []
    length: (int * 2) space+ 3 asterisk 2 space lf
       1 space 2 asterisk 1 starrepeat 1i asteriskint lf[
       1 star 1 asterisk 1repeat starj 3 asterisk lf[
       2 space 3 asterisk 2 space lf
     ast: to-integer 1((i space* 2) asterisk- 1 star+ 1(j asterisk* 12) space- lf2)
       7 asterisk lf
       3 spacesp: 1to-integer bar(length 3- spaceast) lf/ ]2
result: copy []
rule: [ some [ set i integer! 'space (  append/dup resulttr space i )sp |
           set i integer! 'asterisk ( append/dup resulttr "*" i )ast |
           set i integer! 'star ( append/dup result "☆" i )tr |lf
           set i]
 integer! 'bar]
 ( append/dup result "||" i) |
 tr space (length - 1) / 2
  append tr 'lf"|"
 ( append resulttr lf ) | skip
   ]tr
]
parse tree rule
print resultmake-tree 3

enter image description herea tree with 3 layers a tree with 5 layers

Rebol

With a dialect to display the symbols.

tree: [ 3 space 1 asterisk 3 space lf 
       2 space 3 asterisk 2 space lf
       1 space 2 asterisk 1 star 1 asterisk lf
       1 star 1 asterisk 1 star 3 asterisk lf
       2 space 3 asterisk 2 space lf
       1 space 2 asterisk 1 star 1 asterisk 1 space lf
       7 asterisk lf
       3 space 1 bar 3 space lf ]
result: copy []
rule: [ some [ set i integer! 'space ( append/dup result space i ) |
           set i integer! 'asterisk ( append/dup result "*" i ) |
           set i integer! 'star ( append/dup result "☆" i ) |
           set i integer! 'bar ( append/dup result "||" i) |
           'lf ( append result lf ) | skip
   ]
]
parse tree rule
print result

enter image description here

Rebol

With a dialect to display the symbols. To change the tree size, just change the parameter of make-tree.

make-tree: func [int /local tr] [
  tr: copy []
  length: (int * 2) + 3
  repeat i int [
      repeat j 3 [
            ast: to-integer ((i * 2) - 1 + (j * 2) - 2)
            sp: to-integer (length - ast) / 2
            append/dup tr space sp 
            append/dup tr "*" ast 
            append tr lf
      ]
  ]
  append/dup tr space (length - 1) / 2
  append tr "|"
  append tr lf
  tr
]

print make-tree 3

a tree with 3 layers a tree with 5 layers

Source Link

Rebol

With a dialect to display the symbols.

tree: [ 3 space 1 asterisk 3 space lf 
       2 space 3 asterisk 2 space lf
       1 space 2 asterisk 1 star 1 asterisk lf
       1 star 1 asterisk 1 star 3 asterisk lf
       2 space 3 asterisk 2 space lf
       1 space 2 asterisk 1 star 1 asterisk 1 space lf
       7 asterisk lf
       3 space 1 bar 3 space lf ]
result: copy []
rule: [ some [ set i integer! 'space ( append/dup result space i ) |
           set i integer! 'asterisk ( append/dup result "*" i ) |
           set i integer! 'star ( append/dup result "☆" i ) |
           set i integer! 'bar ( append/dup result "||" i) |
           'lf ( append result lf ) | skip
   ]
]
parse tree rule
print result

enter image description here