Welcome to the FLOG

The F648 Blog
Beating technology into submission,
one client at a time...

See What Our Clients Have To Say

Quote Author Image
"BY POPULAR DEMAND...
In the course of web development and hosting, many customers came to us about creative services. Do you know anyone who can help us with our logo? Can you handle copywriting? Where do we begin? We decided to find the answers to these questions and are excited to now offer expert creative services to our customers. "


Fast Fact:

Why Foundation648?

Can you think of a reason not to work with us? If you can, we would genuinely like to hear what we might do to earn your business.

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 post a comment.

1 comment for “Code Golf, GolfScript 101 and Phrasebook”

  1. Posted Tuesday, January 17, 2012 at 1:52:29 AM

    wish to say your article is as amazing. The clearness in your post is simply excellent and i can assume you’re an expert on this subject.

Post a comment