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.

383
votes
723answers
111k 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 ...
30
votes
67answers
7k views

How many arguments were passed?

Using your language of choice, write a function that takes a variable number of arguments and returns the number of arguments it was called with. Specifics: Your language needs to support variadic ...
19
votes
4answers
580 views

Pentomino 6x10 solution normalizer

As you most probably now, there are 2339 solutions to pentomino puzzle in a 6x10 grid. There are different labeling schemes for the 12 pentominoes, two of them are shown on the image below: Image ...
9
votes
5answers
529 views

Tips for golfing in Lisp

What general tips are these for golfing in Lisp (any dialect)? Please post one tip per answer, and only answers that are specific to a dialect of Lisp (e.g. "remove comments" is not an answer). ...
24
votes
19answers
2k views

Convert to Suzhou numerals

Suzhou numerals (蘇州碼子; also 花碼) are Chinese decimal numerals: 0 〇 1 〡 一 2 〢 二 3 〣 三 4 〤 5 〥 6 〦 7 〧 8 〨 9 〩 They pretty much work like Arabic numerals, except ...
181
votes
297answers
38k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
14
votes
18answers
3k views

How much candy can you eat?

Credit to Geobits in TNB for the idea A post without sufficient detail recently posited an interesting game: 2 children sit in front of an array of candy. Each piece of candy is numbered 1 to ...
4
votes
73answers
3k views

Summation from a to b

The program has an input of a and b, and outputs the sum of numbers from a to b, inclusive. Score is in bytes. As always, standard loopholes are disallowed. If your input is in the format [a,b], +3 ...
10
votes
11answers
855 views

How many syllables in that number?

I'd love to take a number and know how many syllables are in it, when spoken in English. Let's limit this to positive integers which are less than one thousand. I'm British, so we're going to follow ...
7
votes
12answers
235 views

Standardize the Samples (Compute the z-Score)

Given a list of floating point numbers, standardize it. Details A list \$x_1,x_2,\ldots,x_n\$ is standardized if the mean of all values is 0, and the standard deviation is 1. One way to compute this ...
52
votes
72answers
6k views

Test a number for narcissism

A Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits. For example, take 153 (3 digits): 13 + 53 + 33 = 1 + 125 + 27 = 153 1634: ...
25
votes
22answers
2k views

Find the first word starting with each letter

Given a string, find the first word starting with each letter (case insensitive). Sample Using Ferulas flourish in gorgeous gardens. as input: ...
37
votes
40answers
3k views

Is it a balanced number?

A number is balanced if the sum of the digits on each half of the number is equal, so: 1423 is balanced because 1+4 = 2+3, so is:...
68
votes
158answers
13k views

Find the Factorial!

Create the shortest program or function that finds the factorial of a non-negative. The factorial, represented with ! is defined as such $$n!:=\begin{cases}1 &...
136
votes
338answers
24k views

Implement a Truth-Machine

A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does: Gets a ...
22
votes
25answers
2k views

First they came

"First they came..." is a poem by Martin Niemöller: ...
13
votes
11answers
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 ...
9
votes
80answers
2k views

What's the file extension?

Your challenge is to find the file extension of a provided filename: ...
53
votes
180answers
18k views

Is this even or odd?

Note: There is not been a vanilla parity test challenge yet (There is a C/C++ one but that disallows the ability to use languages other than C/C++, and other non-vanilla ones are mostly closed too), ...
20
votes
23answers
1k views

Find the BCD difference of a number

BCD difference Given an integer n, convert it to BCD (binary-coded decimal) by replacing each decimal digit with its 4-digit binary representation ...
29
votes
15answers
1k views

Fill in an increasing sequence with as many numbers as possible

A list of numbers is called monotonically increasing (or nondecreasing) is every element is greater than or equal to the element before it. For example, ...
15
votes
4answers
339 views

Code Golf: Letter-Ception

The Challenge: For an input of one letter X (upper or lower case from A to Z) and one digit N (0-9) print the corresponding letter X made of N * X. The letter has to be from this list: ...
29
votes
58answers
10k views

What's my middle name?

Note: The winning answer will be selected on 4/12/17 the current winner is Jolf, 1 byte. I'm surprised that we haven't had a what's my middle name challenge on this site yet. I did alot of searching ...
21
votes
37answers
3k views

Draw some expanding arrows

This challenge is about printing a series of growing ASCII-art arrows. I'll describe the pattern in words, but it might be easier to look at what the start of this series looks like: ...
14
votes
28answers
2k views

