Skip to content

Instantly share code, notes, and snippets.

Created January 11, 2011 09:16
Show Gist options
  • Save anonymous/774229 to your computer and use it in GitHub Desktop.
Save anonymous/774229 to your computer and use it in GitHub Desktop.
(digits-to-meisuu "123456789")
(def digit {\0 "" \1 "一" \2 "二" \3 "三" \4 "四" \5 "五" \6 "六" \7 "七" \8 "八" \9 "九"})
(defn digit-keta [d m]
(if (= (digit d) "") ""
(if (and (not= m "") (= (digit d) "一")) m
(str (digit d) m))))
(defn digits-to-sen [digits]
(loop [d digits
m ["" "十" "百" "千"]
out ""]
(if (empty? d) out
(recur (rest d) (rest m) (str (digit-keta (first d) (first m)) out)))))
(def meisuu ["" "万" "億" "兆" "京" "垓" "叙" "穣" "溝" "澗" "正" "載" "極" "恒河沙" "阿僧祇" "那由多" "不可思議" "無量大数"])
(defn digits-to-meisuu [digits]
(if (= digits "0") "零"
(loop [d (partition-all 4 (reverse digits))
m meisuu
out ""]
(if (empty? d) out
(recur (rest d) (rest m) (str (digits-to-sen (first d)) (first m) out))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment