Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

24
votes
14answers
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 ...
8
votes
2answers
140 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 ...
3
votes
14answers
305 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 ...
12
votes
29answers
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 ...
24
votes
11answers
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 (...
8
votes
8answers
874 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%" ...
7
votes
31answers
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 ...
11
votes
10answers
611 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 ...
6
votes
10answers
477 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 ...
1
vote
9answers
189 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 ...
26
votes
24answers
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 ...
11
votes
3answers
390 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 ...
74
votes
19answers
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 ...
0
votes
0answers
90 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 ...
-4
votes
1answer
248 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 ...
17
votes
19answers
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 ...
12
votes
1answer
404 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: ...
12
votes
9answers
981 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 ...
13
votes
9answers
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 ...
9
votes
1answer
241 views

Dyadic Transpose

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

Is this quadrilateral cyclic?

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 ...
19
votes
13answers
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 ...
31
votes
42answers
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: ...
12
votes
3answers
252 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, ...
12
votes
11answers
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 ...
0
votes
2answers
144 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 ...
19
votes
27answers
3k views

Strange Addition

Challenge Calculate the strange sum of two natural numbers (also known as lunar addition): Given A=... a2 a1 a0 and ...
16
votes
10answers
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 ...
23
votes
25answers
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 ...
15
votes
9answers
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 ...
15
votes
30answers
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 ...
4
votes
2answers
209 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 ...
-3
votes
3answers
245 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 ...
6
votes
4answers
377 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 ...
38
votes
21answers
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 ...
10
votes
9answers
875 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 ...
6
votes
3answers
250 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 ...
17
votes
10answers
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 ...
19
votes
27answers
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!?' ...
8
votes
2answers
170 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 ...
21
votes
15answers
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 ...
5
votes
3answers
155 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, ...
6
votes
5answers
449 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: ...
-2
votes
3answers
119 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 ...
14
votes
8answers
655 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 ...
7
votes
5answers
362 views

9erilous 9ermutations

Note: This is an attempt at recycling guest271314's permutation question(s) There's an interesting pattern that forms when you find the differences between lexographically sorted permutations of base ...
16
votes
40answers
2k views

Multiplicity Test

Use any programming language to display numbers between 1 and 99 (including both) in such a way, so that: the numbers are separated by single space, if a number is divisible by 3, it should be in ...
7
votes
4answers
171 views

Dina's Paintings

Dina loves most numbers. In fact, she loves every number that is not a multiple of n (she really hates the number n). For her friends’ birthdays this year, Dina has decided to draw each of them a ...
20
votes
8answers
1k views

Draw this diamond pattern

The below pattern will form the basis of this challenge. ...
10
votes
9answers
1k views

Through Space and Time

Introduction: In general we usually speak of four dimensions: three space dimensions for x, y, and ...