Skip to content

Instantly share code, notes, and snippets.

@jamiltron
Created October 13, 2011 19:07
Show Gist options
  • Save jamiltron/1285184 to your computer and use it in GitHub Desktop.
Save jamiltron/1285184 to your computer and use it in GitHub Desktop.
num to base 62
(def base62-alphabet
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
(defn num->base62 [x]
(letfn [(base-conv [curr q]
(if (>= 0 q) curr
(recur (conj curr (nth base62-alphabet (rem q 62))) (quot q 62))))]
(base-conv '() x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment