From a9398076003f1db4075580da6da950ee6b29158b Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:57:13 -0800 Subject: [PATCH] Format/typo check 1995/vanschnitz --- 1995/vanschnitz/README.md | 175 +++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 87 deletions(-) diff --git a/1995/vanschnitz/README.md b/1995/vanschnitz/README.md index 6d20750f1..56e90e8a6 100644 --- a/1995/vanschnitz/README.md +++ b/1995/vanschnitz/README.md @@ -60,7 +60,7 @@ never be placed on top of a smaller disk. Our program solves the Towers of Hanoi problem. Well, that's not exactly true; actually, it's the compiler that solves the -problem. The resulting program just prints out the correct\ +problem. The resulting program just prints out the correct solution. How do you trick a compiler into actually solving the problem? @@ -76,25 +76,24 @@ gcc hanoi.c -o hanoi -Dn=4 A default value of `5` will be used for `n` if you do not define it on the command line. The value of `n` cannot be greater than -fifteen (the compiler we used to test has a limit on the #include -depth). The compiler then solves the problem using binary\ +fifteen (the compiler we used to test has a limit on the `#include` +depth). The compiler then solves the problem using binary arithmetic based on whether particular symbols are defined or not. -To loop, the program `#include`s itself. This is, of course, -expensive; one compile we did with `n=14` took about fifty -minutes to compile on our system (compiling with `n=15` caused our system to -crash). +To loop, the program `#include`s itself. This is, of course, expensive; one +compile we did with `n=14` took about fifty minutes to compile on our system +(compiling with `n=15` caused our system to crash). The resulting program that the compiler generates simply prints out the answer. Did I say "simply"? Actually, the -whole resulting program consists of a single printf statement, +whole resulting program consists of a single `printf(3)` statement, consisting of a massive string constant of length `35*(2^n-1)`, followed by `3*(2^n-1)` integers which get formatted into the string. For our `n=14` run, this adds up to a string constant of length 573405, followed by 49149 integers delimited by commas. (Generating the string constant depends on the ANSI C feature in which adjacent character strings are -catenated; a version that does not use this feature has been +concatenated; a version that does not use this feature has been included for people who can only run K&R). A good way to see the resulting program (on a Unix system) is to do the command @@ -104,91 +103,93 @@ gcc hanoi.c -E -Dn=5 | grep -v \# | grep -v ^\$ For an odd number of disks, the program will provide a solution wherein the disks end up on peg 2; for an even -number of disks, they will end on peg 3. This should\ +number of disks, they will end on peg 3. This should provide some hint as to what sort of algorithm is used. We have included a [spoiler](spoiler.c) version of the program, with meaningful symbol names and comments, but we encourage you to try to decipher the program without it... - begin 444 spoiler.c - M(VEF;F1E9B`@24Y)5$E!3$E:140*"B\J"B`J("!)9B!N(&ES;B=T(&1E9FEN - M960L(&UA:V4@:70@-0H@*B\*(VEF;F1E9B`@;@HC9&5F:6YE("!N(#`U"B-E - M;F1I9@H*+RH*("H@4V]M92!UPIP2!N('=E)W)E(&UO=FEN9R!D:7-K(&XK,2X@5&AA="!M96%N6-L92`Q - M(#T^(#(@/3X@,R`]/B`Q+B!#;VUB:6YE('1H:7,@=VET:"!T:&4@:VYO=VQE - M9&=E"B`J("!O9B!W:&5R92!D:7-K(#$@:7,L(&%N9"!W92!C86X@9&5T97)M - M:6YE(&AO=R!T;R!M;W9E(&%N>2!D:7-K+@H@*B\*(VEF;F1E9B`@3D]77T1/ - M7U1(15].54U"15)3"D9/4DU!5%]35%))3D<*(V5LPIP2!N('=E)W)E(&UO=FEN9R!D:7-K(&XK,2X@5&AA="!M96%N6-L92`Q +M(#T^(#(@/3X@,R`]/B`Q+B!#;VUB:6YE('1H:7,@=VET:"!T:&4@:VYO=VQE +M9&=E"B`J("!O9B!W:&5R92!D:7-K(#$@:7,L(&%N9"!W92!C86X@9&5T97)M +M:6YE(&AO=R!T;R!M;W9E(&%N>2!D:7-K+@H@*B\*(VEF;F1E9B`@3D]77T1/ +M7U1(15].54U"15)3"D9/4DU!5%]35%))3D<*(V5L