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.

16
votes
6answers
201 views

Non-overlapping Matrix Sum

Non-overlapping Matrix Sum Given k arrays of length n, output the maximum sum possible using one element from each array such that no two elements are from the same index. It is guaranteed that k<=...
7
votes
5answers
131 views

Approximate the proportion of integers with neighboring factors

If 1 is not counted as a factor, then 40 has two neighboring factors (4 and 5) 1092 has two neighboring factors (13 and 14) 350 does not have two neighboring factors (out of its factors 2, 5, 7, 10, ...
12
votes
7answers
491 views

Rotation invariant fingerprinting

Imagine we have some polyomino and would like to uniquely identify them, however the polyominos can be rotated, so blindly hashing them won't give us the same fingerprint for a piece and a rotation ...
13
votes
22answers
694 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 ...
14
votes
12answers
1k 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 ...
1
vote
0answers
55 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-...
26
votes
20answers
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 ...
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 ...
18
votes
2answers
327 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 ...
21
votes
38answers
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: ...
6
votes
1answer
208 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
287 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: ...
14
votes
7answers
982 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 ...
4
votes
5answers
241 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 ...
0
votes
3answers
136 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 & ...
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 ...
15
votes
4answers
348 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: ...
14
votes
6answers
963 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 ...
-2
votes
1answer
78 views

Regex only base64 decoder [closed]

Write a regular expression substitution string which can base64 decode a string using only a regular expression engine built into the language. Eg: ...
18
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 ...
-2
votes
0answers
89 views

Sum of 2D Array Elements [closed]

The Challenge: Consider the below series: n^(i+4) , n^(i+3) , n^(i+2) , n^(i+1) , n^(i) where, i>=0 && i<=27, and, n>=2 && n<=10 Now, the ...
11
votes
2answers
273 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 ...
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 ...
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: ...
19
votes
7answers
485 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 ...
16
votes
6answers
474 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
52 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 ...
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 ...
29
votes
24answers
5k 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
368 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 ...
20
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
122 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 ...
3
votes
2answers
206 views

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

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

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

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 ...
8
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
417 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 ...
14
votes
12answers
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 ...
7
votes
1answer
296 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
2k 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
241 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
488 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
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 ...
12
votes
10answers
1k 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
843 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 ...