Skip to content

Instantly share code, notes, and snippets.

@jamiltron
Created October 13, 2011 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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