# 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.

9,385 questions
Filter by
Sorted by
Tagged with
3k views

### Length-terminated sequences

We all know the age-old debate - should strings be length-prefixed or should they be null-terminated? Well, you've run into a blob of binary data and apparently whoever made it decided that the best ...
3k views

### Implement the 2D Hadamard Transform

The Hadamard transform works similarly to the Fourier transform: it takes a vector and maps it to its frequency components, which are the Walsh functions. Instead of sine waves in the Fourier ...
476 views

### List where pinballs would exit a grid of bumpers from different entrance points

Inspired by this lumosity mini game, Pinball Recall We start with a rectangular grid (viewed from above) with several bumpers as follows. Entrances/exits are numbered counter-clockwise starting from ...
273 views

### Explore a Klarner-Rado sequence [duplicate]

One of the Klarner-Rado sequences is defined as follows: the first term is $1$ for all subsequent terms, the following rule applies: if $x$ is present, so are $2x+1$ and $3x+1$ the sequence ...
4k views

### Visualize a large int

Convert a large int (e. g. 1234567890) into a string containing the usual decimal prefixes k, M, G, T, etc. for kilo, mega, giga, tera, etc. The result shall be groups of three digits, interspersed ...
3k views

### Are my triangles similar?

Given (in any structure; flat list, two lists of lists, a tuple of matrices, a 3D array, complex numbers,…) the coordinates for two non-degenerate triangles ...
2k views

### Russian Caesar cipher

The objective Given a Russian text, encrypt it with Caesar cipher with key 16. The basic Cyrillic alphabets The basic Cyrillic alphabets are: (U+0410 – U+042F) ...
556 views

### Implement the named labels for assembly

Let's assume we've got an imaginary assembler. The assembler supports numerical labels. An infinite loop example: :1 jmp 1 Your task is, to write a ...
1k views

### Digit Date Range

NOTE: Since I'm Dutch myself, all dates are in the Dutch dd-MM-yyyy format in the challenge description and test cases. Challenge: Inputs: Start date $s$; End ...
226 views

### Tips for golfing in MathGolf

