15
3
Write a program that is capable of randomly generating itself.
It must do this based on the tokens used in its source code. If your program's source code is composed of 50 unique tokens and is 60 tokens long, then the program should output 60 tokens where each token is randomly chosen from one of the 50 unique tokens.
For example, this program would have a one in 50^60 chance to reproduce itself.
What is a token? That depends on the language. For example, identifiers (foo_bar
), keywords (while
), and numbers (42
) would count as tokens in most languages. Whitespace would not count in most languages.
Additional rules:
- Output may only contain tokens found in the programs source code, separated by the appropriate delimiter
- Output must be the same length as the program's source code, counted by tokens
- Only one programming language may be used
- Source code must have at least 3 unique tokens
- Exclude comments from the source code
- Program should only have a one in U^L chance to reproduce itself
Scoring: The program that has the best chance to reproduce itself, wins.
Does the randomness have to be uniform? – Jo King – 2018-12-01T03:48:07.790
@MathieuRodic: You're assuming that the program draws tokens without repetition. – user2357112 supports Monica – 2014-03-25T09:48:10.540
@MathieuRodic: Let me rephrase. You're assuming the program randomly scrambles the multiset of its tokens, rather than drawing L tokens with repetition from the set of U tokens used in its source. – user2357112 supports Monica – 2014-03-25T09:52:58.453
@user2357112: I see. My mistake was to consider this problem as a draw without replacement. – Mathieu Rodic – 2014-03-25T10:02:18.970
1Rule #1 and #5 appear to be in contradiction to me. – Cruncher – 2014-03-25T13:46:37.613
Also rule #5 in conjunction with the scoring means that the highest possible score is if it has exactly U^L chance? – Cruncher – 2014-03-25T13:49:03.500
@Cruncher Fixed the contradiction. I edited earlier to simplify and ended up messing it up. – Austin Henley – 2014-03-25T14:14:30.777
@Cruncher The highest possible score is by minimizing U^L. – Austin Henley – 2014-03-25T14:15:54.503
4Can you assume that built in random functions are TRNGs? Typical implementations have too small seeds to produce all outputs and thus might be unable to actually regenerate itself. – CodesInChaos – 2014-03-25T15:20:05.387
@CodesInChaos Sounds like a safe assumption to me. – Austin Henley – 2014-03-25T16:01:37.947
@abligh No, how does that contradict? Minimize U^L. Or maximize 1/U^L. – Austin Henley – 2014-03-25T18:30:28.513
@AustinHenley doh. Deleted that comment. – abligh – 2014-03-25T18:31:12.800