Message 1 of 27
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The objective is to create a function that returns a string from an integer based on 1=A, 26=Z, 27=AA, 52=AZ, 53=AAA, etc.
My bloated attempt is below, but I know that a number of you wizards can do a lot better, even keeping the function producing correct results on up to 1000 and more. I am personally challenged with recursive functions which I think is the way to go.
(defun alpha (n / a) (cond ((<= n 26) (chr (+ 64 n))) ((< 26 n 52) (strcat "A" (chr (+ 64 (if (= (setq a (rem n 26)) 0) 1 a))))) ((= n 52) "AZ") ((< 52 n 78) (strcat "AA" (chr (+ 64 (if (= (setq a (rem n 26)) 0) 1 a))))) ("ZZZZZ") ;; Just a bail-out condition ) )
The winner will receive a personally autographed digital copy of my AARP card, if I can find it.
John F. Uhden
Solved! Go to Solution.