Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Combinations of Points

Name: Anonymous 2012-05-14 13:56

I have a set of 8 unique points, and I need to cycle through all possible routes between those points, [preferably] using recursion.

How do I go about a problem like this?

Name: Anonymous 2012-05-15 2:48

here ya go op!


#include <stdio.h>

void main() {
  int i1;
  for(i1 = 0; i1 < 8; i1++)
    {
      int i2;
      for(i2 = 0; i2 < 8; i2++)
        {
          if(i2 != i1)
            {
              int i3;
              for(i3 = 0; i3 < 8; i3++)
                {
                  if(i3 != i1 && i3 != i2)
                    {
                      int i4;
                      for(i4 = 0; i4 < 8; i4++)
                        {
                          if(i4 != i1 && i4 != i2 && i4 != i3)
                            {
                              int i5;
                              for(i5 = 0; i5 < 8; i5++)
                                {
                                  if(i5 != i1 && i5 != i2 && i5 != i3 && i5 != i4)
                                    {
                                      int i6;
                                      for(i6 = 0; i6 < 8; i6++)
                                        {
                                          if(i6 != i1 && i6 != i2 && i6 != i3 && i6 != i4 && i6 != i5)
                                            {
                                              int i7;
                                              for(i7 = 0; i7 < 8; i7++)
                                                {
                                                  if(i7 != i1 && i7 != i2 && i7 != i3 && i7 != i4 && i7 != i5 && i7 != i6)
                                                    {
                                                      int i8;
                                                      for(i8 = 0; i8 < 8; i8++)
                                                        {
                                                          if(i8 != i1 && i8 != i2 && i8 != i3 && i8 != i4 && i8 != i5 && i8 != i6 && i8 != i7)
                                                            {
                                                              printf("(%d, %d, %d, %d, %d, %d, %d, %d)\n", i1, i2, i3, i4, i5, i6, i7, i8);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List