Code Golf, GolfScript 101 and Phrasebook
Monday, April 25, 2011
Recall that I am a language nut.
GolfScript is a language
built for the single purpose of code golf - solving a programming
problem in the fewest number of characters, or strokes. (
Not lines, characters.) The two code golf venues where you'll
see GolfScript are CodeGolf.SE (Which is
not found at codegolf.se) and Anarchy Golf (which is extremely
quiet, peaceful, well organized and automatically judged).
When I started hanging around CodeGolf.SE, I submitted all my
golfs in J, an APL-like
language with really mind-bending array-oriented, function-level
features. But as short, dense and powerful as J is, my solutions
ket getting beaten by even denser, more nonsensical-looking code in
GolfScript, which I had never heard of. Here's an example of
GolfScript:
@6?:yr)
(f/s{][=p@s's}+>;4"#\vkec025:cu(
No, wait, that's a randomly
generated1 string of
gibberish. This is actual GolfScript:
~\:@;0
1{.3$&{\@+\}{}if@@+:@;.+.3$>!}do;\;
(
Thanks, Juan. )
So, for semi-obvious reasons, I kept at it with the J. See
footnote 1 for an example of J, which can be quite lucid by
comparison.
And I kept getting beaten, though mysteriously never on problems
that involved floating point math. I looked at the GolfScript
site... Looked at the builtins... Looked at the examples... And
still didn't really get it.
Then, about a week ago, I finally caved and wrote some
GolfScript.
GolfScript 101
Here's
the official GolfScript tutorial. That glosses over how to run
GolfScript, although it's almost trivial. You'll need Ruby
installed, and you'll need GolfScript.rb saved somewhere handy.
Also, you cannot provide input to GolfScript programs from the
terminal, so you'll have to give it through pipes or
redirection.
This article was published before it was finished, so I'm
leaving it here to be continued at a later date...
1. The J code for generating random GolfScript
looking-gibberish is "(u: (32+i.33), (91+i.36)) {~ ? (40) # 69".
I'm really still a J guy.
This entry was written by Administrator,
posted on Monday, April 25, 2011
Bookmark the permalink.
Follow any comments here with the
RSS feed for this post.
You can .