Skip to main content
added 32 characters in body
Source Link
Chris Degnen
  • 31.4k
  • 2
  • 57
  • 112
Clear[P1, P2, B1, B2, P3, B3] Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count initially, to be replaced with Count

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Examples

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 

Assigning values after symbolic construction.

With[{d = a}, d = {1, 2, 3, 4, 3, 2}]; B2 
4 
B3combb /. count -> Count 
{f[1], f[2], f[3], f[4], -1 + f[3], -1 + f[2]} 
Clear[P1, P2, B1, B2, P3, B3] Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count initially, to be replaced with Count

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Examples

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 

Assigning values after symbolic construction.

With[{d = a}, d = {1, 2, 3, 4, 3, 2}]; B2 
4 
B3comb /. count -> Count 
-1 + f[2] 
Clear[P1, P2, B1, B2, P3, B3] Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count initially, to be replaced with Count

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Examples

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 

Assigning values after symbolic construction.

With[{d = a}, d = {1, 2, 3, 4, 3, 2}]; B2 
4 
b /. count -> Count 
{f[1], f[2], f[3], f[4], -1 + f[3], -1 + f[2]} 
added 171 characters in body
Source Link
Chris Degnen
  • 31.4k
  • 2
  • 57
  • 112
Clear[P1, P2, B1, B2, P3, B3] Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count initially, to illustrate the output. (Replacebe replaced with Count.)

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Example outputExamples

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 

Assigning values after symbolic construction.

With[{d = a}, d = {1, 2, 3, 4, 3, 2}]; B2 
4 
B3comb /. count -> Count 
-1 + f[2] 
Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count to illustrate the output. (Replace with Count.)

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Example output

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 
Clear[P1, P2, B1, B2, P3, B3] Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count initially, to be replaced with Count

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Examples

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 

Assigning values after symbolic construction.

With[{d = a}, d = {1, 2, 3, 4, 3, 2}]; B2 
4 
B3comb /. count -> Count 
-1 + f[2] 
added 58 characters in body
Source Link
Chris Degnen
  • 31.4k
  • 2
  • 57
  • 112
Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count to illustrate the output. (Replace with Count.)

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

E.g.Example output

P1comb 

B3comb

-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 
Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count to illustrate the output. (Replace with Count.)

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

E.g.

B3comb

-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 
Clear[P1comb, P2comb, B1comb, B2comb, P3comb, B3comb] a = {P1, P2, B1, B2, P3, B3}; b = {P1comb, P2comb, B1comb, B2comb, P3comb, B3comb}; 

Using lower-case count to illustrate the output. (Replace with Count.)

Array[With[{c = b[[#]]}, c = f[a[[#]]] - count[Take[a, # - 1], a[[#]]]] &, Length[a]] 

Example output

P1comb 
-count[{}, P1] + f[P1] 
B3comb 
-count[{P1, P2, B1, B2, P3}, B3] + f[B3] 
Source Link
Chris Degnen
  • 31.4k
  • 2
  • 57
  • 112
Loading