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

Let us first deal with the exercise of the preceding hint. Again, we put the two fragments in the string. That means that function tr will look like this:

where N is the length of the second fragment, that is, of );. The use of a negative index argument i in substr is short for i - s.length.

So, the construction program to put the pieces together will be:

This construction program outputs the following ():

This is itself a program, which by construction should produce itself as output:

Again, it is a small wonder to :

Once more, the one-line program is rather long: characters. Too long to be acceptable.

There are actually three related but distinguishable problems. First, the program is long because we put all the statements on a single line. Part of this is easy to repair:

This program still produces the same output as before (one long line, ), because we only changed its layout, not its functionality. Hence, it does not produce itself as output.

In case of our earlier program (without user-defined function), we could get ():

Furthermore, the string literal itself is too long (making the longest line still characters long). Finally, we need a way to produce output on multiple lines from a single string.

Can you think of ways to address the two remaining issues:

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

These issues can be addressed separately, but there are also some useful relationships. You may have to give up some earlier choices. Some new ideas are needed.

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