I want to create a variable list like this:
{0, 0, ..., 0, 0, 1, 1}
This list would grow list this, starting with no 0's, but then gaining more 0's to the left the larger you want it.
f[0] := {1, 1}
f[1] := {0, 1, 1}
f[2] := {0, 0, 1, 1}
f[3] := {0, 0, 0, 1, 1}
f[4] := {0, 0, 0, 0, 1, 1}
I know that I can use Table
to create ten 0
by doing
Table[0, 10]
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
but not an efficient way to have it so that the last two digits are 1
.
PadLeft
andPadRight
would be better than the solution you found. There’s alsoJoin
andCatenate
which are used for this, rather thanFlatten
. $\endgroup$list[nzeros_] := PadLeft[{1, 1}, nzeros + 2]
usagelist[0]
,list[1]
,list[6]
, etc. $\endgroup$