MetaGolfScript
MetaGolfScript is a family of programming languages, designed to allow zero length programs to be written, in order to win code-golf contests (although this sort of technique for winning contests has been banned at at least one code-golf site,[1] and many others don't allow the use of arbitrary languages).
Overview
The family consists of multiple languages, all named MetaGolfScript-N, where N is any integer.
For every task which can be solved with GolfScript:
- All languages in the family can solve the task as well
- There exists a language in the family, in which a zero length program solves the task.
Syntax
A non-empty MetaGolfScript-N program behaves identically to the same program in GolfScript, regardless of N.
An empty MetaGolfScript-N program behaves identically to the Nth possible GolfScript program. Programs are enumerated first by size, then by lexicographic order. E.g. program 0 is empty, program 1 contains a single NUL character, and so forth.
Examples
'Hello, World!'
Prints "Hello, World!" in all MetaGolfScript-N languages.
The empty program prints "Hello, World!" in the MetaGolfScript-209180605381204854470575573749277224 language.
Computational class
All MetaGolfScript languages are Turing-complete, as it can be shown to be computationally equivalent to GolfScript: any non-empty MetaGolfScript langauage behaves identically to the same program in GolfScript.
The interpreter
The following Python script implements MetaGolfScript-N, based on an existing GolfScript interpreter. The interpreter should be saved in a file named metags.N.py, to interpret the MetaGolfScript-N language.
import sys, os, tempfile
gs="./golfscript.rb"
def ns(n):
l=0
while n>=256**l:
n-=256**l
l+=1
return "".join(chr(n/(256**i)%256) for i in range(l-1,-1,-1))
p = sys.argv[1]
if os.stat(p).st_size == 0:
tmp = tempfile.NamedTemporaryFile()
tmp.write(ns(long(sys.argv[0].split('.')[-2]))) # Script name = meta-gs.N.py
tmp.flush()
p = tmp.name
os.system("%s %s"% (gs, p))