What general tips do you have for golfing in MathGolf? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to MathGolf (for tips which can be ...
509 views

### Typing, but to the left [closed]

Background You've been given a task to take notes for a meeting. You start typing on your Google Doc, but you don't have enough time during the meeting to look at your keyboard while you type. ...
151 views

### Make Korean Character Multi-style Ascii/Box Art

About Hangul As I'm Korean, I'm really proud of Korean character, Hangul(한글). Hangul is artificial character made by King Sejong the great, 4th king of Joseon dynasty, at 1443. Because today(...
2k views

### Fermat's polygonal number theorem

Fermat's polygonal number theorem states that every positive integer can be expressed as the sum of at most $n$ $n$-gonal numbers. This means that every positive integer can be expressed as the ...
5k views

### Code Golf Measurer © 2019

Code Golf Measurer © 2019 Hexdumps used with xxd look something like this: ...
313 views

### The null challenge: do nothing [closed]

Write the shortest possible program or function in your language that does nothing. Specifically, it must take no input or ignore its input, and must not produce any output in any legal output method ...
373 views

### North Korean dictionary order

The objective Given a string of Hangul syllables, sort the characters in North Korean dictionary order. Introduction to Hangul syllables Hangul(한글) is the Korean writing system invented by Sejong ...
2k views

### What's the current zodiac?

Display the emoji of the eastern zodiac of given time, according to given country. The eastern zodiac is a classification scheme that assigns an animal and its reputed attributes to each year in a ...
2k views

### Diamondize Some Text

Given an input string of length 2 or longer consisting solely of alphabetical characters [A-Z] or ...
240 views

### Is this skew symmetry?

In this challenge, your task is to detect (vertical) Skewer Symmetry. This means that one half of the pattern can be produced by mirroring the other half along a vertical axis, and then moving it ...
481 views

### C4_4 Reflection!

In this challenge, your task is to input a rectangle ASCII pattern (You may assume only printable characters need to be handled, and you may assume a trailing newline or not), C4_4 symmetrify, and ...
3k views

### Shortest way to get an EOF Error [closed]

It's simple, simply output text to STDERR containing the string EOF. Input/Output Your input will be none; however, you should output the message to STDERR. ...
49 views

Spreadsheet Columns In most spreadsheet programs, columns go A, B, C, ... ...
4k views

### Fill a bowl with alphabet soup

We seem to never get tired of alphabet-related challenges... The recipe Given a string of letters S, and two positive integers ...
404 views

### CUT OUT HEXAGONS

Write a full program or a function taking an unsigned integer number N and doing this cut out work: Cut out a hollow hexagon 'donut' shape with side B-C equal to 2N times '/' Translate the piece ...
982 views

### From Plate to State

This is essentially the inverse of Generate a US License Plate Challenge: Given a string that matches one of the below license plate formats, output all possible states that match that formatting. In ...
3k views

### Print the sequence

21, 21, 23, 20, 5, 25, 31, 24, ? Inspired by this Puzzle, given an integer $n>0$ , print out the following sequence until you reach a non-Integer (spoilered, in case you want to solve the puzzle ...
153 views

### Test the endianness

Given a UTF-16 string, test its endianness. Rules: As long as the input is in UTF-16 without BOM, its type doesn't matter. In C++ on Windows, it can be ...
3k views

### Little Endian Number to String Conversion

Introduction During work with BMP (bitmap) generator I face problem of converting number to little endian hex string. Here is function which I create in JavaScript - but wonder how small code can ...
320 views

### BLUEREDGOLDEGGSFEATHERSFEATHERS

There's a little-known secret in Banjo-Kazooie that you can interleave the three Cheato codes on the Treasure Trove Cove Sandcastle floor and it will still recognize all of them. So you could, for ...
2k views

### Postman Delivery

I just got a job as a postman and I need your help to keep it. I have to order a lot of mails before I go out to deliver them. Streets are numbered strictly sequentially, starting with 1 at the start ...
94 views

### Decode a UTF-8 string to character byte counts [duplicate]

Given a UTF-8 string, give a string that represents byte counts of each characters. Rules: As long as the input string is encoded in UTF-8 (without BOM), its type doesn't matter. In C++, it can be <...
3k views

### Find the percentage

We haven't had any nice, easy challenges in a while, so here we go. Given a list of integers each greater than $0$ and an index as input, output the percentage of the item at the given index of the ...
99 views

### Write a piece of code that prints out itself [duplicate]

I'm new to this site, so I don't know whether this challenge already appeared: Write a piece of source code, so that after running the code, it prints out exactly (i.e. not longer, not shorter) the ...
2k views

### Injection from two strings to one string

Challenge Write a program that applies an injective function which takes an ordered pair of strings as input and one string as output. In other words, each input must map to a unique output. ...
162 views

### Replace by most recent nonzero [duplicate]

Given a non-empty list of decimal digits (0, 1, ..., 9), replace each zero by the most ...
2k views

### Determine the Winner of a Game of Australian Football

In Australian Football, goals are worth 6 points and behinds are worth 1 point. Scores may include the number of goals and behinds, as well as the total score. Given the number of goals and behinds ...
563 views

### Split string using rules

Introduction Some time ago, I need to write function which split string in some specific way. At the first look, task looks trivial, but it was not so easy - especially when I want to decrease code ...
207 views

### A really inefficient calculator [closed]

Challenge: Add two numbers. In O(n^m) time, where n and m are the two numbers given. Sleeping, or your language equivalent, is not allowed. Input: Two integers, separated by a space. Output: The sum ...
746 views

### What is the score of my Scopa hand?

I like card game challenges so I made this one for the Italian card game Scopa. My family has been playing this game since time immemorial. It has a very interesting scoring system that should be fun ...
269 views

### Is this a valid Tichu play?

Tichu is a card game in which players take turn playing sets of cards from a deck consisting of a standard 52-card deck, plus 4 additional cards: the dragon, which has a greater value than any other ...
1k views

### Approximate the perfect fifth

Starting at 1-TET, give equal temperaments that have better and better approximation of the perfect fifth(just ratio 3/2). (OEIS sequence A060528) The formal description of the sequence, copied from ...
10k views

### Duck, duck, gone!

Here is the (quite scary) Five little ducks song(it is not long): ...
191 views

### Tips for golfing in Keg

What general tips do you have for golfing in Keg? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Keg (e.g. "remove comments" is not ...
219 views

### Tips for golfing in 1+

What general tips do you have for golfing in 1+? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to 1+ (e.g. "remove unnecessary ...
8k views

Sandbox French License Plates French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD Challenge Write ...
3k views

What is the Ultraradical The ultraradical, or the Bring radical, of a real number $a$ is defined as the only real root of the quintic equation $x^5+x+a=0$. Here we use $UR(\cdot)$ to denote ...
3k views

### Convert a string of digits from words to an integer

Convert a string containing digits as words into an integer, ignoring leading zeros. Examples "four two" -> 42. ...
6k views

### I transpose the source code, you transpose the input!

Rip-off of a rip-off of a rip-off of a rip-off. Go upvote those! Your task, if you wish to accept it, is to write a program/function that outputs/returns its input/argument¹. The tricky part is that ...