19 lines
404 B
Rust
19 lines
404 B
Rust
|
pub fn title_to_number(title: String) -> i32 {
|
||
|
let mut result = 0;
|
||
|
|
||
|
for (index, character) in title.chars().rev().enumerate() {
|
||
|
// Convert the character to a number and subtract 9 so A will equal 1.
|
||
|
let number = character.to_digit(36).unwrap() - 9;
|
||
|
|
||
|
let n = if index == 0 {
|
||
|
number
|
||
|
} else {
|
||
|
26_u32.pow(index as u32) * number
|
||
|
};
|
||
|
|
||
|
result += n;
|
||
|
}
|
||
|
|
||
|
result as i32
|
||
|
}
|