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

8,686 questions
135 views

### Fibonacci with n numbers instead of 2 [duplicate]

How to Given an integer n start with n ones (i.e. 4 -> 1 1 1 1). Then sum up the last ...
726 views

### ASCII art H trees

An H tree is a fractal tree structure that starts with a line. In each iteration, T branches are added to all endpoints. In this challenge, you have to create an ASCII representation of every second H ...
219 views

### Special quines and code golf, hooray!

Make a quine. Simple enough, except it has to be a palindrome and accept input. Now, any side of a palindromic quine is one half of it. For example, one side of the hypothetical quine AAAA is AA. One ...
3k views

### How frustrating is my movie?

My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards ...
159 views

### Let's play Peg Solitaire

Peg solitaire is a popular game usually played alone. The game consists of some number of pegs and a board which is divided into a grid - usually the board is not rectangular but for this challenge we ...
331 views

### Create a kind of quine, such that the program prints one character of itself, then two, then three and so on

Create quine variant such that the program prints its first character, then the first two, then three and so on until the whole program is printed. Example Suppose your code is ...
1k views

### Nth subset of a set

The task Given the set $$S = \left[{1,2,3,4,5,6,7,8}\right]$$ and an integer $$0 \leq N < 2^{|S|}$$ find the Nth subset. Input/Output N is given as an unsigned integer on stdin. You must ...
2k views

### Densely packed decimal (DPD) to decimal

