anchor.diff:    N + 22.
   
   
  -% decode
  -decode([], Head, Tail) ->
  -  decode_whileloop(Tail, Head, #decode{});
  +decode(Input) ->
  +  {Output, Input2} = case string:rstr(Input, [?DELIMITER]) of
  +             0 -> {"", Input};
  +             Pos ->
  +               {lists:sublist(Input, Pos - 1), lists:sublist(Input, Pos + 1, length(Input) )}
  +           end,
  +  decode(Input2, Output, ?INITIAL_N, ?INITIAL_BIAS, 0).
   
  -% If we have a repeated ?DELIMITER, pass one through into Tail (Output)
  -decode([?DELIMITER, ?DELIMITER|Input], [], Tail) ->
  -  decode([?DELIMITER|Input], Tail, [?DELIMITER]);
   
  -decode([?DELIMITER|Input], [], Tail) ->
  -  decode(Input, Tail, []);
  -decode([?DELIMITER|Input], Head, Tail) ->
  -  decode(Input, Head ++ [?DELIMITER|Tail], []);
  -decode([C|Input], Head, Tail) ->
  -  decode(Input, Head, Tail ++ [C]).
  +decode([], Output, _, _, _) -> Output;
  +decode(Input, Output, N, Bias, I) ->
  +  decode(Input, Output,  N, Bias, I, I, 1, ?BASE).
   
  -decode_whileloop([], Output, _) -> Output;
  -decode_whileloop(Input, Output, State=#decode{n = N, i = I}) ->
  -  {Input2, State2=#decode{i = I2}} = decode_forloop(Input, State#decode{k = ?BASE, w = 1}),
  -  X = 1 + length(Output),
  -  N2 = N + I2 div X,
  -  I3 = I2 rem X,
  -  {Head, Tail} = lists:split(I3, Output),
  -  decode_whileloop(Input2, Head ++ [N2] ++ Tail, State2#decode{n = N2, i = I3 + 1, bias = adapt(I2 - I, X, I == 0)}).
  +decode([C|Rest], Output, N, Bias, I0, OldI, Weight, K) ->
  +  Digit = digit(C),
  +  I1 = case Digit > ((?MAX - I0 ) div Weight) of
  +         false -> I0 + (Digit * Weight);
  +         true -> exit(overflow)
  +       end,
   
  -decode_forloop([C|Input], State=#decode{bias = Bias, i = I, k = K, w = W}) ->
  -  D = decode_digit(C),
  -  I2 = I + D * W,
  -  case threshold(K, Bias) of
  -    T when D < T -> {Input, State#decode{i = I2}};
  -    T -> decode_forloop(Input, State#decode{i = I2, k = K + ?BASE, w = W * (?BASE - T)})
  +  T = if
  +        K =< Bias -> ?TMIN;
  +        K >= (Bias + ?TMAX) -> ?TMAX;
  +        true -> K - Bias
  +      end,
  +  case Digit < T of
  +    true ->
  +      Len = length(Output),
  +      Bias2 = adapt(I1 - OldI, Len + 1, (OldI == 0)),
  +      {N2, I2}= case (I1 div (Len +1)) > (?MAX - N) of
  +                  false ->
  +                    {N + I1 div (Len + 1), I1 rem (Len + 1)};
  +                  true ->
  +                    exit(overflow)
  +                end,
  +
  +      {Head, Tail} = lists:split(I2, Output),
  +      Output2 = Head ++ [N2] ++ Tail,
  +      decode(Rest, Output2, N2, Bias2, I2+1);
  +    false ->
  +      case Weight > (?MAX  div (?BASE - T)) of
  +        false ->
  +          decode(Rest, Output, N, Bias, I1, OldI, Weight * (?BASE - T), K + ?BASE);
  +        true ->
  +          exit(overflow)
  +      end
     end.
   
  -threshold(K, Bias) when K =< Bias + ?TMIN -> ?TMIN;
  -threshold(K, Bias) when K >= Bias + ?TMAX -> ?TMAX;
  -threshold(K, Bias) -> K - Bias.
   
  -decode_digit(N) when N >= $0 andalso N =< $9 -> N - 22;
  -decode_digit(N) -> N - 22 - 75.
  +digit(C) when C >= $0, C =< $9 -> C - $0 + 26;
  +digit(C) when C >= $A, C =< $Z -> C - $A;
  +digit(C) when C >= $a, C =< $z -> C - $a.
   
  -adapt(Delta, Numpoints, Firsttime) ->
  -  Delta2 = case Firsttime of true -> Delta div ?DAMP; false -> Delta bsr 1 end,
  -  adapt_whileloop(Delta2 + (Delta2 div Numpoints), 0).
   
  -adapt_whileloop(Delta, K) ->
  -  case Delta > (((?BASE - ?TMIN) * ?TMAX) bsr 1) of
  +adapt(Delta, NumPoints, FirstTime) ->
  +  Delta2 = case FirstTime of
  +             true ->
  +               Delta div ?DAMP;
  +             false ->
  +               Delta div 2
  +           end,
  +  adapt(Delta2 + (Delta2 div NumPoints), 0).
  +
  +adapt(Delta, K) ->
  +  case Delta > (((?BASE - ?TMIN) * ?TMAX) div 2) of
       true ->
  -      adapt_whileloop(Delta div (?BASE - ?TMIN), K + ?BASE);
  +      adapt(Delta div (?BASE - ?TMIN), K + ?BASE);
       false ->
         K + (((?BASE - ?TMIN + 1) * Delta) div (Delta + ?SKEW))
  -  end.
  +  end.
positive.code: -define(INITIAL_N, 128).
  -define(DELIMITER, $-).
  
  %%============================================================================
  %% Encoding algorithm state
  %%============================================================================
  
negative.code: 
  -export([encode/1,
           decode/1]).
  
  
  %%============================================================================
  %% Constants
  