## Answer to Part 1 ### >! <p>We encode a dragon, $D$, as a string of $L$s and $R$s, where we start facing right and place the first letter at our starting point. If it is an $L$, we turn left and move forward one space; if it is an $R$ turn right and move forward one space. Then place the second letter, and repeat the process until the string of letters is used up.</p> >! <p>Given a dragon, $D$, we write $\overline D$ to mean the dragon obtained from $D$ by replacing all its $L$s with $R$s and *vice versa*. We write $\neg D$ to represent the dragon whose string of letters is the string for $D$ listed in reverse. Finally, for two dragons, $D$ and $D'$, we write $DD'$ to mean the dragon whose string is the concatenation of the strings for $D$ and $D'$, in that order.</p> >! <p>Let $D_i$ represent the level $i$ dragon, and take $D_1 = R$ and $D_2 = LRR$. Then $D_i$ (for $i\ge3$) is obtained by $(\neg\overline{D_{i-2}})\, D_{i-1}\, D_{i-2}$.</p> --- ## Answer to Part 2 ## Here is my preliminary solution to part 2. It produces all the dragons through level 11 without needing to adjust the MathJax parameters. It runs out of macro substitutions at level 12. Level 13 would definitely exceed the buffer size for this code, but I might be able to get level 12 with some work (I haven't tried to optimize macro calls, or reduce the buffer usage at this point). I have put some comments in the code (listed after the diagrams below), but don't have time to write anything more about it at the moment. I think it should be pretty straight forward. It is best to use the CommonHTML output for MathJax rather than the HTML-CSS output, since the former is more accurate (the placement may be off a bit with the default HTML-CSS output). It also turns out the the Preview HTML output is a good option for this as well. To switch, right-click (or CTRL-click) on any typeset math, and select the "Math Settings" menu, then the "Math Renderer" submenu, then the "CommonHTML" output. I'd also turn off the "Fast Preview", and the "Assistive MathML" options for best results. $\require{begingroup}\begingroup \def\safe{\text{\endgroup error}}$ $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Some utility functions: % % % Make a large rectangle to surround the dragon. % \def\Board#1#2{\bbox[border:1px solid black]{\xspace{#1}\Rule{0em}{#2em}{0em}}} % % Place a letter at the right location on the board. % \def\Place#1#2#3{\smash{\rlap{\xspace{#1}\raise{#2em}{#3}}}} % % Do the horizontal space (the letters are a bit bigger than an ex, % so add extra space via pts). % \def\xspace#1{\hskip #1ex\hskip #1pt \hskip #1pt \hskip #1pt} % % Place a marker with a given color at the correct place. % \def\Marker#1#2#3{\Place{#1}{#2}{\color{#3}{\kern-2.25pt\raise.25pt\bigcirc}}} \def\Marker#1#2#3{} % don't put in markers -- comment out to show them % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Create a dragon from the currently saved dragon string starting % at the given location on the board. % \def\Dragon#1#2{\small\sf\Marker{#1}{#2}{green}\Dii{\D{#1}{#2}\E} \P \X} % % Check if there is more letters and call \P if so and \X if not. % \def\D#1 #2#3 #4{#4#1 #2#3 #4} % % Place the letter at the current location. % Then define \T to determine the new orientation from % the current one and the current letter. % Perform the orientation command in order to move to the new location. % \def\P#1#2#3#4{ \Place{#1}{#2}#4 \def\T##1#4#3 ##2##3\T{##2{#1}{#2}##2 } \T L\E \N R\E \S L\S \E R\S \W L\W \S R\W \N L\N \W R\N \E \T } % % These are the commands to move in the given direction % \def\N#1#2{\def\n##1 #2 ##2 ##3\n{\D{#1}{##2}}\p} \def\E#1#2{\def\n##1 #1 ##2 ##3\n{\D{##2}{#2}}\p} \def\S#1#2{\def\n##1 #2 ##2 ##3\n{\D{#1}{##2}}\m} \def\W#1#2{\def\n##1 #1 ##2 ##3\n{\D{##2}{#2}}\m} % % A cheap version of addition and subtraction (works from 0 to 50, % and clamps to those values so that we don't go off the edge). % It would be nice to make it so that this workes for arbitrary % positive integers. % \def\p{ \n. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 50 \n } \def\m{ \n. 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 \n } % % Stop making a dragon by cleaning up and placing the final marker. % \def\X#1#2#3\X{\Marker{#1}{#2}{red}} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % These function produce new dragons from old ones % % This uses Di and Dii to produce the next dragon string by % reversing and inverting the Di, appending Dii, then appending Di, % then makes Di be the original Dii, and Dii the new dragon. % The \Copy macro copies a dragon to the end of the string % The \Reverse macro reverses and changes the letters in a dragon % using a loop like we have seen before, and a macro to interchange % L's and R's. % \def\NextDragon{\Di\Reverse\It \Dii\Copy\It \Di\Copy\It \Define \EndD} \def\Define#1\EndD{\let\Di=\Dii \def\Dii##1{##1 #1}} \def\Copy#1\It#2\EndD{#2#1\EndD} \def\Reverse#1\It{\R#1 \R {}} \def\R#1#2 #3#4\Define {\def\LR##1#1 ##2##3\LR {#3#2 #3#4\Define##2}\LR R L R \R {} \LR } % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % The initial two dragons (D_0 and D_1) % \def\Di#1{#1 R} \def\Dii#1{#1 R} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% $ $ \Dragon{2}{2} \Board{5}{5} $ $ \NextDragon \Dragon{2}{2} \Board{6}{6} $ $ \NextDragon \Dragon{3}{2} \Board{6}{7} $ $ \NextDragon \Dragon{5}{2} \Board{8}{8} $ $ \NextDragon \Dragon{7}{4} \Board{10}{9} $ $ \NextDragon \Dragon{9}{7} \Board{12}{12} $ $ \NextDragon \Dragon{7}{12} \Board{13}{16} $ $ \NextDragon \Dragon{6}{15} \Board{20}{20} $ $ \NextDragon \Dragon{6}{12} \Board{28}{23} $ $ \NextDragon \Dragon{6}{10} \Board{36}{36} $ $\NextDragon$ $ \Dragon{19}{9} \Board{41}{52} $ $\endgroup\safe$ The code: $\require{begingroup}\begingroup \def\safe{\text{\endgroup error}}$ $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Some utility functions: % % % Make a large rectangle to surround the dragon. % \def\Board#1#2{\bbox[border:1px solid black]{\xspace{#1}\Rule{0em}{#2em}{0em}}} % % Place a letter at the right location on the board. % \def\Place#1#2#3{\smash{\rlap{\xspace{#1}\raise{#2em}{#3}}}} % % Do the horizontal space (the letters are a bit bigger than an ex, % so add extra space via pts). % \def\xspace#1{\hskip #1ex\hskip #1pt \hskip #1pt \hskip #1pt} % % Place a marker with a given color at the correct place. % \def\Marker#1#2#3{\Place{#1}{#2}{\color{#3}{\kern-2.25pt\raise.25pt\bigcirc}}} \def\Marker#1#2#3{} % don't put in markers -- comment out to show them % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Create a dragon from the currently saved dragon string starting % at the given location on the board. % \def\Dragon#1#2{\small\sf\Marker{#1}{#2}{green}\Dii{\D{#1}{#2}\E} \P \X} % % Check if there is more letters and call \P if so and \X if not. % \def\D#1 #2#3 #4{#4#1 #2#3 #4} % % Place the letter at the current location. % Then define \T to determine the new orientation from % the current one and the current letter. % Perform the orientation command in order to move to the new location. % \def\P#1#2#3#4{ \Place{#1}{#2}#4 \def\T##1#4#3 ##2##3\T{##2{#1}{#2}##2 } \T L\E \N R\E \S L\S \E R\S \W L\W \S R\W \N L\N \W R\N \E \T } % % These are the commands to move in the given direction % \def\N#1#2{\def\n##1 #2 ##2 ##3\n{\D{#1}{##2}}\p} \def\E#1#2{\def\n##1 #1 ##2 ##3\n{\D{##2}{#2}}\p} \def\S#1#2{\def\n##1 #2 ##2 ##3\n{\D{#1}{##2}}\m} \def\W#1#2{\def\n##1 #1 ##2 ##3\n{\D{##2}{#2}}\m} % % A cheap version of addition and subtraction (works from 0 to 50, % and clamps to those values so that we don't go off the edge). % It would be nice to make it so that this workes for arbitrary % positive integers. % \def\p{ \n. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 50 \n } \def\m{ \n. 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 \n } % % Stop making a dragon by cleaning up and placing the final marker. % \def\X#1#2#3\X{\Marker{#1}{#2}{red}} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % These function produce new dragons from old ones % % This uses Di and Dii to produce the next dragon string by % reversing and inverting the Di, appending Dii, then appending Di, % then makes Di be the original Dii, and Dii the new dragon. % The \Copy macro copies a dragon to the end of the string % The \Reverse macro reverses and changes the letters in a dragon % using a loop like we have seen before, and a macro to interchange % L's and R's. % \def\NextDragon{\Di\Reverse\It \Dii\Copy\It \Di\Copy\It \Define \EndD} \def\Define#1\EndD{\let\Di=\Dii \def\Dii##1{##1 #1}} \def\Copy#1\It#2\EndD{#2#1\EndD} \def\Reverse#1\It{\R#1 \R {}} \def\R#1#2 #3#4\Define {\def\LR##1#1 ##2##3\LR {#3#2 #3#4\Define##2}\LR R L R \R {} \LR } % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % The initial two dragons (D_0 and D_1) % \def\Di#1{#1 R} \def\Dii#1{#1 R} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% $ $ \Dragon{2}{2} \Board{5}{5} $ $ \NextDragon \Dragon{2}{2} \Board{6}{6} $ $ \NextDragon \Dragon{3}{2} \Board{6}{7} $ $ \NextDragon \Dragon{5}{2} \Board{8}{8} $ $ \NextDragon \Dragon{7}{4} \Board{10}{9} $ $ \NextDragon \Dragon{9}{7} \Board{12}{12} $ $ \NextDragon \Dragon{7}{12} \Board{13}{16} $ $ \NextDragon \Dragon{6}{15} \Board{20}{20} $ $ \NextDragon \Dragon{6}{12} \Board{28}{23} $ $ \NextDragon \Dragon{6}{10} \Board{36}{36} $ $\NextDragon$ $ \Dragon{19}{9} \Board{41}{52} $ $\endgroup\safe$