Hints for the Challenge:

Below, you can find another hint for the Challenge.

You should only get here after reading, digesting, and applying the .

Hint

So, the aim is to solve two more problems:

  1. Distribute the string over multiple lines.
  2. Produce multiple lines of output from a single string.

Let us address the second problem first (divide and conquer; separation of concerns). This means that we are looking for a way to have the program write itself as output, where each statement is on a separate line, but where the string literal is still long and on a single line.

The newlines will not appear using write(), because we have no way of putting newlines in the string literal.

N.B. JavaScript does have a facility to put newlines in string literals (we could use NL or the escape mechanism '\n'). But we want to avoid that, because

Consequently, the newlines will only appear when we use writeln() instead of write().

There is a blunt way of approaching this problem. Write each program line by extracting it from S using a statement of the form:

where you put appropriate numbers (start index and length) on the dots.

Can you develop this idea into a better solution?

Try your program in the machine, and see if you can extend it to a complete solution.

Apply the Hint

It is your turn ...

Need Another Hint?

If you tried this hint, or do not see how it helps, then you are ready for the .


Valid HTML 4.01 Transitional

Copyright ©2009, Tom Verhoeff, T.Verhoeff@TUE.NL