Created
October 25, 2011 14:39
-
-
Save mnzk/1312959 to your computer and use it in GitHub Desktop.
Excel A1 Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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