Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Author: Mischi Alexander // Program: MischiAlexander.cpp #include #include #include void s (const unsigned int i) { if (i%120 > 0) s(i-1); ifm::left(1); ifm::forward(); } void w (const unsigned int i) { if (i%120 > 0) w(i-1); ifm::right(1); ifm::forward(); } unsigned x (unsigned int i) { ifm::left(60); int k= i; ifm::save(); while (i > 120) { i-=120; if ((i%240) >= 120) w(i); else s(i); } ifm::restore(); ifm::save(); ifm::left(61); while (k > 120) { k-=120; if ((k%240) >= 120) s(k); else w(k);} ifm:: restore(); } unsigned k (unsigned int i) { if (i > 0) { double o=3.3; while (o>0) {o-=0.1; k(i-1); x(900); ifm::left(119); ifm::forward(o); ifm::right(179); }} } void f (const unsigned i) { double h=3.2; k(i); ifm::jump(16); ifm::left(89); ifm:: jump(63); ifm::right(90); ifm::left(60); while (h>0) { h-=0.4; ifm::left(119); ifm::forward(h); ifm::right(179); x(900); } } ifm::integer fac (ifm::integer x) { ifm::integer l=1; if (x== 1 || x==0) x=1; else while (x > 1) { l*=x; --x; } return l; } unsigned c (const unsigned int i) { int z; if (fac(i)%30<10)z=5; else z=0; ifm::forward(5); ifm::right(z); if (i==0) ifm::forward(); else { c(i-1); ifm::save(); ifm::left(30); ifm::forward(2); c(i-1); ifm::restore(); ifm::right(12); ifm::forward(2);} } unsigned u (unsigned int i) { ifm::left(50); int k= i; ifm::save(); while (i > 120) { i-=120; if ((i%240) >= 120) w(i); else s(i); } ifm::restore(); ifm::save(); ifm::left(61); while (k > 120) { k-=120; if ((k%240) >= 120) s(k); else w(k);} ifm:: restore(); } void p (unsigned int i) { if (i > 0) p(i-1); u(900); ifm::left(110); ifm::forward(10); ifm::right(170); } int main() { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; f(1); ifm::left(265); ifm::jump(15); c(11); ifm::left(28); ifm::jump(180); ifm::right(165); f(1); ifm::left(265); ifm::jump(15); c(11); ifm::left(90); ifm::jump(180); ifm::left(135); f(1); ifm::left(265); ifm::jump(15); c(11); ifm::right(145); ifm::jump(185); ifm::left(6); f(1); ifm::left(265); ifm::jump(15); c(11); ifm::right(61); ifm::jump(300); p(n); return 0; }