Tom's JavaScript Machine

[ Machine | Instructions | Examples | JavaScript Basics | Challenge | Hints | About ]

The Challenge

Write a self-reproducing program for Tom's JavaScript Machine. This is a program

  1. that is finite and not empty (obviously),
  2. that processes no input (this is a must),
  3. that produces itself as output (and this is also a must; the button `Challenge' is the judge),
  4. that uses only these JavaScript basics and extensions,
  5. that adheres to reasonable coding conventions, in particular, source lines must be no longer than 80 characters (this makes for a more interesting challenge), and
  6. that does not use the predefined constants QU and NL (this makes for an even more instructive challenge).

The latter three requirements could be dropped initially, but using extra JavaScript features is not necessary and can be distracting. Note that user-defined functions are not needed, but they can simplify life (a bit).

If you have a solution that has too long lines, then you are making good progress, but you should also try to improve that.

Here are three ways to cheat:

Put the program in the input and copy it with Run
Find the program text in the web page and write it with Challenge
Use the ability to obtain the source code of a function
(This also depends on how your browser's JavaScript engine formats source code.)
with Challenge

Other things that I consider cheating, but less so, are:

These things are allowed in full JavaScript, but it is more instructive to find a solution without extras. However, a solution using these features can be considered a step in the right direction. Needless to say, it is not necessary to use these features.

The output features of Tom's JavaScript Machine were introduced to circumvent some technical problems, so you can concentrate on the real challenge.

In case you get stuck, you can look at some hints.


Valid HTML 4.01 Transitional

©2009-2010, Tom Verhoeff (TU/e)
Feedback about this page is welcome