33

See http://codegolf.stackexchange.com

It seems that someone gives us a problem to solve, tags the question and the winner is whoever completes the solution in the fewest characters. I haven't found a reference for what it is, so lets discuss its purpose here.

EDIT: OK, we've explained what it is, but why stage a competition to see who can use the least number of characters? It's an interesting contest (and that may be the point and I'm looking too deeply) but it doesn't seem to have any other reason. It is terrible to read; I think we could have more interesting contests to see who could make the fastest or most flexible or otherwise "best" solution.

3
  • 7
    Justifying a game is like explaining a joke is like dissecting a butterfly.
    – Benjol
    Commented Feb 8, 2010 at 9:06
  • 3
    What is the purpose of sudoku and crosswords?
    – gnibbler
    Commented Mar 19, 2010 at 20:47
  • 3
    @gnibbler to be able to show others how smart I am. Commented Jun 20, 2010 at 0:11

9 Answers 9

36

Like in golf where the low score wins, the fewest amount of characters "wins". While certainly the best solution in every case is not necessarily the solution that has the fewest characters or fewest lines of code, it can be a fun way to exercise your programming muscles. There is even a Code Golf stack exchange.

1
  • 18
    Yes, “fewest (key)strokes wins” is exactly what I had in mind when I coined the phrase.
    – Greg Bacon
    Commented Aug 5, 2010 at 20:53
14

Try to solve the problem using the fewest possible characters of source code.

It's relatively well-known in Perl circles, since Perl's flexibility and terseness make possible very brief solutions to many problems. In fact, some sources say that code golf originated as "Perl golf". It's no coincidence that in language-agnostic code golf challenges, a Perl solution is usually the winner.

When the winner uses a language other than Perl, that is truly an accomplishment, not only because Perl is naturally suited to this sort of challenge, but because Perl programmers are largely well-acquainted with the game and know the tricks and techniques to golf effectively in their language of choice.

3
  • 5
    I do not think that winning solutions in GolfScript are "truly an accomplishment". :-P Commented Oct 13, 2009 at 17:14
  • Well, it's at least "kinda" an accomplishment. It's not like you don't have to think to write a GolfScript solution. ;) Commented Dec 1, 2009 at 21:04
  • Writing or understanding GolfScript appears to be less of a challenge than doing the same with J, though. At least in my experience.
    – Joey
    Commented Jun 9, 2010 at 22:08
8

shortest->+1

(12 character response)

6

I like the atmosphere of code-golf on SO, The other sites mentioned all have us golf in secret and sometimes never reveal the secret source.

As someone who golfs regularly on SO in 6 or so languages, I find I am sometimes learning useful new things about those languages due to the openness and collaboration that is unique to SO code-golf.

2
  • 1
    +1. Heck, I learned many things about a language I'm now using on a daily basis by golfing Project Euler problems in it. It certainly is a great way of finding and trying out even the most obscure language features – not all of them lead to shorter results in all circumstances but you still know tricks you'd otherwise probably never encountered.
    – Joey
    Commented Jun 9, 2010 at 22:11
  • Another comment masquerading as an answer
    – Argalatyr
    Commented Dec 24, 2017 at 19:26
4

https://codegolf.stackexchange.com/ has been in public beta for 11 months.

3

In the game of golf, the player who completes the course with the fewest club strokes wins. Likewise, code golf is a competition to achieve the specifications in the fewest keystrokes. It's been popularized on SO and other programming fora, as well as in organized competitions.

3
  • Code golf has been around a long time, I first came across it ?10 years ago.
    – Richard
    Commented Oct 2, 2009 at 8:31
  • Yes, that's consistent with the link I provided, which was an organized competition 9 years ago.
    – Argalatyr
    Commented Oct 2, 2009 at 9:35
  • @Richard: It started way earlier even, with APL.
    – Joey
    Commented Jun 9, 2010 at 22:10
3

a complete waste of time and pixels - on SO [please people, leave this stuff on codegolf.com where it belongs; leave SO for useful questions]

6
  • 8
    @Steven, it can be useful for sharpening skills, personally I prefer these questions to "what is your favorite IDE color scheme"
    – waffles
    Commented Sep 7, 2009 at 23:07
  • 2
    While I agree that it is more useful than "what is your favorite IDE color scheme" I do not think that makes it useful for the site. If you want to sharpen your skills, go find someone's intractable problem and help them solve it.
    – AnonJr
    Commented Sep 7, 2009 at 23:19
  • 10
    why whine about it? It would take fewer keystrokes to add "code-golf" to you Ignored tags list than it did to write your mini-rant.
    – Argalatyr
    Commented Sep 7, 2009 at 23:21
  • 3
    @[Sam Saffron]: "what is your favorite IDE color scheme" I can close as not-programming-related - and I would; code-golf is technically a programming question so I can't in good faith vote to close it, but it is non-productive noise. @[Argalatry]: i forgot about ignored tags, i'll do that right away - but that does not alter the navel-gazing, bit-wasting, pixel-churning, pocket-pool nature of code-golf questions on SO :-P Commented Sep 8, 2009 at 1:33
  • @[Argalatyr]: ignored meta-code-golf as well, thanks again for the reminder! Commented Sep 8, 2009 at 1:35
  • 12
    "A waste of pixels". Never heard that one before. Are we running out? ;)
    – Rex M
    Commented Sep 8, 2009 at 2:53
3

Code golf is for those bored of helping people solve real problems, but don't want to leave the site.

As per my comment, while I agree that it is more useful than some of the questions floated (the aforementioned "what is your favorite IDE color scheme" comes to mind) I do not think that makes it useful for the site.

If you want to sharpen your skills, go find someone's intractable problem and help them solve it.

1
  • 4
    This looks very much like a comment, not an answer to the question.
    – Argalatyr
    Commented Sep 7, 2009 at 23:23
0

It's a puzzle-style problem, which is a classic playground for programmers. A puzzle-style problem relating to programming is like chocolate for your girlfriend...it's not even a question of whether it'll be wanted. :-)

0

Not the answer you're looking for? Browse other questions tagged .