Method of assigning a number to the number of attempts that have appeared from it, with the first attempt appearing as number 1

I want to assign the first trial that appears as number 1 and the number of trials that appear from there as elements of the list, plus a number.

At first, The following listA consisting of {a, b}. In practice, {a, b} is like an address determined by a random integer.

For example, there is listA.

listA = {{{1, 3}, {1, 1}, {3, 3}, {3, 1}},
{{1, 3}, {1, 2}, {2, 1}, {2, 3}},
{{3, 1}, {3, 2}, {1, 1}, {1, 2}},
{{2, 2}, {2, 3}, {3, 1}, {3, 3}},
{{3, 3}, {3, 2}, {2, 3}, {2, 1}}};


and listA is represented in a table as follows.

Next, I want to create a newlistA made up of {{a,b},c}.

templistA = {{{{1, 3},c}, {{1, 1},c}, {{3, 3},c}, {{3, 1},c}},
{{{1, 3},c}, {{1, 2},c}, {{2, 1},c}, {{2, 3},c}},
{{{3, 1},c}, {{3, 2},c}, {{1, 1},c}, {{1, 2},c}},
{{{2, 2},c}, {{2, 3},c}, {{3, 1},c}, {{3, 3},c}},
{{{3, 3},c}, {{3, 2},c}, {{2, 3},c}, {{2, 1},c}}};


The first occurrence of {a, b} is numbered as trial number 1. I want to number the next occurrence of {a, b} by counting from the number of trials in which it first appeared. And I want to create newlistA.

So, newlistA is represented in a table as follows.

I hope newlistA will be as follows.

  newlistA ={{{{1, 3},1}, {{1, 1},1}, {{3, 3},1}, {{3, 1},1}},
{{{1, 3},2}, {{1, 2},1}, {{2, 1},1}, {{2, 3},1}},
{{{3, 1},3}, {{3, 2},1}, {{1, 1},3}, {{1, 2},2}},
{{{2, 2},1}, {{2, 3},3}, {{3, 1},4}, {{3, 3},4}},
{{{3, 3},5}, {{3, 2},3}, {{2, 3},4}, {{2, 1},4}}};


Please let me know what I should do.

• Imagine you needed to tell me step by step how to find each c and then I must correctly do this alone without asking more questions. Please tell me exactly the steps I must do and the information I must use to do this for you. Thank you.
– Bill
Commented Dec 7, 2023 at 1:43

With[