1
$\begingroup$

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.

enter image description here

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.

enter image description here

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.

$\endgroup$
1
  • 4
    $\begingroup$ 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. $\endgroup$
    – Bill
    Commented Dec 7, 2023 at 1:43

1 Answer 1

1
$\begingroup$

How about something like this...

With[
  {homeRows = # -> First[FirstPosition[listA, #]] & /@ Union @@ listA},
  MapIndexed[{#1, 1 + #2[[1]] - Lookup[homeRows, Key[#1]]} &, listA, {-2}]]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.