Skip to content

Instantly share code, notes, and snippets.

@mnzk
Created October 25, 2011 14:39
Show Gist options
  • Save mnzk/1312959 to your computer and use it in GitHub Desktop.
Save mnzk/1312959 to your computer and use it in GitHub Desktop.
Excel A1 Converter
(def alpha "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(def alen (count alpha))
(defn freq-alpha [n]
(mapcat (partial repeat n) alpha))
(defn fun [[xss m]]
[(map cons (freq-alpha m) (cycle xss)), (* m alen)])
(defn A1-seq []
(->> (iterate fun [(map list alpha), alen])
(mapcat first)))
(defn N->A1 [n]
(apply str (nth (A1-seq) (dec n))))
;;------------------------------------------------
;; Examples
;;------------------------------------------------
(N->A1 1) ;=> "A"
(N->A1 10) ;=> "J"
(N->A1 2000) ;=> "BXX"
(N->A1 30000) ;=> "ARIV"
(N->A1 500000) ;=> "ABKPT"
(N->A1 1000000) ;=> "BDWGN"
(->> (A1-seq)
(drop 2000) (take 10)
(map (partial apply str)))
;;=> ("BXY" "BXZ" "BYA" "BYB" "BYC" "BYD" "BYE" "BYF" "BYG" "BYH")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment