Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0.
從 1 開始加總到給的整數
summation(2) -> 3
1 + 2
summation(8) -> 36
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
數學解
(ns kata.summation)
(defn summation [n]
(/ (* (+ 1 n) n) 2))
(ns kata.summation)
(defn summation [n]
(reduce + (range (+ 1 n)))