This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sha1-str [s] | |
(->> (-> "sha1" | |
java.security.MessageDigest/getInstance | |
(.digest (.getBytes s))) | |
(map #(.substring | |
(Integer/toString | |
(+ (bit-and % 0xff) 0x100) 16) 1)) | |
(apply str))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.test]) | |
(defn powerset | |
([ls] (lazy-seq (cons () (powerset '(()) ls)))) | |
([acc ls] | |
(if (empty? ls) | |
() | |
(let [fs (first ls) | |
added (map #(conj % fs) acc)] | |
(lazy-cat added | |
(powerset (concat acc added) (rest ls))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.contrib.str-utils) | |
(def digits {"零" 0 "一" 1 "二" 2 "三" 3 "四" 4 "五" 5 "六" 6 "七" 7 "八" 8 "九" 9}) | |
(defn- str-first [s] | |
(str (.charAt s 0))) | |
(defn- trans-ichi [s] | |
(let [n (re-find #"[一二三四五六七八九]$" s)] | |
(if (nil? n) 0 (digits n)))) |