For nandgame fans: Please try out DPD to decimal in logic gates too! Background Densely packed decimal (DPD) is a way to efficiently store decimal digits in binary. It stores three decimal digits (...
877 views

### Find the best period in which to have invested in a S&P500 index fund

Here are the annual returns for a hypothetical S&P 500 stock index fund for each calendar year from 1928 to 2017, expressed as a multiplier. So in 1928 you might say "the index went up by 37.88%" ...
2k views

### Number of rotations

Task Write a function or a program to find the number of rotations required by a wheel to travel a given distance, given its radius. Rules Input can be 2 positive rational numbers and can be taken ...
683 views

### Kolmogorov Flexibility. A.K.A. Sale! $38\%$ Off All Codegolf While Stocks Last!

This is a restricted-source, kolmogorov-complexity, code-golf challenge to produce a fixed output with no input. The output format, however, is flexible - it may be printed to standard out, printed ...
492 views

### Simulate a Cisco Ping

Premise: For those in networking, you've most likely sent a ping to or from some device to make sure everything's properly connected. Cisco, a popular company in networking[citation needed], has a ...
195 views

### Finding the period of a recurring element in an array [closed]

Given an array A of integers, there exists at least one positive integer p such that A[i] == A[j] for all ...
3k views

### Arbitrary Randomness

Randomness is fun. Challenges with no point are fun. Write a function that, given integer input n, will output a set (unordered, unique) of exactly ...
396 views

### Is it an arithmetico-geometric sequence?

An arithmetico-geometric sequence is the elementwise product of an arithmetic sequence and a geometric sequence. For example, 1 -4 12 -32 is the product of the ...
5k views

### The Hungry Mouse

Sixteen piles of cheese are put on a 4x4 square. They're labeled from $1$ to $16$. The smallest pile is $1$ and the biggest one is $16$. The Hungry Mouse is so hungry that it always goes ...
96 views

### Tiny, Tiny “Hello, world!” - an adventure in small executables [duplicate]

The challenge: Print Hello, world!. Shortest executable wins. Criteria: Your program must compile into an ELF x86-64 executable that prints ...
261 views

### Compound interest with additions [closed]

You have been given the charge to calculate the current balance as of the day that you perform the calculation for 330,000 individuals who worked for an average of 30 years spanning 300 years where ...
3k views

### Is this number a hill number?

A hill number is a number that has the same digit in the first & the last, but that's not all. In a hill number the first digits are strictly increasing, and the last digits are strictly ...
412 views

### Splitting The Bill

Task Suppose that p pepole have to split a bill; each of them is identified by a triple (Name, n, k) made up of: ...
985 views

### Number of transformations until repeat

Given a sequence of integers or to be more specific a permutation of 0..N transform this sequence as following: output[x] = reverse(input[input[x]]) repeat For ...
1k views

### Drawing the Peano curve

Introduction In geometry, the Peano curve is the first example of a space-filling curve to be discovered, by Giuseppe Peano in 1890. Peano's curve is a surjective, continuous function from the unit ...
254 views

As with most APL symbols, has different meanings when called with one argument (transpose) versus two arguments (dyadic transpose / reorder dimensions). This ...
753 views

In mathematics, a cyclic quadrilateral is one whose vertices all lie on the same circle. In other words, every vertex is on the circumcircle of the other three. For more information, see the MathWorld ...
1k views

### Dirichlet Convolution

The Dirichlet convolution is a special kind of convolution that appears as a very useful tool in number theory. It operates on the set of arithmetic functions. Challenge Given two arithmetic ...
4k views

### Print all lexicographically increasing numbers under 10000

A lexicographically increasing number is an integer whose digits are in strictly increasing order. Print all lexicographically increasing numbers under 10000. Here are lines of the expected output: ...
260 views

### Unminify a Pythlike String

Pyth is perhaps the most successful general-purpose golfing language. Though it is somewhat in decline as a result of newer languages, from 2014 to 2016 Pyth's concise syntax, constant updates, ...
2k views

### Quaternion square root

Background Quaternion is a number system that extends complex numbers. A quaternion has the following form $$a + bi + cj + dk$$ where $a,b,c,d$ are real numbers and $i,j,k$ are three ...
148 views

### Number letter counts [closed]

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. Output how many letters would be used if all the numbers from ...
3k views

Challenge Calculate the strange sum of two natural numbers (also known as lunar addition): Given A=... a2 a1 a0 and ...
2k views

### Largest and Smallest Possible Number

Task Given an array of non-negative numbers, output the largest and smallest possible number that can be formed by joining them. Rules Input,Output can be in any convenient format. The array may ...
2k views

### Sort by Largest Digit(s)

Challenge: Given a list of integer, sort descending by their single largest digit(s). The order for numbers with the same largest digit are then sorted by second largest digit, etc. We ignore ...
1k views

### Hide the buildings

Shorter version of Skyscrapers Challenge Task Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the ...
2k views

### Upward and onward to greater glory!

May this challenge serve as (another) tribute to Stan Lee, who passed away aged 95. Stan Lee has left us an invaluable legacy and a peculiar catch word: Excelsior. So here's a small challenge based ...
214 views

### Alignment of a string

This is similar to the alignment used in word. Task 3 inputs: A 1 line string, a positive integer k, and direction (left or middle or right) Your job is to ...
252 views

### FreeChat Online [closed]

FreeChat Online It is 1985, and you are a humble Russian potato farmer. Sadly, your glorious homeland is going through a time of crisis and it needs your help! The KGB, with the "assistance" of your ...
474 views

### Calculate your Icy Tower Score

Do you know Icy Tower ? Here is a gameplay example of what i'm talking about The game concept is simple : you play as Harold the Homeboy, and your goal is to jump from floors to floors to go as high ...
11k views

### Tribute to Stan Lee

Unfortunately one of the greatest comic book writers passed away yesterday afternoon. Lots of Hollywood stars, musicians, actors, and many other people are paying tribute to this awesome writer, so we ...
886 views

### Terms of the EKG sequence

Introduction The EKG sequence begins with 1 and 2, then the rule is that the next term is the smallest positive integer not already in the sequence and whose common factor with the last term is ...
255 views

### Cut-Off The Matrix

Task Given is a square matrix of any dimension and any integer n. Output all possible matrices(without duplicates) by removing columns and rows from the input ...
2k views

### Reciprocal copycats

Let $A$ be a positive integer consisting of $n$ decimal digits $d_1,d_2,...,d_n$. Let $B$ be another positive integer. For the purpose of this challenge, we call $A$ a copycat of $B$ if ...
5k views

### Couch 2048: How much more till 2048?

I have just tried a game called Couch 2048. (Note: You should have a look to better understand this question.) Since it wasn't very exciting for me, I've been asking myself 'How much more till 2048!?' ...
172 views

### Should this identifier be suggested?

Introduction In Android Studio and other IDEs there are code completions to assist efficient code insertion (especially when the names of the classes or methods are so verbose), like the one in the ...
2k views

### All the single eights

Given a non-empty rectangular array of integers from 0 to 9, output the amount of cells that are ...
175 views

### Generate Matlab plot markers

Matlab has a useful command for visualizing data: plot. It draws data points using "markers" in 2-D space, connecting them with lines; however, for this challenge, ...
456 views

### Gold nugget storage

Given a positive integer, write it as the sum of numbers, where each of them is in $\{kt|k\in{1,9,81},t\in{1,2,3,...,64}\}$. How many numbers at least are used? Shortest code win. Samples: ...
122 views

### Doce logf a string swapper [closed]

Challenge Take an input string $s$, and split it into words $w_1, w_2, ..., w_n$. If the amount of words is odd, then return $s$. Otherwise, for each word: Take the second last letter, and swap ...
669 views

### Outline words with their letters

For the purposes of the current challenge to "outline" a word means to surround it successively with its own letters, starting with the last one, and finally to replace the original word in the center ...