Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
81
votes
140answers
13k views

Print a Tabula Recta!

Print a Tabula Recta! The Tabula Recta (sometimes called a 'Vigenere Table'), was created by Johannes Trithemius, and has been used in several ciphers, including all variants of Bellaso's Vigenere ...
81
votes
11answers
18k views

Regex, Paper, Scissors, Lizard, Spock

Warm up: Regex, Paper, Scissors This is the challenge I originally wanted to post, before realising that some very short solution exist. Nevertheless, it can be an interesting problem to think about ...
80
votes
53answers
27k views

Shortest code that raises a SIGSEGV

Write the shortest code that raises a Segmentation Fault (SIGSEGV) in any programming language.
80
votes
50answers
13k views

Detect MS Windows

Challenge Create a program that returns a truthy value when run on Microsoft Windows (for simplicity we'll stick with Windows 7, 8.1 and 10) and a falsey value when run on any other operating system (...
80
votes
131answers
23k views

The shortest code to invert bit-wise a binary string

Me thinks there aren't enough easy questions on here that beginners can attempt! The challenge: Given a random input string of 1's and 0's such as: ...
80
votes
35answers
10k views

Implement Sleep Sort

Sleep Sort is an integer sorting algorithm I found on the Internet. It opens an output stream, and for each input numbers in parallel, delay for the number seconds and output that number. Because of ...
80
votes
16answers
4k views

Defeat SVGCaptcha

I came across SVGCaptcha, and immediately knew it was a bad idea. I would like you to show just how bad an idea this is by extracting the validation code from the SVG images that code produces. An ...
79
votes
39answers
26k views

Leak Memory in as few bytes as possible

Your task is to write code that will leak at least one byte of memory in as few bytes as possible. The memory must be leaked not just allocated. Leaked memory is memory that the program allocates ...
79
votes
44answers
7k views

Telescopic Parentheses

Consider a non-empty string of correctly balanced parentheses: (()(()())()((())))(()) We can imagine that each pair of parentheses represents a ring in a ...
79
votes
25answers
7k views

print “Hello, World!”

Yes, really. Print it with a hardware printer 🖨 to create a hard copy. Send the necessary commands/data to your printer such that the following text is printed on a piece of paper: Hello, World! ...
78
votes
101answers
13k views

Hello World 0.0!

source: Dilbert, September 8, 1992 I'm hoping to add a new twist on the classic "Hello World!" program. Code a program that outputs Hello World! without: String/...
77
votes
24answers
14k views

Shortest code to throw SIGILL

Background We already have a challenge about throwing SIGSEGV, so why not a challenge about throwing SIGILL? What is SIGILL? SIGILL is the signal for an illegal instruction at the processor, which ...
77
votes
75answers
15k views

It was just a bug

Inspired by the bugged output in @Carcigenicate's Clojure answer for the Print this diamond challenge. Print this exact text: ...
77
votes
60answers
6k views

From Programming Puzzles to Code Golf

Your task is to write a program that outputs the exact string Programming Puzzles (trailing newline optional), but when all spaces, tabs, and newlines are removed ...
77
votes
88answers
13k views

Print this diamond

This question has been spreading like a virus in my office. There are quite a variety of approaches: Print the following: ...
77
votes
5answers
6k views

Recognise Stack Exchange Sites by Their Icon

After spending a while on Stack Exchange, I can recognise most sites in the Hot Network Questions by their little icon (which is also their favicon), but certainly not all of them. Let's write a ...
76
votes
51answers
12k views

Tips for golfing in Haskell

What general tips do you have for golfing in Haskell? I am looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Haskell. Please post only one ...
76
votes
183answers
16k views

Find the Factorial!

Create the shortest program or function that finds the factorial of a non-negative integer. The factorial, represented with ! is defined as such $$n!:=\begin{...
76
votes
68answers
20k views

Shortest program that throws StackOverflow Error [closed]

Write a program that throws a StackOverflow Error or the equivalent in the language used. For example, in java, the program should throw java.lang.StackOverflowError...
76
votes
89answers
11k views

Count of “a”s and “b”s must be equal. Did you get it computer?

In the popular (and essential) computer science book, An Introduction to Formal Languages and Automata by Peter Linz, the following formal language is frequently stated: mainly because this language ...
76
votes
40answers
10k views

Cops and Robbers: Reverse Regex Golf

Note: This challenge is now closed. Any future cops' submission will not be considered for the accepted answer. This is to ensure that no one can post a very simple regex in the future that only ...
76
votes
30answers
12k views

Create an “H” from smaller “H”s

Challenge Create a function or program that, when given an integer size, does the following: If size is equal to 1, output <...
76
votes
6answers
33k views

Hard code golf: Regex for divisibility by 7

Matthias Goergens has a 25,604-character (down from the original 63,993-character) regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution (...
76
votes
15answers
3k views

Progruzzle & Colf

Ever fancied creating cool twitter hashtags such as #brexit or #brangelina? this golf is for you. Write a program that accepts two strings A & B as input and merges them according to the ...
75
votes
37answers
12k views

Non-discriminating Programming

We say a string is non-discriminating if each of the string's characters appears the same number of times and at least twice. Examples "aa!1 1 !a !1" is non-...
75
votes
45answers
13k views

Code Johnny Code, Code!

Rock-and-roll founding father Chuck Berry sadly passed away today. Consider the chorus of his famous song "Johnny B. Goode": ...
75
votes
16answers
15k views

Build a Faulty XKCD Browser

Challenge Given the number of an XKCD comic, output the title text of that comic (the mouseover text). However, the program must throw an error when given the numbers ...
75
votes
11answers
13k views

How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

This is a tips question for golfing in Python concerning the Evil Numbers question on Anarchy Golf. An number is evil if its binary expansion has an even number of 1's. The challenge is to print the ...
74
votes
149answers
17k views

“99 Bottles of Beer”

Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible. Lyrics: ...
74
votes
70answers
8k views

Print some JSON

This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it: You need to print/return a valid JSON object of at least 15 characters, not counting unessential ...
74
votes
41answers
10k views

Fibonacci + Fizz Buzz = Fibo Nacci!

Fibonacci + FizzBuzz = Fibo Nacci! Your challenge is to create a Fibo Nacci program! A Fibo Nacci program outputs the first 100 Fibonacci numbers (starting from 1). If the Fibonacci number is ...
74
votes
39answers
6k views

Stack Exchange Vote Simulator

Write a program or function that takes in a string only containing the characters ^ and v (you can assume there will be no other ...
74
votes
22answers
8k views

Turtles All the Way Down

Write a program or function that takes in a positive integer and prints or returns a stack of that many ASCII-art turtles, where each turtle is larger than the one above it. Specifically, if the ...
74
votes
11answers
5k views

Error 404: Character Not Found

Scenario One of your friends is struggling on a homework assignment. He needs a simple program which prints the first 404 natural numbers: ...
74
votes
11answers
11k views

The 9 Billion Names of God

The 9 Billion Names of God is a short story by Arthur C. Clarke. It's about a group of Tibetan monks whose order is devoted to writing down all the possible names of God, written in their own alphabet....
74
votes
13answers
4k views

Friar simulator

The brethren from the order of St Golfus the Concise have a tradition of reciting a short prayer whenever they see someone make the sign of the cross. Due to the high level of sin measured among ...
73
votes
86answers
17k views

Build me a brick wall!

Challenge I need help building a brick wall! Throw together some code for me using no input and produce the following output wall shown below: ...
73
votes
64answers
17k views

Sing Baby Shark

"Baby Shark" is a children's song about a family of sharks. Having long been popular as a campfire song, it has been popularized since the mid-2000s by social media, online video and radio. - ...
73
votes
28answers
6k views

Calculate Phi (not Pi)

No, I don't mean ϕ = 1.618... and π = 3.14159.... I mean the functions. φ(x) is the number of integers less than or equal to <...
73
votes
63answers
14k views

Is this relationship creepy?

According to this XKCD comic, there is a formula to determine whether or not the age gap in a relationship is "creepy". This formula is defined as: (Age/2) + 7 ...
73
votes
18answers
4k views

Golf Dennis a thermometer

Dennis puts in a huge amount of effort for this community, including as moderator, language designer, and provider of TIO. Unfortunately, his four-year-old daughter has caught a cold, so let us all ...
72
votes
179answers
19k views

The Letter A without A

Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of ...
72
votes
117answers
15k views

Print the alphabet without using each vowel

Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'. Your task is to write a set of (up to 5) programs in any language (which has a text-...
72
votes
40answers
8k views

Happy Birthday V!

Thanks to @KritixiLithos for helping me out with this challenge! V is a programming language that I wrote so that I could use and extend vim for code-golf challenges. The very first commit was on ...
72
votes
38answers
12k views

Am I a Rude Number?

For a while now, I've been running into a problem when counting on my fingers, specifically, that I can only count to ten. My solution to that problem has been to count in binary on my fingers, ...
72
votes
36answers
4k views

Uncollapse digits

Task Given a string of English names of digits “collapsed” together, like this: zeronineoneoneeighttwoseventhreesixfourtwofive Split the string back into digits:...
72
votes
17answers
11k views

Two lasers between two mirrors

What if we have a corridor comprised of two parallel mirrors? ...
71
votes
190answers
13k views

Count up forever

Write a program that counts up forever, starting from one. Rules: Your program must log to STDOUT or an acceptable alternative, if ...
71
votes
50answers
7k views

Score rock-paper-scissors

Given two string inputs of "Rock", "Paper", or "Scissors", determine the outcome of the RPS round. Output 1 if the first player wins, -1 if the second player wins, or 0 for a tie. ...
71
votes
16answers
17k views

Draw the ☣ (Biohazard Symbol)

Draw the Biohazard symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the US Government. ...