A triangle number is a number where n objects form an equilateral triangle (it's a bit hard to explain). For example, 6 is a triangle number because you can arrange 6 objects into an equilateral triangle:
寫一個可以確認數字是否為 triangle number
的函式
;; 6 is a triangle number
1
2 3
4 5 6
;; 8 is not a triangle number
1
2 3
4 5 6
7 8
(ns nb-triangle.core)
(defn is-triangle-number [n]
(loop [iter 1
acc 0]
(if (>= acc n)
(= acc n)
(recur (inc iter) (+ acc iter))))
)