Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

Filter by
Sorted by
Tagged with
11
votes
1answer
642 views

Write a compressing util for gzip files

The task of this challenge is as following: Write a program that reads a file of reasonable size (let's say <16 MB) from stdin or anywhere else (however you like, but must not be hardcoded), and ...
50
votes
27answers
13k views

Tips for golfing in C++

What general tips do you have for golfing in C++? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C++ (e.g. "remove comments" is not ...
32
votes
24answers
15k views

Morse code translator

Write the shortest program to transform the standard input into Morse code. Characters not in the table should be printed as they are.
-1
votes
1answer
4k views

Poisson random number generator [closed]

What is the shortest function (implemented in C) that will return a random draw from a Poisson distribution (given the mean or λ parameter)? ...
14
votes
2answers
3k views

Test if a given number is a Vampire Number

EDIT: In the interest of increasing the complexity, i've added more to the challenge. In mathematics, a vampire number (or true vampire number) is a composite natural number v, with an even ...
7
votes
5answers
810 views

Tree traversal.

Write the shortest code that traverses a tree, breadth-first. Input any way you like Output a list of "names" of the nodes in correct order.
27
votes
42answers
3k views

Sum of primes between given range

Write the shortest code for finding the sum of primes between a and b (inclusive). Input a ...
50
votes
41answers
15k views

Obfuscated FizzBuzz Golf [closed]

Create the shortest possible obfuscated FizzBuzz implementation. To be considered obfuscated, it should satisfy at least one of the following: Does not contain any of the words "Fizz", "Buzz", or "...
115
votes
239answers
27k views

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...
113
votes
52answers
16k views

Interpret brainf***

Write the shortest program in your favourite language to interpret a brainfuck program. The program is read from a file. Input and output are standard input and standard output. Cell size: 8bit ...
24
votes
38answers
3k views

Reimplementing square root [duplicate]

Define a function, s, which takes a number and returns the square root. No use of library functions, such as Java's Math.sqrt() or PHP's built in sqrt(), allowed.
204
votes
337answers
45k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
255
votes
145answers
81k views

Tips for golfing in Python

What general tips do you have for golfing in Python? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Python (e.g. "remove comments" is ...
36
votes
21answers
7k views

Angle between the hands on a clock [duplicate]

Given the time in 24 hour format (2359 = 11:59pm) return the angle between the minute and hour hands on a standard clock (on the ...
51
votes
45answers
6k views

The Luhn algorithm for verifying credit card numbers, etc

Challenge Write the shortest program or function to calculate the Luhn Algorithm for verifying (credit card) numbers. Luhn algorithm explained From RosettaCode, this algorithm for the purposes of ...
18
votes
9answers
3k views

Hamming numbers

Given a positive integer, print that many hamming numbers, in order. Rules: Input will be a positive integer \$n \le 1,000,000 \$ Output should be the first n terms of https://oeis.org/A051037 ...
34
votes
52answers
5k views

ROT-13 transform standard input

The challenge: To read an input of arbitrary length and produce the ROT13 of the input. All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible. ...
92
votes
103answers
14k views

Code Golf Christmas Edition: How to print out a Christmas tree of height N

Given a number N, how can I print out a Christmas tree of height N using the least number of code characters? ...