Skip to content

Instantly share code, notes, and snippets.

(defn freq-of-cha
[str]
(->> str
frequencies
(sort-by val >)
first
second
(vector str)))
(add-hook 'clojure-mode-hook
'(lambda ()
(font-lock-add-keywords
nil
'(("\\(\\<[a-zA-Z0-9\-\._\?]+\\>" 1 '(:foreground "red") t)))))
(defn char-diff
"the diff between char1 and (char21,char22)"
[char1 char21 char22]
(cond
(= char1 char21) 1
(= char1 char22) 2
:else 0))
(defn word-chain?
;;http://www.4clojure.com/problem/21
#(loop [index 0 col %1]
(if (< index %2)
(recur (inc index) (next col))
(first col)))
@weejulius
weejulius / gist:5501587
Created May 2, 2013 11:21
;;assert(succ("") == "") ;;assert(succ("R2D3") == "R2D4") ;;assert(succ("R2D9") == "R2E0") ;;assert(succ("A99") == "B00") ;;assert(succ("Z99") == "AA00") ;;assert(succ("Zz99") == "AAa00") ;;assert(succ("9Z") == "10A")
(defn increment
[str-chars]
(if ((complement empty?) str-chars)
(let [last-char (last str-chars)
ahead-chars (drop-last str-chars)]
(cond
(= last-char \9) (if (empty? ahead-chars) "10" (str (increment ahead-chars) \0))
(= last-char \z) (if (empty? ahead-chars) "aa" (str (increment ahead-chars) \a))
(= last-char \Z) (if (empty? ahead-chars) "AA" (str (increment ahead-chars) \A))
:else (apply str (conj (vec ahead-chars) (char (inc (int last-char))))))) ""))