Skip to content

Instantly share code, notes, and snippets.

@hozumi
hozumi / meisuu.clj
Created December 13, 2010 06:23 — forked from kencoba/meisuu.clj
(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))))
(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)))))))
@hozumi
hozumi / sha1-hash.clj
Created December 13, 2011 16:46 — forked from prasincs/sha1-hash.clj
clojure sha1 hash
(defn sha1-str [s]
(->> (-> "sha1"
java.security.MessageDigest/getInstance
(.digest (.getBytes s)))
(map #(.substring
(Integer/toString
(+ (bit-and % 0xff) 0x100) 16) 1))
(apply str)))