RE: need to make a special function
- To: mathgroup at smc.vnet.net
- Subject: [mg68334] RE: [mg68284] need to make a special function
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 1 Aug 2006 07:00:08 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Nabeel,
I'm not certain if this is the most efficient or elegant but how about...
f[n_] :=
Module[{p, x, iters},
x = Table[p[i], {i, 1, n}];
iters = Table[{p[i], 0, 1}, {i, 1, n}];
Flatten[
Table[x, Evaluate[Sequence @@ iters]], n - 1]
]
f[1]
{{0}, {1}}
f[2]
{{0, 0}, {0, 1}, {1, 0}, {1, 1}}
f[3]
{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1,
0}, {1, 1, 1}}
f[4]
{{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 0, 0}, {0,
1,
0, 1}, {0, 1, 1, 0}, {0, 1, 1, 1}, {1, 0, 0, 0}, {1, 0, 0, 1}, {1, 0, 1,
0}, {1, 0, 1, 1}, {1, 1, 0, 0}, {1, 1, 0, 1}, {1, 1, 1, 0}, {1, 1, 1,
1}}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Nabeel Butt [mailto:nabeel.butt at gmail.com]
To: mathgroup at smc.vnet.net
Dear Users,
I need help on making a special type of function which has the
following properties.
f[1]={{0},{1}}
f[2]={{0,0},{0,1},{1,0},{1,1}}
f[3]={{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}}
.............so on you can see the pattern emerging.
I need a very efficient code to perform the above evaluation in some
optimization problem.
Thanks in advance.
regards,
Nabeel
--
Nabeel Butt
LUMS,Lahore