Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
11 votes
22 answers
2k views

Generate the Crystal Maze™ time matrix

Behold! The Crystal Maze™ Time Matrix! ...
AJFaraday's user avatar
  • 11.7k
1 vote
1 answer
154 views

Start a program so that /proc/self/cmdline contains a binary representation of the input number

I am sorry for the very long description. But i think some information of how /proc/self/cmdline works and how it can be used to get a integer input was necessary. ...
12431234123412341234123's user avatar
11 votes
11 answers
1k views

(Robbers) Fast and Golfiest Season 1: The Lord of the Strings

Fast and Golfiest Robbers Thread Welcome to the first season of Fast and Golfiest, a cops-and-robbers challenge! I designed this challenge to encourage competitive coding for efficiency (fastest ...
Shiran Yuan's user avatar
17 votes
15 answers
1k views

(Cops) Fast and Golfiest Season 1: The Lord of the Strings

Fast and Golfiest Cops Thread Welcome to the first season of Fast and Golfiest, a cops-and-robbers challenge! I designed this challenge to encourage competitive coding for efficiency (fastest ...
Shiran Yuan's user avatar
23 votes
15 answers
3k views

Code Golf for Golf

My first code golf question post! Hope u like it ;-) The task is simple. Write either an stdin-stdout program or a function. Input is a 2D array which contains only either characters or the integer <...
Shiran Yuan's user avatar
19 votes
10 answers
3k views

Numbers that can be negated by reading backwards

Balanced ternary is a modified version of ternary (base 3), using the three digits 1,0 and -1...
bsoelch's user avatar
  • 4,781
19 votes
41 answers
1k views

Output / Convert to unary number

Your task is it to output a number as a unary string. You get the number of a non-negative integer input in the range of 0 - 2'000'000'000. Rules You can choose any character for the digit you like. ...
12431234123412341234123's user avatar
1 vote
7 answers
471 views

Relations between interval and semitones

Output this table: -2* -1* - 0 - 1 2 -1* 0 1 - 2 3 4 1 2 3 - 4 5 6 3 4 - 5 - 6 7 5 6 - 7 - 8 9 6 7 8 - 9 10 11 8 9 10 - 11 12 13 10 11 - 12 - 13 14 You can output one string with two types of ...
l4m2's user avatar
  • 19.1k
21 votes
16 answers
2k views

Chamber of Reflection

Background A ray of light is fired from the top left vertex of an MxN Chamber, where M a denotes the width and ...
Jacob Creutzfeldt's user avatar
24 votes
37 answers
2k views

Diagonalize a vector

Diagonalize a vector into a matrix. Input A vector, list, array, etc. of integers \$\mathbf{v}\$ of length \$n\$. Output A \$n \times n\$ matrix, 2D array, etc. \$A\$ such that for each element \$a_i \...
bigyihsuan's user avatar
  • 8,258
0 votes
1 answer
74 views

Find the sum of primes [duplicate]

Given a number x, find the sum of all primes up to that number. The input will always be a positive number, bigger than 2. An upper limit isn't defined, so data types can be ignored. Use whichever you ...
S-Flavius's user avatar
  • 459
9 votes
13 answers
982 views

Landmine Number V

Background You have again x4 been given the task of calculating the number of landmines in a field. But this time, the field is not a number field... it's a field of letters. Our landmine letter ...
Jacob Creutzfeldt's user avatar
7 votes
1 answer
239 views

Reverse Conway's Game of Life

Conway's Game of Life is a cellular automaton "played" on an infinite grid, filled with cells that are either alive or dead. Once given an initial state, the board evolves indefinitely ...
c--'s user avatar
  • 2,393
10 votes
13 answers
1k views

Landmine Number IV

Background You have again x3 been given the task of calculating the number of landmines in a field. But this time, we have no landmine number, and some landmines have exploded. You must calculate the ...
Jacob Creutzfeldt's user avatar
14 votes
19 answers
2k views

Vanilla Natural Logarithm Challenge

There is a challenge for multiplying two numbers so I guess this counts too Given as input a positive real number n compute its natural logarithm. Your answer ...
mousetail's user avatar
  • 11.4k
6 votes
6 answers
957 views

Critical Calculations

Background In the game stick ranger, there is an item which grants the character the ability to get critical hits. Each time a projectile hits an enemy, it has some probability to be a critical hit (...
CursorCoercer's user avatar
22 votes
40 answers
3k views

Sum of a range of a sum of a range of a sum of a range of a sum of a range of a sum of

Inspired by the fact that a few related challenges to this could be answered by Vyxal in 0 Bytes using a special flag combination. Given only one input integer \$n\$, calculate \$f(n,n)\$ where $$ f(x,...
The Empty String Photographer's user avatar
11 votes
14 answers
2k views

Landmine Number III

Background You have again, again been given the task of calculating the number of landmines in a field. But this time, the field is foggy. You must calculate the landmine score given a list/string of ...
Jacob Creutzfeldt's user avatar
11 votes
6 answers
691 views

Compute the maximal Ducci period

Given an initial \$n\$-tuple \$t_0=(t_{0,1},...,t_{0,n})\$, we can obtain its corresponding Ducci sequence \$\{t_0, t_1, ...\}\$ by the recurrence \$\displaystyle t_{i+1}=\left(\left|t_{i,1}-t_{i,2}\...
att's user avatar
  • 19.4k
13 votes
11 answers
2k views

Measure the Diamond Road

Background You are planning your trip away from the Diamond City, and must travel through Diamond Road. However, Diamond Road branches away from Diamond City to different locations. Out of curiosity, ...
Jacob Creutzfeldt's user avatar
10 votes
13 answers
2k views

Landmine Number II

Background You have again been given the task of calculating the number of landmines in a field. However, we have now travelled into the flatlands. You must calculate the landmine score given a list/...
Jacob Creutzfeldt's user avatar
13 votes
26 answers
2k views

Landmine Number I

Background You have been given the task of calculating the number of landmines in a field. You must calculate the landmine score given a list/string of numbers and the landmine number. The landmine ...
Jacob Creutzfeldt's user avatar
13 votes
8 answers
686 views

Generate all linked chains

A followup to this challenge by Jeremy Collprav, inspired by DLosc solving this in Regenerate. Some sections copied from the linked challenge. Linking chains We define a chain to be a string ...
caird coinheringaahin g's user avatar
14 votes
15 answers
1k views

Two Parallel Linked Chains

Background We define the two types of chain to be a string that contains only dashes, "-", or only underscores, "_". We link two chains using one equals sign, "=". ...
Jacob Creutzfeldt's user avatar
12 votes
17 answers
2k views

Draw the initial positions of Mölkky pins in ASCII art

Write a function (or a whole program) that outputs (or prints) an ASCII art of the initial position of Mölkky pins. Output : ...
Fhuvi's user avatar
  • 1,458
21 votes
32 answers
2k views

Reversed Squares

Given an integer n, your task is to determine whether it is a perfect square that when reversed, is still a perfect square. You may assume n is always positive. When numbers such as 100 (10x10) are ...
Alan Bagel's user avatar
  • 3,445
10 votes
5 answers
848 views

Translate the keitai input method

The keitai input method is a method for writing Japanese kana on a 12-key phone keypad. Similar to Western keypads, each kana is assigned to a key; when the key is pressed multiple times, it cycles ...
bigyihsuan's user avatar
  • 8,258
6 votes
6 answers
714 views

Detect Maxima Using Persistent Homology

Inspired by this SO answer about peak detection. Background Persistent homology is a fancy term for a fancy math concept, but in this case all we care about is how it can be used for peak detection. ...
CursorCoercer's user avatar
23 votes
43 answers
3k views

Output each second

With roughly one second (plus or minus 10 ms) between outputs, output anything. The first output must be at most one second after the start of the program, but can be as soon as right when the program ...
Dadsdy's user avatar
  • 1,995
8 votes
5 answers
1k views

Approximate e using small numbers

Given an input integer from 1, 2, ..., n, the task to write code to make a number as close as possible (as measured by absolute distance) to e using only the four ...
Simd's user avatar
  • 1,547
8 votes
6 answers
218 views

Minimum partition with non-empty intersections

Given a set of intervals \$\mathcal{I} = \{I_1, \ldots, I_m\}\$, where each interval \$I_j\$ is represented by its bounds \$(a_j, b_j)\$, find a partition \$\mathcal{T}\$ of \$\mathcal{I}\$ of minimal ...
matteo_c's user avatar
  • 5,593
16 votes
17 answers
2k views

XOR of independent Bernoulli variables

In probability theory, a Bernoulli variable is a random variable which has a single parameter \$p\$, and is equal to 1 with probability \$p\$, and 0 with probability \$1-p\$. In this challenge, there ...
Command Master's user avatar
-8 votes
9 answers
294 views

Wrt "Hello World" prgrm bt wth n vwls

Create A "Hello, World!" program but without any vowels. Winner is the program with the least bytes. Rules: No vowels are allowed in the code. Must print to STDOUT Must be a full program. ...
Wallace's user avatar
  • 125
4 votes
4 answers
198 views

Tips for golfing in (,) in-paren-comma

What tips do you have for golfing in (,)? I've found that there are so many ways to make code shorter, and I want more ways. I doubt there even are any tips for (,) that are applicable in the majority ...
Dadsdy's user avatar
  • 1,995
25 votes
15 answers
2k views

Vertices of a regular dodecahedron

A regular dodecahedron is one of the five Platonic solids. It has 12 pentagonal faces, 20 vertices, and 30 edges. Your task is to output the vertex coordinates of a regular dodecahedron. The size, ...
alephalpha's user avatar
  • 45.6k
43 votes
37 answers
3k views

Last odd digit of power of 2

Task Given \$n\$, output position of the last odd digit in the decimal representation of \$2^n\$ (counting from the end). Rules There are no odd digits for \$n=1,2,3,6,11\$ \$(2, 4, 8, 64, 2048)\$ - ...
pajonk's user avatar
  • 14.9k
23 votes
28 answers
1k views

Lowest digit addition generator

A digit addition generator of an integer n is any integer x that satisfy the equation ...
Tom Epsilon's user avatar
14 votes
5 answers
2k views

Sudoku as a SAT problem

Background An interesting way to solve a Sudoku puzzle is to represent it as a Boolean satisfiability problem, and then feed it to a SAT solver. A Boolean Satisfiability Problem (abbreviated as SAT ...
alephalpha's user avatar
  • 45.6k
5 votes
4 answers
201 views

Tips for golfing in Arturo

Arturo is a bytecode-compiled/interpreted, garbage-collected general-purpose language filling a role similar to JavaScript, Python and Ruby. It is centered around the concept of blocks, which hold ...
chunes's user avatar
  • 21k
8 votes
5 answers
2k views

What is the shortest regex for the month of January in a handful of the world's languages?

What is the shortest regular expression equivilant to the following? ...
Samuel Muldoon's user avatar
18 votes
3 answers
2k views

Render text in a slanted ASCII-art font

Given a text input such as: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG render the following output: ...
Timwi's user avatar
  • 12.9k
19 votes
24 answers
2k views

Split a string on unnested commas

Create the shortest program/function/whatever that splits an inputted string along un-nested commas. A comma is considered nested if it is either within parentheses, brackets, or braces. Input and ...
Dadsdy's user avatar
  • 1,995
12 votes
2 answers
981 views

Can Bitshift Variations in C Minor be compressed down to less than 185 characters?

Bitshift Variations in C Minor by Robert Miles is a Code Golf music piece written in C (with some additional bash commands). It was originally presented in a 2016 Computerphile video Code Golf & ...
brubsby's user avatar
  • 243
17 votes
4 answers
647 views

Complete the landscape

Carcassonne is a tile-based game, where the objective is to construct Roads, Cities and Monasteries, in order to score points. The game works by players taking turns to draw and place tiles to ...
caird coinheringaahin g's user avatar
5 votes
2 answers
281 views

My eight braille pattern progressive snake spinner

Introduction I would like to drawn a nice spinner by using eight braille patterns on two lines, drawing a square of 8x8 pixel, for showing a kind of snake growing and reducing: ...
F. Hauri  - Give Up GitHub's user avatar
13 votes
10 answers
1k views

Adjacent Items Sorting

Given a list, L, of sets of numbers like this: [[1], [0,2,3], [3,1], [1,2,3]] Output a single list of numbers such that 2 ...
mousetail's user avatar
  • 11.4k
10 votes
40 answers
2k views

Output endless powers of 2 [duplicate]

In any programming language, make a program that outputs infinite subsequent powers of two, starting at any power of two with finite integer exponent. There does not need to be a seperator between ...
Dadsdy's user avatar
  • 1,995
19 votes
19 answers
2k views

Logarithmic Incrementation

In this challenge you will write a function that takes a list (ordered set) containing real numbers (the empty list is an exception, as it has nothing) and calculates $$f(x)=\begin{cases}1 & \text{...
The Empty String Photographer's user avatar
14 votes
13 answers
1k views

Resultant of two polynomials

The resultant of two polynomials is a polynomial in their coefficients that is zero if and only if \$p\$ and \$q\$ have a common root. It is a useful tool for eliminating variables from systems of ...
alephalpha's user avatar
  • 45.6k
5 votes
3 answers
319 views

Valid python function invocation signatures

Background In Python, function arguments are defined within the parentheses following the function name in the function definition. There are different ways to present function arguments, and they can ...
Mardoxx's user avatar
  • 181