# Last edited on 2002-01-16 01:23:24 by stolfi

# To be included in gawk programs together with roman-encoding.gawk
# Defines renc_init() for scrambled subtractive Roman numerals

function renc_init()
{
  # A variant of the Roman system with subtractive convention
  # (iv = 4, ix = 9) with digits in unorthodox positions.
  # Extended with p = 5000, b = 10000, f = 50000, e = 100000

  # Digit 0 length distribution = (1,2,4,2,1)
  renc_base0 = 10; renc_mul0 = 1;
  renc_digs0[0] = ":";
  renc_digs0[1] = ":i";
  renc_digs0[2] = ":ii";
  renc_digs0[3] = ":iii";
  renc_digs0[4] = "iv:";
  renc_digs0[5] = "v:";
  renc_digs0[6] = "v:i";
  renc_digs0[7] = "v:ii";
  renc_digs0[8] = "v:iii";
  renc_digs0[9] = "ix:";

  # Digit 1 length distribution = (1,2,4,2,1)
  renc_base1 = 10; renc_mul1 = renc_mul0*renc_base0;
  renc_digs1[0] = ":";
  renc_digs1[1] = ":x";
  renc_digs1[2] = ":xx";
  renc_digs1[3] = ":xxx";
  renc_digs1[4] = "xl:";
  renc_digs1[5] = "l:";
  renc_digs1[6] = "l:x";
  renc_digs1[7] = "l:xx";
  renc_digs1[8] = "l:xxx";
  renc_digs1[9] = "xc:";

  # Digit 2 length distribution = (1,2,2,2,2,1)
  renc_base2 = 10; renc_mul2 = renc_mul1*renc_base1;
  renc_digs2[0] = ":";
  renc_digs2[1] = ":c";
  renc_digs2[2] = ":cc";
  renc_digs2[3] = ":ccc";
  renc_digs2[4] = "cd:";
  renc_digs2[5] = "d:";
  renc_digs2[6] = "d:c";
  renc_digs2[7] = "d:cc";
  renc_digs2[8] = "d:ccc";
  renc_digs2[9] = "cm:";

  # Digit 3 length distribution = (1,2,2,2,2,1)
  renc_base3 = 10; renc_mul3 = renc_mul2*renc_base2;
  renc_digs3[0] = ":";
  renc_digs3[1] = ":m";
  renc_digs3[2] = ":mm";
  renc_digs3[3] = ":mmm";
  renc_digs3[4] = "mp:";
  renc_digs3[5] = "p:";
  renc_digs3[6] = "p:m";
  renc_digs3[7] = "p:mm";
  renc_digs3[8] = "p:mmm";
  renc_digs3[9] = "mb:";

  # Digit 4 length distribution = (0,3,3)
  renc_base4 = 10; renc_mul4 = renc_mul3*renc_base3;
  renc_digs4[0] = ":";
  renc_digs4[1] = ":b";
  renc_digs4[2] = ":bb";
  renc_digs4[3] = ":bbb";
  renc_digs4[4] = "bf:";
  renc_digs4[5] = "f:";
  renc_digs4[6] = "f:b";
  renc_digs4[7] = "f:bb";
  renc_digs4[8] = "f:bbb";
  renc_digs4[9] = "be:";

  renc_max_num = renc_mul4 * renc_base4 - 1;
  renc_max_code = renc_encode(renc_max_num);
}