! A simple program that generates Excel spreadsheet column id corresponding to given column number. ! For example: ! 14 - N ! 26 - Z ! 27 - AA ! 29 - AC USING: kernel math math.ranges sequences strings ; IN: excel-columns ! Use the following after 'alphabet' definition to make it a compile time constant. ! << \ alphabet alphabet define-constant >> : alphabet ( -- seq ) CHAR: A CHAR: Z [a,b] ; : nth-char ( n -- char ) 25 + 26 mod alphabet nth 1string ; : break-26 ( m -- n o ) 26 [ /i ] [ mod ] 2bi ; : column-id ( i -- str ) dup 26 <= [ nth-char ] [ break-26 [ column-id ] bi@ append ] if ; : test-run ( -- ) 1000 [1,b] [ dup column-id 2array . ] each MAIN: test-run