# generate a table of error correction codewords

RS_BLOCK_TABLE = [
  [  26,  1,  26,  19],
  [  44,  1,  44,  34],
  [  70,  1,  70,  55],
  [ 100,  1, 100,  80],
  [ 134,  1, 134, 108],
  [ 172,  2,  86,  68],
  [ 196,  2,  98,  78],
  [ 242,  2, 121,  97],
  [ 292,  2, 146, 116],
  [ 346,  2,  86,  68,  2,  87,  69],
  [ 404,  4, 101,  81],
  [ 466,  2, 116,  92,  2, 117,  93],
  [ 532,  4, 133, 107],
  [ 581,  3, 145, 115,  1, 146, 116],
  [ 655,  5, 109,  87,  1, 110,  88],
  [ 733,  5, 122,  98,  1, 123,  99],
  [ 815,  1, 135, 107,  5, 136, 108],
  [ 901,  5, 150, 120,  1, 151, 121],
  [ 991,  3, 141, 113,  4, 142, 114],
  [1085,  3, 135, 107,  5, 136, 108],
  [1156,  4, 144, 116,  4, 145, 117],
  [1258,  2, 139, 111,  7, 140, 112],
  [1364,  4, 151, 121,  5, 152, 122],
  [1474,  6, 147, 117,  4, 148, 118],
  [1588,  8, 132, 106,  4, 133, 107],
  [1706, 10, 142, 114,  2, 143, 115],
  [1828,  8, 152, 122,  4, 153, 123],
  [1921,  3, 147, 117, 10, 148, 118],
  [2051,  7, 146, 116,  7, 147, 117],
  [2185,  5, 145, 115, 10, 146, 116],
  [2323, 13, 145, 115,  3, 146, 116],
  [2465, 17, 145, 115],
  [2611, 17, 145, 115,  1, 146, 116],
  [2761, 13, 145, 115,  6, 146, 116],
  [2876, 12, 151, 121,  7, 152, 122],
  [3034,  6, 151, 121, 14, 152, 122],
  [3196, 17, 152, 122,  4, 153, 123],
  [3362,  4, 152, 122, 18, 153, 123],
  [3532, 20, 147, 117,  4, 148, 118],
  [3706, 19, 148, 118,  6, 149, 119],
]

s = ""
RS_BLOCK_TABLE.each.with_index(1) do |a, v|
  size_1 = 4 * v + 16

  total_codes, n1, c1, k1, n2, c2, k2 = *a
  s << (total_codes * 54 / 265 - (n2 ? n1 + n2 : n1) * (c1 - k1) + 43)
end

p s
