RE: [Dev-C++] Code for all combinations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-07-23 08:38:24
|
A slightly more efficient solution for the suspected school assignment:
#define BASE 11
#define MAX_DIGITS 6
int digit,vec[MAX_DIGITS];
for (;;) {
// This loop is also easy to unroll...
for (digit =3D 0; digit < MAX_DIGITS; digit++) {
if (++vec[digit] < BASE) break;
vec[digit] =3D 0;
}
if (digit >=3D MAX_DIGITS) break;
print(xx);
}
/Per W
On Wed, 23 Jul 2003, Rafael del Valle Huerta wrote:
> It's like counting in base 11 (6 digits, in reverse order).
>
> #define MAX 11L*11L*11L*11L*11L*11L // 11^6 -> 1.7e6
> ...
> unsigned long n, m;
> int i;
> int vect[6]=3D{0};
> ...
> for(n=3D0; n<MAX; n++) {
> m=3Dn;
> for(i=3D5; i>=3D0; i--) {
> vect[i]=3Dm%11;
> m/=3D11;
> printf("%ul, ", vect[i]);
> }
> printf("\n");
> }
> ...
>
> It's easy to "unroll" the inner loop in 6 steps and leave only one loop.
>
>
>
> -----Mensaje original-----
> De: dev...@li...
> [mailto:dev...@li...]En nombre de Rodolfo
> Dettorre
> Enviado el: mi=E9rcoles 23 de julio de 2003 6:31
> Para: Andr=E9 Mac=E1rio Barros; Dev-Cpp-Users
> Asunto: RE: [Dev-C++] Code for all combinations
>
>
> Hi,
>
> just curiosity, is that a school assignment? An idea would be to nest si=
x
> for statements.
>
> Regards
>
> Rodolfo d'Ettorre
>
> -----Original Message-----
> From: Andr=E9 Mac=E1rio Barros [mailto:and...@su...]
> Sent: Wednesday, 23 July 2003 1:54 PM
> To: Dev-Cpp-Users
> Subject: [Dev-C++] Code for all combinations
>
>
> Dear Users,
>
> I need to test all possibilities in a specific code.
> I couldn=B4t realize how I can generate theese possibilities with two
> for=B4s.
> Here is the problem:
>
> Suppose you have a vector like
> int vect[6]=3D{0};
>
> How could be a C code to have (print for example) all possible
> combinations in the
> six positions from the range 0 to 10?
> the output is something like:
> 0 , 0, 0, 0, 0, 0
> 1 , 0, 0, 0, 0, 0
> 2 , 0, 0, 0, 0, 0
> ...
> 10, 0, 0, 0, 0, 0
> 0 , 1, 0, 0, 0, 0
> 0 , 2, 0, 0, 0, 0
> ...
> 0 ,10, 0, 0, 0, 0
> 1, 1, 0, 0, 0, 0
> 2, 1, 0, 0, 0, 0
> ...
> 10, 1, 0, 0, 0, 0
> 1 , 2, 0, 0, 0, 0
> 2 , 2, 0, 0, 0, 0
> ...
> 10, 2, 0, 0, 0, 0
> ...
> ...
> 10,10,10,10,10,10
>
> Some repetition values are allowed, that is, if you have to
> reset all values to begin the counting to another digit, etc.
>
> Regards
> Andre
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
> same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
> same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
> same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|