For the task, we need to draw a Christmas tree in R. I searched the Internet and found useful tips, but at the end of the day I donβt know how to proceed further and I hope that someone can help me.
This is my code so far.
#ctree: prints a Christmas tree on screen with size N ctree <- function(N){ for (i in 1:N){ width = sample("*",i,replace=T) cat(width,sep="-","\n") } cat(width[1],"\n") }
This leaves me on the middle and right side of my tree (with N = 4), which is great, but not enough.
*- *-*- *-*-*- *-*-*-*- *
I planned to reverse what I had (basically the alignment to the right of the product of the function) to create the left side, then remove the right extreme column of the left side and stick it together with the right side of the tree, creating a Christmas tree.
I really hope someone can help me with this! Waiting for your advice.
Thanks in advance.
source share