Update 12/25/12
After a bit of struggle, I came up with this method. no Do
is used.
(*data*)
Clear["Global`*"]
lst = {{19, 19, 19, 19, 23, 19, 23}, {37, 53, 53, 53, 53, 37, 53},
{73, 59, 59, 59, 73, 73, 73}, {2, 83, 83, 83, 79, 2,79},
{79, 41, 41, 41, 19, 79, 19}};
p = {a, b, c, d, e, f, g};(*that is what we need,7 letters max*)(*engine*)
(*engine*)
u = Map[Flatten, Map[DeleteDuplicates, Gather /@ lst, {2}]]
z = Map[MapThread[Rule, #] &, Map[{#, Take[p, Length[#]]} &, u]]
MapThread[(#1 /. #2) &, {lst, z}]
(* {{a, a, a, a, b, a, b},
{a, b, b, b, b, a, b},
{a, b, b, b, a, a, a},
{a, b, b, b, c, a, c},
{a, b, b, b, c, a, c}} *)
old answers below
Updated based on MrWizard suggestions. I'll keep my original complicated answer below since that is what I wrote first. But credit for this updated answer goes to MrWizard, so please do not upvote me based on this new answer or I'll get upset.
Updated and improved answer
(*data*)
lst = {{19, 19, 19, 19, 23, 19, 23}, {37, 53, 53, 53, 53, 37,
53}, {73, 59, 59, 59, 73, 73, 73}, {2, 83, 83, 83, 79, 2,
79}, {79, 41, 41, 41, 19, 79, 19}};
p = {a, b, c, d, e, f, g};(*that is what we need,7 letters*)
(*engine*)
r = Gather /@ lst (*note: Gather is listable *)
Tally@MapThread[# /.MapThread[Rule, {First /@ #2, Take[p, Length@#2]}] &, {lst, r}]
old original answer
is a Do ok? I think I can get rid of it if I try harder.
(*data*)
lst = {{19, 19, 19, 19, 23, 19, 23},
{37, 53, 53, 53, 53, 37, 53},
{73, 59, 59, 59, 73, 73, 73},
{2, 83, 83, 83, 79, 2, 79},
{79, 41, 41, 41, 19, 79, 19}};
p = {a, b, c, d, e, f, g}; (*that is what we need, 7 letters*)
(* engine *)
r = Gather[#, #1 == #2 &] & /@ lst;
z = Last@Reap@Do[
rule =Rule[#1[[1]], #2] & @@@Transpose[{ r[[i]] , p[[1 ;; Length[r[[i]]]]]}];
Sow[lst[[i]] /. rule],
{i, 1, Length[r]}]
Tally[#] & /@ z
gives
(*{{{a, a, a, a, b, a, b}, {a, b, b, b, b, a, b}, {a, b, b, b, a, a,a},
{a, b, b, b, c, a, c}, {a, b, b, b, c, a, c}}}
{{{{a, a, a, a, b, a, b}, 1}, {{a, b, b, b, b, a, b},1},
{{a, b, b, b, a, a, a}, 1}, {{a, b, b, b, c, a, c}, 2}}}
*)