a question from Maple users
Alec Mihailovs
alec at mihailovs.com
Mon May 15 19:07:29 CEST 2006
From: "Emeric Deutsch" <deutsch at duke.poly.edu>
>
> I'd like to be able to get for any n all the n-dimensional
> 0-1 vectors (2^n, of course).
> For a particular n, for example n=3, I can write the
> command
>
> [seq(seq(seq([u,v,w],u=0..1),v=0..1),w=0..1)];
>
> leading to
> [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1],
> [1, 0, 1], [0, 1, 1], [1, 1, 1]]
>
> How can I avoid writing seq n times?
There are many ways of doing that. I like
f:=n->[seq](k, k=Array((0..1)$n,()->[args])):
For example,
f(3);
[[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 1],
[0, 1, 1], [1, 1, 1]]
Alec Mihailovs
More information about the SeqFan
mailing list