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.

0
votes
2answers
15 views

Find the number of leading zeroes in a 64-bit integer

Problem: Find the number of leading zeroes in a 64-bit signed integer Rules: The input cannot be treated as string; it can be anything where math and bitwise operations drive the algorithm The ...
10
votes
26answers
350 views

String rotation - output string repeatedly moving first character to the end

The challenge here is to take a string and output all its rotations, by repeatedly moving the first character to the end, once per character in the string, ending with the original string: ...
15
votes
4answers
318 views

Doubled-letter steganography

Steganography hides a given message inside a given carrier, producing a package that does not look suspicious. For this challenge, you will write a program that takes an ASCII message and an ASCII ...
15
votes
5answers
306 views

Satisfying Rounding

Satisfying Rounding You know when you're in science class, and asked to round to 2 sig figs, but your answer is 5.2501...? You should round to ...
1
vote
0answers
44 views

Bracket checking [duplicate]

Consider a string like: a.push(c.push("a",["ad","bd",2,{"ard",duo}]).pop().replace(2,"tg").enc([3,{2,adf},"atr"],5) Write a program that will verify whether a ...
20
votes
48answers
2k views

P Pr Pre Pref Prefi Prefix Prefixe Prefixes

Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length. (Basically implementing the Haskell function ...
29
votes
22answers
4k views

Number that can eat itself

Given a positive integer, output a truthy/falsy value as to whether the number can eat itself. Rules Leftmost is the head, rightmost is the tail If the head is greater than or equal to the tail, ...
9
votes
9answers
329 views

Map the cheaters!

After all assignments are submitted, a dictionary is created that maps student number to the hash of their file. This dictionary, or hashmap, or mapping (whatever your language calls it) will look as ...
18
votes
6answers
2k views

Walk Across a Keyboard

Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you ...
-3
votes
6answers
116 views

Measuring Mountains [duplicate]

Sum-It is a language I created (quite late) for the Language Design Contest in TNB, for which the theme was "Range". Naturally I interpreted this as "Mountain Range" and created a language about ...
1
vote
0answers
93 views

Algorithm to print the Minimum number of adjacent character swaps necessary to remove all instances of “VK” in a given string? [on hold]

For example, how many adjacent swaps are at least needed to convert some string such as bvvkcv to one without any instances of ...
2
votes
0answers
118 views

Find what a phrase with removed letters originally said in fewest characters [on hold]

Write a program that, given a string of capital letters, output all possible phrases that could have been written originally, using any variant of the Oxford English Dictionary. Input There are two ...
7
votes
11answers
2k views

Color of a Pixel

Write a program that prints the RGB color of a given pixel on the screen. The program should read a line from stdin in the format x,y, where x and y are unsigned ...
9
votes
1answer
395 views

Golf a number bigger than Loader's number

As a follow up to Shortest terminating program whose output size exceeds Graham's number and Golf a number bigger than TREE(3), I present a new challenge. Loader's number is a very large number, ...
19
votes
24answers
2k views

Digital Sumorial

Given an input n, write a program or function that outputs/returns the sum of the digital sums of n for all the bases 1 to ...
11
votes
10answers
2k views

Computer Cipher

Introduction: I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too ...
-5
votes
1answer
130 views

Diagonal of a cube [closed]

Given the measurement of the edge of a cube, output the 3D diagonal measurement of it. Valid input and output formats are all the usual ones. There will be no winner answer as it by language code ...
6
votes
1answer
288 views

Fully Modular C: Grading

You are a Computer Science professor teaching the C programming language. One principle you seek to impart to the students is modularity. Unfortunately, past classes have tended not to get the message,...
18
votes
26answers
1k views

Make a simple word wrapper

(Note: This is my first ever code golf question, but as far as I can tell, nobody else has done exactly this, so I should be good.) Your task is to make a program or function that takes in a string <...
12
votes
5answers
237 views

Conjugation in Real Life

In @Adám's Dyalog APL Extended, the (under) operator means conjugation: apply one function, then a second function, then the inverse of the first. It's fun to ...
21
votes
14answers
2k views

Prime containment numbers (golf edition)

This is sequence A054261. The \$n\$th prime containment number is the lowest number which contains the first \$n\$ prime numbers as substrings. For example, the number \$235\$ is the lowest number ...
-5
votes
18answers
465 views

Print a square!

Print this text: _________ | | | | | | |_________| Shortest code wins. Notice the space at the start of the first line.
21
votes
17answers
2k views

Split Mark's marks

Challenge Mark is a student who receives his N marks in a concatenated way in a one single line. The challenge is to separate his marks, knowing that each mark ...
13
votes
26answers
1k views

Self-contained powers

Given integer n, output the smallest exponent e greater than 1 such that n^e contains ...
13
votes
20answers
1k views

Number in Number-squared

Consider a sequence of natural numbers for which N appears as a substring in N^2. A018834 Output the nth element of this sequence. Rules Program takes only ...
19
votes
36answers
2k views

Given an input, print all exponents where the base and power sum to the input

So this is my first challenge on this site. What this challenge is is that you input a number, and your code spits out numbers which can be calculated as an exponent. The sum of the exponent and base ...
12
votes
10answers
995 views

Convert an Excel date code to a “date”

Given a non-negative integer Excel-style date code, return the corresponding "date" in any reasonable form that clearly shows year, month, and "day". Trivial, you may think. Did you notice the "scare ...
18
votes
9answers
1k views

Partitioning the grid into triangles

Goal The goal of this challenge is to produce a function of n which computes the number of ways to partition the n X 1 grid ...
15
votes
7answers
828 views

Lazy word problems

Summary A teacher was told to prepare word problems for the students. She is given a list of equations and told to write them as the corresponding word problem. However, she is very lazy, so she ...
0
votes
0answers
88 views

Count the score of a Code Golf code [duplicate]

My challenge is to make a Java method(s) that is given a String (another code in Java), removes any unnecessary characters, counts and returns the score, and displays the cleaned-up code in a way that ...
15
votes
5answers
1k views

How many moves?

Given two different positions on a chess board and the type of piece, output the minimum number of moves it will take for that piece to go from one position to another. Rules The given piece can be ...
15
votes
15answers
1k views

Weight of the Least Weighted RoD Path

Let A be an m by n rectangular matrix of positive integers, where ...
5
votes
5answers
127 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 ...
9
votes
4answers
658 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 ...
3
votes
2answers
185 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 ...
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
139 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
302 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
872 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
605 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
474 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
389 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 ...
73
votes
18answers
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 ...