I have a list of integers {3,4,2,2}
.
This list will give patterns {x_,_,y_,y_,_,_,z_,z_,w_,w_,x_}
and {0,0,0,1,1,1,1,0,0,1,1}
.
Notice that I want to assign successive 0,1
with the same symbol.
How to make this?
*edit
Compare the patterns
{x_,_,y_,y_,_,_,z_,z_,w_,w_,x_}
{0, 0, 0,1, 1,1, 1,0, 0,1, 1 }
{1, _, 2,2, _,_, 3,3, 4,4, 1 }
Suppose I have symbols {x_,y_,z_,w_}
(you may use {a_,b_,c_,d_,...}
).
To transform lst={3,4,2,2}
to {x_,_,y_,y_,_,_,z_,z_,w_,w_,x_}
,
begin with {x_,_,_,_,_,_,_,_,_,_,_}
.
Then put y_
at positions lst[[1]]
and lst[[1]]+1
.
Then put z_
at positions lst[[1]]+lst[[2]]
and lst[[1]]+lst[[2]]+1
.
Then put w_
at positions lst[[1]]+lst[[2]]+lst[[3]]
and lst[[1]]+lst[[2]]+lst[[3]]+1
.
And finally put x_
at the last position.
0
is next to1
, assign them with the same symbol. If0
is next to0
(or1
is next to1
), assign with_
. $\endgroup${x_,_,y_,y_,_,_,z_,z_,w_,w_,x_}
? Also, how would you extend the symbol list it there were, say, 7 control integers rather than 4? $\endgroup${3, 4, 1, 2}
be handled? $\endgroup$