Hah - wrote it down already in our code base - about 3 times :(
%% @doc Convert an string to a decimal integer %% @spec b26_to_i(string()) -> integer() b26_to_i(List) when is_list(List) -> b26_to_i(string:to_lower(lists:reverse(List)),0,0). %% private functions b26_to_i([], _Power, Value) -> Value; b26_to_i([H|T],Power,Value)-> NewValue = case (H > 96) andalso (H < 123) of true -> round((H - 96) * math:pow(26, Power)); _ -> exit([H | T] ++ " is not a valid base 26 number") end, b26_to_i(T, Power + 1, NewValue + Value).
The riddle is that it is not a basic representation of a number (here we call ourselves here as a function), because it does not have 0.
Sequence: A, B, C ... Z, AA, AB, AC
not: A, B, C ... Z, BA, BB, BC
(language - Erlang, mais oui).
Gordon Guthrie Apr 18 '09 at 16:22 2009-04-18 16:22
source share