Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; returns the rounded mid of a value
  3. (defn calculateMid [paramx]
  4.   (- (int (Math/ceil (/ paramx 2))) 1)
  5.   )
  6.  
  7. (defn printTree [paramx]
  8.   ; create the first vector with many dots (........)
  9.   (def dots (vec (replicate paramx ".")))
  10.  
  11.   ; creates new vector - adds a X in the mid of the list
  12.   (def midValue (calculateMid paramx))
  13.   (def lines (assoc dots midValue "X"))
  14.  
  15.   ; creates the actual tree shape
  16.   (dotimes [n midValue]
  17.     (-> lines
  18.       (assoc (- midValue n) "X")
  19.       (assoc (+ midValue n) "X")
  20.       (println)
  21.     )
  22.   )
  23. )
  24.  
  25. ; prints the last row with xxxxxxxxx
  26. (defn printLastRow [paramx]
  27. (println (vec (replicate paramx "X")))
  28.   )
  29.  
  30. ; prints the trunk of the tree
  31. (defn printTrunk [paramx]
  32.   (dotimes [n paramx]
  33.   (-> lines
  34.     (assoc (- midValue 1) "X")
  35.     (assoc (+ midValue 1) "X")
  36.     (println)
  37.   )
  38.   )
  39. )
  40.  
  41. (println "Bitte die Groesse des Baums angeben (Zahlen von 5-100)")
  42. (def amount (read-string (read-line)))
  43. (printTree amount)
  44. (printLastRow amount)
  45. (printTrunk 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement