Hello Group,
first let me thank you for this quiz. It is a hillarious idea. Never
would have come up with this by myself and it is really cool to see
the sourcecode vanish and reappear as if by magic.
I first thought to modify the whitout library such, that it includes a
loaded program, but then came to the solution to encode the file in
the whitespace. The simplest encoding / decoding routines are:
# Encode a string into whitespace
def encode(string)
string.unpack('B*')[0].tr('01', " \n")
end
# Decode a whitespace encoded string
def decode(string)
[string.tr(" \n", '01')].pack('B*')
end
But these make the files quite big. So I added two thing:
- Encoding into a eight-sign code with eight different whitespace
symbols that ruby doesn't choke on. This may show as non-whitespace in
something like an editor or "less", but using "cat" its only
whitespace.
- On the fly zipping of the files before encoding.
The encoding of a encoded file is detected by a four byte whitespace
header, so everything works out automatically.
I also added a nice user interface using optparse. Though there is
some optparse bashing going on at the moment I think it is really a
great library.
You can find my solution at:
http://ruby.brian-schroeder.de/quiz/whiteout/
Have fun with the solution and please don't come after me if you have
converted all your ruby code to whitespace and can't get it back.
--
http://ruby.brian-schroeder.de/
Guitar chords in different tunings: http://chordlist.brian-schroeder.de/guitar/