Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Informatik - Serie 11 - Aufgabe 125 // Programm: DaesterSimon.cpp // Autor: S. Däster #include #include //Angle const unsigned int angle = 20; //POST: Replaces F with FF; void f(const unsigned int i); //POST: Replaces X with [++FX][+FFX][-FFX][--FX]FFFX void x(const unsigned int i) { //X = [++FX][+FFX][-FFX][--FX]FFFX if(i == 0) { ifm::forward(); } else { //[... ifm::save(); ifm::right(angle); ifm::right(angle); f(i-1); x(i-1); ifm::restore(); //...] //[... ifm::save(); ifm::right(angle); f(i-1); f(i-1); x(i-1); ifm::restore(); //...] //[... ifm::save(); ifm::left(angle); f(i-1); f(i-1); x(i-1); ifm::restore(); //...] //[... ifm::save(); ifm::left(angle); ifm::left(angle); f(i-1); x(i-1); ifm::restore(); //...] f(i-1); f(i-1); f(i-1); x(i-1); } } void f (const unsigned int i) { //F = FF if (i == 0) { ifm::forward(); } else { f(i-1); f(i-1); } } void g (const unsigned int i) { if (i == 0) ifm::forward(); // F else { g(i-1); // w_{i-1}^F ifm::left(90); // + g(i-1); // w_{i-1}^F ifm::left(90); // + if (i > 1) { g(i-2); // w_{i-1}^F ifm::left(90); // + g(i-2); // w_{i-1}^F ifm::left(90); // + } } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; // turn turtle to the right position ifm::left(90); ifm::save(); x(n); ifm::restore(); ifm::left(150); g(n+8); return 0; }