I have seen this code on stack overflow post. I didn't understand what is the function of this line int Other = 3 - Startpeg - Endpeg; Can anyone explain
//Pegs are counted 0 to 2
void Tower(int Disk, int Startpeg, int Endpeg)
{
if(Disc <= 0) //Sanity check
return;
if(Disc == 1)
cout << "Move disk from "<<Startpeg<<" to "<<Endpeg<<endl;
else
{
int Other = 3 - Startpeg - Endpeg;
Tower(Disc-1, Startpeg, Other);
Tower(1, Startpeg, Endpeg); //Inline output would do here... Calling for message consistency.
Tower(Disc-1, Other, Endpeg);
}
}
Can anyone explain this line int Other = 3 - Startpeg - Endpeg;
what is doing here and explain this line of code, what's going on here, Is it subtracting the endpeg from start and then then whole from 3 ?