Advertisement
k10dayogi

MX Tree

Sep 7th, 2022 (edited)
1,929
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.61 KB | None | 1 0
  1. xt<-function(n, nmin=4){
  2.   #error handling
  3.   if(class(n)!="numeric"){stop("Must be numeric.")}
  4.   if(floor(n)!=n){stop("Must be whole number.")}
  5.   if(n<nmin){stop("n must be at least nmin.")}
  6.   #set up vector for rows
  7.   v<-vector("character", (2*n)-1)
  8.   #determine length of each row of stars.
  9.   for(i in 1:(n-1)){
  10.     mid<-(length(v)+1)/2
  11.     lbound<-mid-(i-1)
  12.     rbound<-mid+(i-1)
  13.     #fill in each row of stars.
  14.     for(j in lbound:rbound){    
  15.       v[j]<-"*"
  16.     }
  17.     print(noquote(v))
  18.   }
  19.   #put in the last row for the stem.
  20.   v<-vector("character", (2*n)-1)
  21.   v[mid]<-"*";print(noquote(v))
  22. }
  23. xt(15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement