Sunday, July 9, 2017

computer puzzle - MathJax: ones and zeros


Do or do not, there is no try.     — Yoda


Here is another MathJax puzzle. The Starring MathJax puzzle involved handling numbers in MathJax, even though there are no count registers or numeric operations implemented in MathJax. This puzzle continues with that theme.


Goal: find the minimal replacement for (replace this line) in the following MathJax code


$$\require{begingroup}\begingroup
(replace this line)
\binary{19}
\endgroup$$

so that the output is the number 19, but displayed in binary:



$$10011$$


The Catch? Your code should produce the proper binary number no matter what non-negative integer is given in place of 19.


When counting the length of your solution, control sequences count as 1 character, as do macro parameters #1 (and ## if needed, and even ##1 if used in a nested macro definition), and pairs of braces ({ with a paired } count as one). So \stars and \s each count as 1. All other non-white-space characters count as 1, but please do use spaces and line breaks for clarity.


Example: \def \x #1:#2\x {#1#1\stop} has a character count of 10.


To make this easier, I've made a code snippet that counts the tokens for you. (Unfortunately, there are no code snippets on this site, so I had to use the SE sandbox for it.) Run the snippet, then paste your MathJax code into the resulting text area and press "Count Tokens". Only paste in the replacement lines, not the \require{begingroup}\begingroup or the \binary{19} or \endgroup lines, or they will be counted against you!


Do not use any additional \require{...} macros, or defeat the final call to \endgroup. Admittedly, the audience for this puzzle is small. Please share any answer that even almost works. A solution is known, and will be posted after a suitable period, if no other solution is offered.


It is not necessary to display your solution in a spoiler. Explanations, especially including self-tracing code is a plus, but not a requirement. A solution is known, but it is likely not optimal.


NOTE ☆ Before posting an answer, be sure to test it on a freshly loaded browser page ☆ Might also need to reload the page while editing, as inadvertent indiscretions in one edit can pervert MathJax results during later edits ☆




No comments:

Post a Comment

classical mechanics - Moment of a force about a given axis (Torque) - Scalar or vectorial?

I am studying Statics and saw that: The moment of a force about a given axis (or Torque) is defined by the equation: $M_X = (\vec r \times \...