Pure Programmer
Blue Matrix


Cluster Map

Project: Spreadsheet Columns

Spreadsheets often have two ways to identify a column. The first is numerically with the first column being 1, second column 2, etc. The second way is with alphabetic labels 'A' - 'Z'. To support more than 26 column labels, the next column after 'Z' is designated 'AA', then 'AB', 'AC', etc. When we reach 'ZZ' we switch to three letters 'AAA', 'AAB', 'AAC, etc.

Write a function that accepts an integer column number and returns the alphabetic label as a string. You may need to write some helper functions as well.  (HINT: a function that can convert a number to base 26 can be very helpful. See BaseConversion). Write a program to exercise the function by printing out all column labels from 'A' to 'ZZZ'. How many labels need to be printed? What label is used for the maximum column number of 32,767?

Output
$ rustc SpreadsheetColumns.rs error[E0277]: the type `[&'static str]` cannot be indexed by `isize` --> SpreadsheetColumns.rs:16:48 | 16 | return spreadsheetLabel(remaining) + symbols[digit]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[&'static str]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<&'static str>` to implement `Index<isize>` error[E0277]: the type `[&'static str]` cannot be indexed by `isize` --> SpreadsheetColumns.rs:18:18 | 18 | return symbols[digit]; | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[&'static str]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<&'static str>` to implement `Index<isize>` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`.

Solution