iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 16
0
自我挑戰組

各種筆記系列 第 16

[Kata] Clojure - Day 16

Century From Year

The first century spans from the year 1 up to and including the year 100, The second - from the year 101 up to and including the year 200, etc.

找出該年度屬於哪個世紀

Solution

(ns century.core)
(defn century [year]
  (int (Math/ceil (/ year 100))))

Count the Monkeys!

;; Example

monkeyCount(10) // --> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
monkeyCount(1) // --> [1]

Solutions

(ns kata.monkey.count)
(defn monkey-count [n]
  (range 1 (+ 1 n))
)
;; (inc x), increment function
;; Returns a number one greater than x.

(ns kata.monkey.count)
(defn monkey-count [n]
  (range 1 (inc n))
)
(inc 1)   ;; 2
(inc -1)  ;; 0
(inc 1.0) ;; 2.0

(map inc [1 2 3 4 5])            ;; (2 3 4 5 6)
(into [] (map inc [1 2 3 4 5]))  ;;[2 3 4 5 6]

上一篇
[Kata] Clojure - Day 15
下一篇
[Kata] Clojure - Day 17
系列文
各種筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言