Article complete

What Is Code Golfing And Biggest Such Tournaments

A person in a golf stance on a green, with a vibrant orange background and text about code golfing and tournaments.

Key takeaways

  • Code Golfing is a competitive programming game focusing on solving problems with the fewest characters.
  • Participants use various programming languages, including Python and JavaScript, to showcase their coding skills.
  • The game is free to play and features multiple challenges like Fizz Buzz and 99 Bottles of Beer.
  • Code Golfing serves as a playful environment for programmers to enhance their coding efficiency.

Takeaways drafted with AI from the article text.

Similar to the golf game, code golf is a competition where the winner achieves the specifications in the fewest keystrokes. It is basically a kind of recreational computer programming competition where the participants compete to achieve the shortest possible source code that implements a certain algorithm. 

Code Golfing can be said as a classic playground for programmers where the main attempt is to solve a problem with the least number of characters. It is written in Go language, licensed under MIT and is available on GitHub. 

Code Golf is free and supports various programming languages including Python, Haskell, JavaScript, Julia, Perl, Rust, Swift, Ruby and more. Currently, it provides a number of games including 12 days of Christmas, Abundant numbers, Fizz Buzz, 99 Bottles of Beer, Diamonds, Evil Numbers and much more. If you are playing for the first time, it has been suggested to start with a simple game, such as Fizz Buzz.

How Code Golfing Works

Below here, we listed general tips of Code Golf that are implemented in popular languages like 

Python and others.

  1. Conditional Statement:

Original- if a

     else:return b

Code Golf- return(b,a)[a

  1. AND Operators

Original- if a > 1 and b > 1 and 3 > a and 5 > b: foo()

Code Golf- if 3 > a > 1 < b < 5: foo()

  1. Multiple Statements

Original- while foo(a):

  print a;a*=2

Code Golf- while foo(a):print a;a*=2

  1. Replacing Append

Original- A.append(B)

Code Golf- A+=B,

  1. Ceil Value of a Real Number

Original- from math import ceil

   n = 3/2

   print(ceil(n))

Code Golf- n = 3/2

       print(-(-n//1))

How Does The Score Work?

The score of your solution is the count of the Unicode characters in your source code. This means both “A” (U+0041 Latin Capital Letter A) and “????” (U+1F609 Winking Face) cost the same despite the 1:4 ratio in byte count in UTF-8.

For each hole, the shortest solution is awarded 1,000 points, with the points decreasing in uniform decrements per rank. Your overall score is simply the sum of your points in each hole. Also, the execution time is limited to 5 seconds.

Pros and Cons of Code Golf

Pros

Code Golfing can be used for various purposes, such as-

  • Practising programming with the help of Code Golf
  • Sharpening skills in coding
  • Learning to optimise codes
  • Can be used as a learning tool and experience
  • To think something out of the box

Cons

  • The codes in Code Golf are often difficult to understand
  • Unlike usual programming codes, the codes of Code Golf are merely impossible to be modified.

Other Similar Tournaments

The International Obfuscated C Code Contest

The International Obfuscated C Code Contest (abbreviated IOCCC) is a computer programming contest for the most creatively obfuscated C code. In this contest, the programmers are asked to write the most obscure and obfuscated C program within the rules, stress C compilers with unusual code, etc. 

During the competition, the programmers usually write the smallest C compiler which is able to compile itself, avoid the commonly used constructs, avoid the C preprocessor and tricky statements such as "if", "for", "do", "while" and other such.  

Know more here.

js13kGames: Code golf for game devs

Js13kGames is an annual online JavaScript competition for HTML5 game developers that began in 2012. The annual js13kGames competition channels creativity by challenging aspiring game developers to create a game using just 13,312 bytes, zipped. 

Some of the tricks that the programmers use in this competition include inlining all images, concatenate images, minimising the JS codes, zipping the final entries, and other such. 

Know more here.

Published

Spotted an error? Tell our editors. Read our editorial standards and corrections.

Selling to AI teams? Put your brand in front of the 5M+ people who read AIM every month. Plan a campaign

More in this story

coding · 5 stories
  1. Understanding The Difference Between Data Architecture & Data Modeling
  2. You are here: What Is Code Golfing And Biggest Such Tournaments
  3. Top 10 Python Cheat Sheets
  4. Is India shifting to low-code/no-code platforms?
  5. Is coding necessary to work as a data scientist?
About the author

Contributor

A Technical Journalist who loves writing about Machine Learning and Artificial Intelligence. A lover of music, writing and learning something out of the box.

All stories
Belamy · Daily

The day’s AI news, before your first meeting.