Questions tagged [code-golf]
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
11,173
questions
3
votes
0
answers
42
views
Build a file/directory tree
Task
In this challenge, your task is to write a program or function which takes an array of paths with an additional boolean indicating it is a file or directory and outputs a file/directory tree in ...
12
votes
4
answers
267
views
Golf Github's Pager Logic
Background
When searches return many pages of results, Github avoids cluttering their UI by eliding page links. Instead, their UI let's you select:
Pages at the beginning of the results.
Pages near ...
12
votes
29
answers
642
views
Erverse Hte Ifrst Wto Eltters fo Aech Owrd
Inspired by this accidental misspelling
If you could read the title, then you already know what the challenge is about. If not, then I'll tell you. Easy: simply take each word (single space delimited)...
15
votes
2
answers
1k
views
Draw the USA flag
I noticed that it seems nobody has posted a non-ASCII (related) USA flag challenge yet, so what better time than the 4th of July?
The Challenge
Draw the current (as of 2022) flag of the United States ...
0
votes
0
answers
116
views
Output your Code Golf submission from Try It Online
When using Try It Online, there is an option to copy a Code Golf submission:
Using a language currently on Try It Online, your task is to output the exact submission copied to your clipboard from ...
2
votes
0
answers
40
views
Bijective Function (mapping integer to arbitrarily large integer tuple) [duplicate]
Find a bijective function which maps integers to arbitrarily large tuples of integers. Given the input \$n\$, output the tuple it matches to.
Edit: The empty tuple is included in the mapping.
7
votes
11
answers
474
views
Get multi-dimensional indices in a list
Given a matrix of non-negative numbers (of arbitrary dimension) and a number, get all multi-dimensional indices of the number in that list.
For example, let's say we have the list ...
6
votes
6
answers
564
views
Is it an ordinal?
Background (feel free to skip)
Ordinals are the abstract representation of well-orders. A well-order of a set is a total order, which basically means that every element in the set can be compared ...
12
votes
13
answers
805
views
Implement Binary Exponentiation
Background
In programming, there is a recursive algorithm called binary exponentiation, which allows for large integer powers to be calculated in a faster way. Given a non-zero base \$x\$ and a non-...
16
votes
6
answers
641
views
Draw this fractal generated by applying Newton's method to cosh(x) - 1
I came across this picture the other day: (Credit to Josep M Batlle I Ferrer)
Your job is to generate this picture. This graph is generated by repeatedly applying newton's method to the graph of:
$$f(...
14
votes
13
answers
759
views
Number of binary partitions
We all know that any positive integer can be represented as the sum of powers of two. This is how binary representations work. However there's not just one way to do this. The canonical method, ...
15
votes
11
answers
777
views
Word stays a word after taking away a letter
This is a repost of this challenge
Challenge
There is an old, popular riddle:
Find an English word with 8 letters that, taken away one letter, creates a new valid word. Repeat that until there are ...
21
votes
21
answers
927
views
Pairs at every distance
Given a list \$X\$ of 2 or more integers, output whether, for all \$n\$ such that \$0 \leq n < length(X)-2\$, there exists a pair of equal integers in \$X\$ separated by exactly \$n\$ elements.
In ...
9
votes
4
answers
409
views
Draw the Progress Pride flag
Challenge
Create the image of a progress pride flag.
Output
Dimensions
Rules
Your program must create the image and not just load it from a website
The colours can be just your language's default ...
12
votes
13
answers
1k
views
Bloons TD 6 Upgrade Paths
Background
The monkeys need help organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options. Each tower has three unique ...
13
votes
15
answers
1k
views
Weighted coin flip strings
Given n, k, and p, find the probability that a weighted coin with probability p of heads will flip heads at least k times in a row in n flips, correct to 3 decimal digits after decimal point (changed ...
9
votes
7
answers
402
views
Collect data on mushroom forests
In these previous challenges[1][2] I've been dealing with "mushroom forests". To help with these I draw little diagrams of the forests to help. In this challenge we are going to reverse ...
-4
votes
0
answers
81
views
No A, just CAPS LOCK... but even more annoying [closed]
Inspired by: No A, just CAPS LOCK.
The question is currently in Sandbox.
My keyboard doesn't have a caps lock key. It's... switching between Chinese and English.
What happens when the CapsLock key on ...
9
votes
1
answer
279
views
Which R version is it? It's Peanuts!
This challenge will be based on an R language trivia: every release is named and it's a reference to Peanuts comic strips (see here and here).
Task
Given a release name, output its number.
For ...
21
votes
59
answers
3k
views
Print the ASCII Code page
Goal
You have to print the ASCII printable characters' code page (0x20-0x7E).
The output should look like this:
...
8
votes
5
answers
898
views
Is it shuffled FizzBuzz?
A twin of this.
FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with &...
19
votes
20
answers
1k
views
Decipher a squashed sequence
Given a string containing a sequence of ascending consecutive positive integers, but with no separators (such as 7891011), output a list of the separated integers. ...
15
votes
3
answers
299
views
Help me design an unfair laundry machine
There's a payment machine for laundry in my building which does a few frustrating things. The ones relevant to this challenge are:
It doesn't make change. So if you pay over the amount then you are ...
11
votes
5
answers
334
views
Nest some addition
Lambda calculus is a system of computation based on single-argument functions; everything in it is such a function. Due to this functional nature, juxtaposition is commonly used to denote function ...
25
votes
7
answers
3k
views
Fix my FizzBuzz
FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with "FizzBuzz&...
11
votes
10
answers
1k
views
Compress Jelly's code page
In this challenge, you'll print out the SBCS of Jelly, a popular golfing language. Its code page looks like this:
_0
_1
_2
_3
_4
_5
_6
_7
_8
_9
_A
_B
_C
_D
_E
_F
0_
...
13
votes
4
answers
406
views
Not-Roman-Numeral Addition
Write the shortest program or function that mimics the addition in this XKCD strip:
Input
Two positive decimal integers containing only the digits 150.
Output
The ...
32
votes
26
answers
5k
views
Doing a little trolling with the microwave timer
Related
Sometimes when I use my microwave, I do a little trolling and enter times such as 2:90 instead of 3:30 because they end ...
13
votes
1
answer
180
views
Is this a strange pond?
In this challenge we considered a frog hopping around a lily pond. To recap the lily pond was represented as a finite list of positive integers. The frog can only jump forward or backwards by a ...
3
votes
0
answers
59
views
Extract the word containing this index [duplicate]
For this challenge, a word is defined as a string of letters, separated by spaces.
Given a string of words, and an integer i representing an index into that string, ...
18
votes
15
answers
2k
views
Fibonacci polynomials
The Fibonacci polynomials are a polynomial sequence defined as:
\$F_0(x) = 0\$
\$F_1(x) = 1\$
\$F_n(x) = x F_{n-1}(x) + F_{n-2}(x)\$
The first few Fibonacci polynomials are:
\$F_0(x) = 0\$
\$F_1(x) ...
17
votes
9
answers
1k
views
ro1000an nu1000era50 en100o501ng
In the hovertext of this xkcd:
There's an "encoding" based on replacing runs of roman numerals with their sums. To do this:
Find all runs of at least 1 roman numeral (...
15
votes
10
answers
1k
views
Flood fill by distance
Say I have a grid with some obstacles:
----
| X |
| |
|XX |
| |
----
I can fill this with numbers, as distance from the top left corner. But, because ...
18
votes
16
answers
2k
views
Check a mushroom forest
In this challenge you will receive a list of pairs of non-negative integers representing a mushroom forest. Each pair represents a mushroom whose center is at that horizontal coordinate. The only ...
14
votes
2
answers
2k
views
Can `a?b<c:b>c` be shortened in Javascript?
So I have the situation where I have one boolean value a and, if that one is true and b<c ...
19
votes
23
answers
2k
views
The Unaverageables
Related.
Given a list of 3 or more positive integers, remove every number X for which there is another number Y in the list and the average of X and Y is also in the list. In other words, if X, Y, and ...
15
votes
22
answers
948
views
Iterative Smallest Complement
For this challenge, we will define the "complement" of a list of integers A as being any list B such that the union of ...
21
votes
9
answers
2k
views
How tall are the mushrooms?
In this challenge you will receive a list of non-negative integers. Each one represents a mushroom with a cap of that radius centered at that location. So a 0 ...
22
votes
25
answers
3k
views
How far from binary?
Given a decimal integer n as input, output the smallest (in terms of absolute value) decimal integer m such that the absolute ...
15
votes
12
answers
2k
views
Find the walls!
This is a simpler variant of my previous challenge Don't touch the walls!, as suggested by Jonah.
Given a multi-dimensional rectangular array of integers between 0 and 9, output all the elements ...
1
vote
10
answers
330
views
Divide by an odd number, 2-adically
Given \$a\$ and \$b\$, both odd \$n+1\$-bit integers, compute \$a/b\$ to a precision of \$n+1\$ bits in the 2-adic integers. That is, compute \$c\$ such that \$a = bc\, (\mathop{\rm mod} 2^{n+1})\$. \$...
24
votes
24
answers
3k
views
backwardS_hybriD-snakE_kebaB-cameL_case
There are a bunch of different casing conventions, like camelCase, PascalCase, snake_case ...
21
votes
16
answers
2k
views
Create Bernard from Desmos
Background
In the online graphing calculator Desmos, there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed &...
20
votes
4
answers
1k
views
Gray coded Gray code convertor
To increase data safety at our company, we are planning to start using Gray code numbers (where successive values differ by only one bit) instead of classical binary ones.
Please help us to make a ...
17
votes
11
answers
1k
views
Extend a matrix in all directions
Given a multidimensional, rectangular array and a list of dimensions, such as:
[ [1, 2],
[3, 4] ]
[3, 4]
Your challenge is to extend the matrix to the ...
18
votes
26
answers
1k
views
Truncate words in a sentence
Inspired by wezl.
Your challenge is to take words (sequences of [a-zA-Z]) and truncate them to length 3. For example, ...
13
votes
4
answers
257
views
Is it a heapable sequence?
A binary max heap is a rooted tree with integer labeled nodes such that:
No node has more than 2 children.
The label of every node is greater than all of its children.
We say a sequence of integers ...
17
votes
13
answers
998
views
Enumerate all pure sets
In set theory, a set is an unordered group of unique elements. A pure set is either the empty set \$\{\}\$ or a set containing only pure sets, like \$\{\{\},\{\{\}\}\}\$.
Your challenge is to write a ...
18
votes
25
answers
2k
views
Is it a valid list?
Given a string like [[[],[[]]],[]], made of only commas and square brackets, your challenge is to determine whether it represents a list.
A list is either:
...
18
votes
10
answers
1k
views
Position from atomic number in the periodic table
Let us consider the following representation of the periodic table.
...