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
78
votes
196answers
20k 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 ...
30
votes
3answers
1k views

Write a C++ demangler

If you have ever looked at an objdump of a C++ program, you have likely seen something like this: _ZN3foo3bar3bazI6sampleEE3quxvi3foo This is a C++ mangled symbol, ...
19
votes
14answers
2k views

Largest Number with No Repeating Digit Pairs

Inspired by the problem with the same name on Puzzling SE by our very own Dmitry Kamenetsky. You are to find the largest number that only uses every digit pair once, in a given base. For example, in ...
44
votes
26answers
8k views

Random point on a sphere

The Challenge Write a program or function that takes no input and outputs a 3-dimensional vector of length \$1\$ in a theoretically uniform random direction. This is equivalent to a random point on ...
47
votes
43answers
20k views

Outputting ordinal numbers (1st, 2nd, 3rd)

I would like to generate (as a return result of a function, or simply as the output of a program) the ordinal suffix of a positive integer concatenated to the number. Samples: ...
10
votes
6answers
175 views

Side to side, not up and down

Task Given a list of nodes representing a binary tree of positive integers serialized depth-first, return a list of nodes representing the same tree serialized breadth-first. To represent an absent ...
6
votes
6answers
222 views

US Tax Due Dates

Introduction In a standard* (e.g. not 2020) tax year, estimated payments are due quarterly according to the schedule outlined in Publication 505. Payment Period Due Date January 1 – March 31 April ...
30
votes
24answers
3k views

Implement the Zundoko Kiyoshi function

Background The Zundoko Kiyoshi function originates from this tweet by kumiromilk. Translated from Japanese, it reads roughly as follows: The test for my Java lecture had a problem that said "...
33
votes
42answers
5k views

Simple ASCII Gantt

This is a simple one: print an ASCII Gantt chart. Given tasks' ranges (start-time - end-time Tuples), print a Gantt timeline in the form of - characters for each ...
5
votes
15answers
3k views

Print the Flag of the Arab Revolt!

It seems flags are a trend now, so what better place to start an account? I thought bars could use a twist to them, so I found this flag. Produce the following in the console output the fewest ...
12
votes
8answers
1k views

Generate a British numberplate

Modern British number plates (a.k.a. registration marks or license plates) use the format AANNXXX where AA is a "DVLA ...
16
votes
33answers
2k views

Antiferromagnetic ordering

Antiferromagnetism is what IBM researchers used to jump from a 1 terabyte disk to a 100 terabyte disk in the same amount of atoms. In materials that exhibit antiferromagnetism, the magnetic moments ...
25
votes
7answers
434 views

Convert Chevrons to Soliduses

Write a program that takes in a string containing only spaces, newlines, and angle brackets: <, > (chevrons). Output a ...
27
votes
20answers
2k views

Is there a single straight line in the matrix?

Inspired by Wzl Determine if a given square binary matrix has exactly one row or column consisting of entirely 1s, and the rest of the matrix is ...
12
votes
2answers
179 views

Counting uniquely solvable polylinks

Related: Counting polystrips Background Link-a-Pix is a puzzle on a rectangular grid, where the objective is to reveal the hidden pixel art by the following rules: Connect two cells with number N ...
25
votes
22answers
4k views

Draw an ASCII Checkerboard

Summary Inspired by the recent popularity of ASCII art challenges, this challenge's purpose is to draw an ASCII checkerboard, like one on which Chess can be played. Write a program that takes a ...
17
votes
37answers
2k views

My Squiggly Lamp

While moving, I broke my lamp. Now, I need a new one. It's your job to make me a lamp! I'm not sure what size I want, though I know I want a squiggly one. Your program/function must take in a number ...
25
votes
30answers
2k views

Log Scales are for Quitters

Everyone knows log scales are for quitters. Therefore, you must write a program or function that de-quitifies a bar graph with a log scale given a base. The bar graph input is taken as a single string ...
17
votes
7answers
2k views

But, Is It Art?

But Is It Art? is an esolang created by ais523, where one step is break the program into orthogonally connected "tiles": A BBBB A B B AA CC A CC Each ...
19
votes
4answers
1k views

X Marks the Spot

X Marks the spot Your goal is to add a cross-hair around the capital X: Example Input / Output Input: ...
16
votes
5answers
2k views

ASCII Art Archery Arrows

Write a program or function that takes in a positive integer and prints or returns an ASCII art depiction of an archery arrow, scaled according to the input. If the input is ...
28
votes
34answers
2k views

Horizontal graph of word length

Input A list of words separated by any number of spaces. Output A horizontal ASCII art graph, where the n-th line is composed by as many asterisks (*) as the n-...
10
votes
9answers
2k views

Have you mooed today?

The Debian Linux distribution (and Debian-based distros, like Ubuntu, Kali and others) uses a package-manager called APT. To install program foo you would type into ...
84
votes
161answers
19k views

“99 Bottles of Beer”

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

Random Capitalization

The Task Your task is to create a program or a function that, given an input, outputs the input text with random letters capitalized, while keeping already capitalized letters capitalized. Every ...
31
votes
20answers
3k views

Looks prime to me!

Figuring out whether a given number is prime, while not very complicated, is kind of hard. But making a guess doesn't need to be. Seeing whether a number is a multiple of 2 or 5 is easy - you can just ...
273
votes
68answers
74k views

