I give up... Nobody can teach a student who doesn't listen.
I give up... Nobody can teach a student who doesn't listen.
Also, no student can learn from a master who wont listen to him.
FYI, I managed to shuffle the minds just fine with a variation of the deck shuffle algorithm. Now I just need an algorithm to follow the theorem, which will most likely be the hardest part. Here's what I have so far if you wanna see what I did:
Code:#include<stdio.h> #include<string.h> #include<time.h> #include<stdlib.h> #define RANDS 9 int main (void) { int N, i; char Body [9] [15]; //Input Names printf("Give me 9 Names\n"); for (i = 0; i < 9; i++) { scanf ("%s", Body[i]); } //Scramble Array (Minds) int Mind[RANDS]; int item = 0; int temp; int idx = 0; srand(time(NULL)); for(idx = 0; idx < RANDS; idx++) Mind[idx] = idx + 1; // shuffle the array for (idx = RANDS - 1; idx > 0; idx--) { item = rand() % idx; temp = Mind[idx]; Mind[idx] = Mind[item]; Mind[item] = temp; } // shuffled array printf("\n\n"); printf ("\t(Body = Mind)\n"); for (idx = 0; idx < RANDS; idx++){ printf("%s %d = %d\n", Body[idx], idx+1, Mind[idx]);} system ("PAUSE"); //Unscramble, step by step, the array //Return Names system ("PAUSE"); }
There was a Stargate SG-1 episode like this exercise once. It was very well done too.
So I assume we're left at the coming up with the algorithm part? How about just starting with the implest possible idea you have and see where that gets you.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
OK, I'm back from running errands, and late to the puzzle party, but please bear with me - some questions, if you don't mind.
1) What episode of Stargate-SG1 was this on? I completely missed that one! (Season is even fine). I tried to look it up, but there are hundreds of episodes!
2) I thought there were two heads (one pair) transplanted in the problem. So why the emphasis on the Shuffle algorithm?
How many heads are on the wrong body?
3) How many bodies are there, in total that we can use?
Thanks for the update.
Okay, there are 9 bodies, ALL of them with the minds swapped, thus the enfasis in the shuffle. Once shuffled, you may add TWO unshuffled people to solve the equation. I've no idea about the SG episode, sorry.
So how are you doing with the shuffle? OK, or need some tips?
I already worked out the random shuffle, it's all on the post 32. All I need now is a way to add those 2 un-swapped guys to the array (I've tried strcat, but I'm pretty sure it didn't work), and then find a way to apply a sorting algorithm that won't swap 2 bodies that've already been swapped.
Perhaps you meant to use strcpy(destination, source), where destination and source, are the names of the char array or pointer to the strings.
Pardon me, but why a sorting algorithm? I can see you'd need a sequence of swaps, but sorting? Sort what?
The two new people can be bodies for holding onto brains, right?
Last edited by Adak; 12-02-2011 at 08:04 PM.
Season 2 episode 17 ... HERE
It starts with an alien swapping with Daniel... and ends with them doing a bunch of swaps to get everyone back in the right body.
The Prisoner of Benda - Wikipedia, the free encyclopedia
is not
Sorry if I contributed to that mayhemOriginally Posted by Ferreres93
Ferreres93, it is you that is going to pass or fail here, and there will be no bodies to switch, so make sure you understand what you are supposed to do and pay attention to the people who are here to help you!
I love sci-fi but Stargate always looked too gimmicky so I never gave it a chance. Futurama, OTOH, was one of the best series of the past decade
I'm off to watch "Metal Evolution" pt. 3, lol
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
This is a solution for 3 brains being switched, with two people we can use as "temporary holders". Very likely, it's not the most efficient way to do this.
persons are number 1, 2, and 3 (4 and 5 for the temps). Brains are denoted by 11, 22, 33, 44 and 55.
Final status:Code:Number People in the Swap Status ========================================== 1) 1<-->2 1.22, 2.11 2) 2<-->3 2.33, 3.11 Now 4 and 5 have joined us, our status is: 1.22, 2.33, 3.11, 4.44, 5.55 3) 1<-->3 1.11, 3.22 4) 2<-->5 2.55, 5.33 5) 3<-->4 3.44, 4.22 6) 2<-->4 2.22, 4.55 7) 3<-->5 3.33, 5.44 8) 4<-->5 4.44, 5.55
1.11, 2.22, 3.33, 4.44, 5.55
Of course, that's not for 9 people, and it's not a program, but it shows a pattern that could be used, I believe.
Brute force, could do this but I believe it's unnecessary in this case.
Last edited by Adak; 12-02-2011 at 10:58 PM.
Another example, again 3 brains have been swapped, but this time with a different sequence. Persons 4 and 5, again serve as temporary hosts. Everyone has a brain that is 10x their person number + their person number: 1 is 11, 2 is 22, ...5 is 55.
Hmmmm. Where'd I leave that deerstalking cap at?Code:Number People in the Swap Status ========================================== Starting status is: 1.33, 2.11, 3.22, 4.44, 5.55 Starting swaps to scramble were: 1) 1 & 2, then 2) 1 & 3 3) 1 & 4 1.44, 4.33 2 and 3 are unavailable, take the next person or host? 4) 3 & 4 3.33, 4.22 3 is ok always take the swap that makes a match, if available 5) 2 & 5 2.55, 5.11 6) 1 & 5 1.11, 5.44 1 is ok 7) 2 & 4 2.22, 4.55 2 is ok 8) 4 & 5 4.44, 5.55 4 and 5 are ok
Last edited by Adak; 12-02-2011 at 11:46 PM.
In very limited testing I have a program that works (initially with 3 brains having been swapped). When I get a chance, I'll up the brain number, and see how that goes.
I used a struct for the brain swappers with their number and their matching brain number, so:
guys[0].n is the zeroth guy's number, and guys[0].b is his brain number, and they are the same (until the swaps start).
I used a 2D array "swapped[5][5]", to keep track and increment the "scorecard" of the swaps. Initially, all elements in it were set to zero. So if guys[0] had swapped brains with guys[1], then:
If you ever have a two in your scorecard of swaps, then it's an error. Without the scorecard of swaps, I'd have had a very difficult time doing this.Code:swapped[0][1]++; //and swapped[1][0]++;
Last screen: