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 - Challenge 125 // Program: GersterBirgit.cpp // Autor: Birgit Gerster // Draw a Christmas tree # include # include # include // PRE: the input n>0 // POST: a Christmas tree is drawn void furcation (unsigned j) { if (j>0) { ifm::forward (); ifm::save(); ifm::right(225); ifm::forward(); furcation (j/3); ifm::restore(); ifm::save (); ifm::left(225); ifm::forward(); furcation (j/3); ifm::restore(); furcation (j-1); } } void length_trunk (int i) { for(int n=i*3/10; n>0;--n) { ifm::forward (); } } void trunk (unsigned int i) { if (i==0); else{ ifm::right(90); length_trunk (i); ifm::left(179); length_trunk(i); } } int main () { //Input std::cout << "Number of iterations=?"; unsigned int n; std::cin>> n; //Check Input assert (n>0); // Draw Christmas tree trunk (n); ifm::right(90); trunk (n); furcation (n); return 0; }