We're no strangers to code golf, you know the rules, and so do I

Write the shortest program that prints the entire lyrics of "Never Gonna Give You Up" by Rick Astley. Rules: Must output the lyrics exactly as they appear in the above pastebin*. Here's the raw dump:...
472
votes
848answers
155k views

“Hello, World!”

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
29
votes
21answers
6k views

Divide Numbers by 0

We've all been told at some point in our lives that dividing by 0 is impossible. And for the most part, that statement is true. But what if there was a way to perform the forbidden operation? Welcome ...
14
votes
16answers
651 views

Square chunk my matrix

Your challenge is to write a function/program that takes a matrix of integers m and a number n as input and: Splits m into n by n chunks Replaces each chunk with the most common value in that chunk (...
7
votes
4answers
607 views

Ordinary Least Squares Regression

I am quite surprised that a variant of linear regression has been proposed for a challenge, whereas an estimation via ordinary least squares regression has not, despite the fact the this is arguably ...
34
votes
6answers
2k views

Zzub Zzif (reverse Fizz Buzz)

Given a snippet of fizz buzz output with all numbers removed, fill in the correct numbers with the lowest possible values such that the fizz buzz snippet is correct. For the purposes of this ...
26
votes
21answers
1k views

Consecutive Distance Rating

We'll call the consecutive distance rating of an integer sequence the sum of the distances between consecutive integers. Consider 2 9 3 6 8 1. ...
25
votes
12answers
2k views

Collatz's ice cream cone factory

The Collatz sequence Given a positive integer \$a_1\$, the Collatz sequence with starting value \$a_1\$ is defined as \begin{equation} a_{n+1} = \begin{cases} a_n/2 & \mathrm{if}\ a_n\ \mathrm{is}\...
5
votes
29answers
2k views

Base-2 integer logarithm of 64-bit unsigned integer

Problem: In your choice of language, write the shortest function that returns the floor of the base-2 logarithm of an unsigned 64-bit integer, or –1 if passed a 0. (Note: This means the return type ...
34
votes
30answers
3k views

Print a tongue twister!

The goal of this challenge is to print the following tongue twister: ...
8
votes
20answers
689 views

Trapezoidal Riemann Sum

Given a list of coordinate pairs, output the Trapezoidal Riemann Sum of the values given between the first and last x-coordinates. You will be given a sorted list of coordinate pairs, like this: ...
92
votes
293answers
19k views

Simple cat program

One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after ...
26
votes
32answers
2k views

Mr. Binary Counterman

Mr. Binary Counterman, son of Mr. Boolean Masker & Mrs. Even Oddify, follows in his parents’ footsteps and has a peculiar way of keeping track of the digits. When given a list of booleans, he ...
14
votes
16answers
2k views

Implement a FuzzyFinder

Inspired by this link I found on Reddit. A FuzzyFinder is a feature of many text editors. As you start to type a file path S, the FuzzyFinder kicks in and shows ...
47
votes
94answers
6k views

StringgnirtSStringgnirtSStringgnirtS

Here is a relatively simple challenge for you. Given a string of length N, output the string forwards, then backwards, then forwards, then backwards... etc. N times. For example, if your input was <...
153
votes
89answers
53k views

Tips for golfing in JavaScript

What general tips do you have for golfing in JavaScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to JavaScript (e.g. "remove ...
35
votes
45answers
6k views

Guess my password (cops' thread)

Inspired by this challenge, which got closed. This is meant to be an easier, but no less interesting version of that. This is the cops thread of a cops-and-robbers challenge. For the robbers thread, ...
29
votes
66answers
5k views

Count the divisors of a number

Introduction This is a very simple challenge: simply count the divisors of a number. We've had a similar but more complicated challenge before, but I'm intending this one to be entry-level. The ...
17
votes
8answers
1k views

Generalised multi-dimensional chess knight's moves

Multi-dimensional chess is an extension of normal chess that is played on an 8x8x8x8... "board". In normal 2D chess, a knight's move is a movement by a vector of \$ \begin{bmatrix} \pm 2 \\ \...
105
votes
77answers
35k views

Shortest code that raises a SIGSEGV

Write the shortest code that raises a Segmentation Fault (SIGSEGV) in any programming language.
0
votes
0answers
65 views

Make a Webcrawler dictionary writer [closed]

Notice: for any text within <> tags, please ignore any .'s. These are simply added so that they are treated as plain text, and not code. Your goal is to make a program that acts as a regular ...
40
votes
30answers
4k views

Tips for golfing in x86/x64 machine code

I noticed that there's no such question, so here it is: Do you have general tips for golfing in x86/x64 machine code? If the tip only applies to a certain environment or calling convention, please ...
105
votes
342answers
25k views

Print a 10 by 10 grid of asterisks

Background This is a standard textbook example to demonstrate for loops. This is one of the first programs I learnt when I started learning programming ~10 years ago. Task You are to print this exact ...
22
votes
42answers
2k views

Output a Latin Square

An \$n\times n\$ Latin Square is a grid containing exactly \$n\$ distinct values where the values in each row and column are distinct. For example, $$\begin{matrix} A & B & C \\ C & A &...

1
2 3 4 5
209