root@m.cs.uiuc.edu (08/31/90)
Here is a macro writing challange for all you TeX haxers out there. Write a long-division macro which does its own division. That is, given the input: $$ \longdivide 21 \by 7 $$ the macro should produce the output: 3 ---- 7) 21 21 -- 0 Of course provision should be made for remainder and precision. E.g., $$ \longdivide 127 \by 8 $$ should produce 15 ----- 8) 127 -80 --- 47 -40 --- 7 remainder and $$ \longdivide 127 \by 8 \precision 5 $$ should produce 15.875 --------- 8) 127 -80 --- 47 -40 --- 70 -64 --- 60 -56 --- 40 -40 --- 0 The final macro must: 1. Work in any sized math without any addtional coding by the end user. 2. Use the call format given above. That is, $\longdivide 234 \by 4$, or $\longdivide 234 \by 4 \precision 2$ and not, $\longdived{234}{4}{}$ for an example of how to do this see the macro for $\root 3 \of 2$. 3. Use character '102 or '142 from font A5796, along with a rule, for the long division symbol. 4. Decimal remainders should be handled when \precision is less than the number of decimals decimal digits in the correct answer. Exta cudos go for detecting repeating decimals. 5. Global parameters to handle, for example, a. rule thickness, b. number of digits found per subtraction, c. space above and below rules, d. and so on are encouraged as long as none of them need to be set by the end user before changing math sizes, or setting long division with or without a given precission. 6. Changing the \baselineskip, \parindent, \hangindent, \hangafter, or any other paragraph or math formatting primitive should result in correct output. The macro should not give poorly aligned output just because \baselineskip=10pt, instead of 12pt. 7. Changing any default formating primitive should give appropriate output. E.g., if \baselineskip=10pt then the long-division should set on a 10pt leading and not a 12pt leading. 8. Provide the correct answer to all long-division problems whose answer is less than 32 digits long. TeX does detect tail-recursion so infinite precision is, in priciple, possible. In other words, the macro should default to acceptable and predictable output regardless of where it is placed in a TeX file. I offer a **bag of Matt's Chocolate Chip cookies** to the first person, or group of people, to write the macro that meets all of the above specifications in a test file to be written by me, with L300 output checked and approved by not less than two coordinators of my choosing. Enjoy, Mike Sofka mike@morgana.pubserv.com