The inverse Collatz Conjecture

I think the Collatz Conjecture is already well-known. But what if we invert the rules? Start with an integer n >= 1. Repeat the following steps: If n is even, multiply it by 3 and add 1. If n is ...
26
votes
10answers
1k views

Optimal Alphabet Stepping

Given an input string consisting of only letters, return the step-size that results in the minimum amount of steps that are needed to visit all the letters in order over a wrapping alphabet, starting ...
10
votes
13answers
342 views

Dot Product of Diagonals

This challenge is very simple. You are given as input a square matrix, represented in any sane way, and you have to output the dot product of the diagonals of the matrix. The diagonals in specific ...
18
votes
2answers
285 views

A spiral sequence

Background OEIS sequence A272573 describes a spiral on a hexagonal grid as follows: Start a spiral of numbers on a hexagonal tiling, with the initial hexagon as a(1) = 1. a(n) is the smallest ...
61
votes
47answers
10k views

My daughter's alphabet

The other day we were writing sentences with my daughter with a fridge magnet letter. While we were able to make some(I love cat), we didn't have enough letters to ...
24
votes
4answers
532 views

Hexagonal adjacency

The above image displays a hexagonal grid of hexagons. Each cell in the grid is assigned an index, starting from the center and spiraling counterclockwise around as shown. Note that the grid will ...
35
votes
33answers
3k views

Hollow out an array

The task This challenge is very simple. Your input is a rectangular 2D array of integers, sized at least 1×1. It can be taken in any reasonable format. Your output shall be the input array, but ...
1
vote
0answers
49 views

Sino-Korean numerals [duplicate]

The Korean language has two sets of numerals, a native Korean numerals and Sino-Korean numerals. The native Korean numerals are mostly used for numbers under 100, such as age and time. The Sino-...
15
votes
29answers
4k 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 ...
14
votes
6answers
939 views

Fill the Bucket

Your task is to fill the bucket with numbers upto a given input. Rules Numbers occupy the leftmost position then rightmost, then leftmost and so on. After overflow, the numbers start to gather ...
0
votes
3answers
130 views

Round the digits last digit, over and over

Challenge: Given two inputs, x and y, round x to one less significant figure, then repeat until it has y number of unrounded digits left. (the decimal point does not count as a digit) Input & ...
31
votes
62answers
5k 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 ...
6
votes
0answers
163 views

Hilbertize an image

For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows: Given square 2D image <...
3
votes
17answers
281 views

Print coordinates of an NxN grid [duplicate]

Question: Print out all the coordinates of a NxN grid. Preferably in C, however other languages also accepted Input: N (integer) Output: for N=3, a 3x3 grid: ...
75
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 ...
31
votes
43answers
4k views

The leading zeroes challenge

The challenge Given two integers as input (x and y), output x as a string with as many ...
17
votes
13answers
1k views

Trifid Cipher (without keyword)

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 ...
11
votes
3answers
418 views

Linear combination of two vectors

Executive summary Given input representing two vectors and their respective "weights", produce output that also represents the weighted sum of those vectors. Challenge The input will consist of one ...
15
votes
38answers
1k 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: ...
4
votes
5answers
233 views

Seconds to human readable format

Given a positive integer input n seconds, output the time in human readable format. The time will be considered from 00:00:00, 1st January, 1 A.D. Leap years must ...
14
votes
9answers
2k views

Tips for golfing in Clean

What general tips do you have for golfing in Clean? Please post only ideas that can be applied to code golf problems in general, and are at least somewhat specific to Clean. If you've never heard of ...
11
votes
2answers
270 views

Golf Paterson's Worms

Paterson's worms are a kind of cellular automaton that exist on an infinite triangular grid and, every step, they turn in some direction and move one unit. Their defining properties are that they can ...
19
votes
38answers
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 ...
230
votes
136answers
67k views

Tips for golfing in Python

What general tips do you have for golfing in Python? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Python (e.g. "remove comments" is ...
13
votes
7answers
953 views

Iron particles around a magnet

There are some iron particles on a board. We pass a current carrying wire through that board and the particles form circles. Show these circles if input given is the position of the wire. Consider ...
27
votes
29answers
5k views

Output an Anagram! No Not That One!

Given a list of unique strings that are anagrams of each other, output an anagram of those words that is different from each word in the list. The strings will be alphanumeric, and there is ...