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
9 votes
14 answers
496 views

It's Just Rocket Science

Write a program/function that finds the amount of fuel needed to escape Earth's gravity well given the exhaust velocity of the fuel and the amount of mass to transport using the Tsiolkovsky rocket ...
  • 239
12 votes
7 answers
371 views

Create a nibble shorthand

I recently stumbled across this image on wikimedia commons. It's a little bit of an information overload at first, but after examining it a bit it shows an interesting number system for writing ...
  • 90.1k
16 votes
11 answers
1k views

Carryless factors

Carryless multiplication is an operation similar to binary long multiplication, but with XOR instead of addition: ...
25 votes
14 answers
3k views

Print every Fool's Mate

In chess, the Fool's Mate is the fastest possible way to reach checkmate. It is reached with Black's second move. In chess notation, one possible sequence of moves that achieves Fool's Mate is ...
  • 717
-2 votes
0 answers
129 views

How many undisrupted rectangles are there in the given figure? [closed]

Your function/program will receive an image as input and has to calculate the amount of rectangles within that image. Only a rectangle that is completely clean in the inside, meaning no other strokes ...
  • 477
11 votes
18 answers
462 views

Count the number of compositions of \$n\$ in which the greatest part is odd

A composition of an integer \$n\$ is a representation of \$n\$ as a sum of positive integers. For example the eight compositions of 4 are as follows: ...
  • 1,091
8 votes
9 answers
1k views

Selective Caesar Cipher

Input A string of text. Output The string of text, however, every consonant is the next consonant in the alphabet, and every vowel is the next vowel in the alphabet (z becomes b, u becomes a). The ...
-5 votes
0 answers
94 views

Gargantuan Collatz numbers: write a function f(x) that outputs the Collatz orbit of x + 10^(1500) - 3^(1499) and gives status updates as it computes

Foreword This is my first prompt submitted to Code Golf. If you have any suggestions on how to make the prompt more interesting, please let me know. This was a problem that I recently had to solve, ...
20 votes
12 answers
2k views

Reconstruct Matrix from its diagonals

Given the diagonals of a matrix, reconstruct the original matrix. The diagonals parallel to the major diagonal (the main diagonals) will be given. Diagonals: ...
  • 4,871
-9 votes
7 answers
260 views

Write "tut-tut-tut" without using "tut"

Following this question: Tut-tut-tut-tut-tut Write a program that writes "tut-tut-tut" without using the characters "t", "u" or "-" in the code itself. This is ...
  • 183
15 votes
28 answers
2k views

Calculating Pi using the Gregory Leibniz series until n terms

based off my previous challenge, this wikipedia article, and a Scratch project Your task: given i, calculate \$\pi\$ till i ...
11 votes
4 answers
678 views

Compute the Fabius Function

The Fabius function is an example of a function that is infinitely differentiable everywhere, yet nowhere analytic. One way to define the function is in terms of an infinite number of random variables....
  • 17.2k
26 votes
12 answers
5k views

Was it a King or a Queen or neither?

Input A calendar year from 927 to 2022. Output You can use any three distinguishable outputs. As an example, “K” (short for King) or “Q” (short for Queen) depending on which of the two England had in ...
  • 1,091
11 votes
14 answers
2k views

Advanced Binary Number System

Your task is to write a program that calculates the amount of different ways to display any given whole positive number using the following rules: Meet the 'advanced binary system': Any whole positive ...
  • 477
2 votes
0 answers
178 views

Shorten this dns txt record request script as much as possible

I have made a short script that will pull dns txt records down from a server and combine them into a single string. DNS txt records are: 1.website.com ...
3 votes
3 answers
290 views

Sudoku Solver Diagonal Constraint

This is the follow up question to standard Sudoku solver. You are given a Sudoku grid where . represents an empty cell and the other cells are filled with numbers <...
20 votes
16 answers
2k views

Calculate Pi unto a point using the Nilakantha series

Your task: given a nonzero positive number i, calculate pi using the Nilakantha series unto i terms. The Nilakantha series is as ...
14 votes
17 answers
2k views

Compute GPA for a set of grades

Given a set of letter grades, output the GPA (grade point average) of those grades, rounded to one decimal place. Valid grades and their corresponding value are the following: ...
  • 377
14 votes
10 answers
1k views

IMO Question Six with a difference

In 1988, the International Mathematical Olympiad (IMO) featured this as its final question, Question Six: Let \$a\$ and \$b\$ be positive integers such that \$ab + 1\$ divides \$a^2 + b^2\$. Show ...
0 votes
0 answers
85 views

shortest runtime bytecode question [duplicate]

What is the shortest runtime bytecode you can write for a contract that satisfies both the following: Accepts calldata of length 32 bytes representing one uint256 (no function selector) Returns, as ...
-5 votes
6 answers
446 views

I'm Blue, Da ba dee da ba die

Write a program, which outputs I'm Blue, and then Da, Ba, Dee, Da, Ba, Die, forever, the words must be space-seperated in one ...
34 votes
10 answers
2k views

Re-name all identifiers to a single letter

Imagine a very simple language. It has just 2 syntax features: () indicates a block scope, and any word consisting only of 1 or more lower case ASCII letters, which ...
  • 2,843
8 votes
1 answer
289 views

Solve a jigsaw puzzle

A jigsaw puzzle consists of (usually rectangular-ish) pieces. On each side of a piece, there is either an edge or a connector (a term I made up). A connector is either a tab sticking out (outie) or a ...
-2 votes
3 answers
156 views

Find the GCD and LCM of a list of numbers [duplicate]

Note: most of the questions that are already in existence about this topic only deal with two numbers as inputs. This question deals with any number (>1) of inputs. GCD The GCD (greatest common ...
39 votes
23 answers
5k views

Tut-tut-tut-tut-tut

The string tut-tutut-tut-tuttut-tut can be constructed with overlapping or concatenated instances of the word tut-tut: ...
  • 12.9k
17 votes
11 answers
3k views

Fibonacci word fractal

The Fibonacci word is a sequence of binary strings defined as: \$F_0 = \$ 0 \$F_1 = \$ 01 \$F_n = F_{n-1} F_{n-2}\$ The first ...
  • 37.5k
50 votes
10 answers
9k views

When will the DVD logo hit the corner?

One of my favorite memes is the bouncing DVD logo. Yet silly but extremely satisfying, a DVD logo keeps bouncing on a screen and if you ever happened to watch this screensaver, you were most likely ...
  • 1,199
21 votes
5 answers
603 views

Does there exist a synchronizing word?

A complete deterministic finite automaton is a machine, with some states. Each state in the automaton has, for each character in the alphabet, a pointer to a state (not necessarily a different one). ...
15 votes
14 answers
4k views

The "Fly straight, dammit" sequence

Background "Fly straight, dammit" (OEIS A133058) is a sequence of integers, which has these rules: \$a_0 = a_1 = 1\$ \$a_n = a_{n-1}+n+1\$ if \$gcd(a_{n-1}, n) = 1\$ Otherwise, \$a_n = \...
6 votes
13 answers
1k views

Number of ways to make an amount with coins

This is not a duplicate of Sum of combinations with repetition. This question considers 1+2 to be the same as 2+1. The other ...
16 votes
14 answers
1k views

Persistence of a number

The persistence of a number \$x = d_1d_2d_3...d_n\$, with \$d_1 \ne 0\$, under some function \$f : \mathbb N_0 \times \mathbb N_0 \to \mathbb N_0\$ is defined as the number of applications of \$f\$ to ...
19 votes
9 answers
1k views

Is This an Equivalence Relation?

Given a relation, and a domain, output whether the relation is an equivalence relation. Context For this challenge, a relation is defined as being a set of ordered pairs that is a subset of the ...
  • 23.7k
10 votes
16 answers
694 views

Sum of partition numbers

The partition function: In number theory, the partition function p(n) represents the number of possible partitions of a positive integer n into positive integers For instance, p(4) = 5 because the ...
11 votes
17 answers
1k views

Find the nth Mersenne Prime

A number is a Mersenne Prime if it is both prime and can be written in the form 2m-1, where m is a positive integer. For example: 7 is a Mersenne Prime because it is 23-1 11 is not a Mersenne Prime ...
15 votes
5 answers
831 views

Detect round trips on a dodecahedron

An ant starts on an edge of a dodecahedron, facing parallel to it. At each step, it walks forward to the next vertex and turns either left or right to continue onto one of the other two edges that ...
  • 251
10 votes
1 answer
234 views

Optimally pop all the bubbles

In a given 2d grid of positive integers (representing different types of "bubbles"), there are one of two actions that you can do each "step". You can either: Pop an island (a ...
  • 8,405
-1 votes
3 answers
185 views

Make a Brainfuck Interpreter [duplicate]

There already is a Brainfuck interpreter question, but it is from 2011 and not up to date with current site standards and vague in places. I have proposed reposting this in chat, and it was well-...
  • 3,715
8 votes
3 answers
1k views

The smallest number of steps for a chess piece to reach a position

I have previously posted a challenge, smallest number of steps for a knight in chess. Now I would like to go a step further by adding the possibility to choose your piece. If you place a piece on any ...
  • 405
21 votes
15 answers
2k views

Polyglot Quiz (Cops' thread)

This is the cops' thread of a cops-and-robbers challenge. The robbers' thread can be found here In this challenge as a cop you will choose two programming languages A and B, as well as a non-empty ...
  • 90.1k
12 votes
2 answers
713 views

Solving an easy Sudoku in increasing digit order

Introduction: I'm old-fashioned and still read a physical newspaper in the morning while eating my breakfast. Although I don't like Sudoku that much, I do solve the Light-complexity ones, which are ...
17 votes
25 answers
2k views

Is it a properly tiered list?

A ragged list is a (finite depth) list where each element is either a positive integer or a ragged list. A ragged list is properly tiered if it contains either all positive integers or all properly ...
  • 90.1k
8 votes
2 answers
249 views

Implement Level-Index Addition

Level-index is a system of representing numbers which has been proposed as an alternative to floating-point formats. It claims to virtually eliminate overflow (and underflow, in its symmetric form) ...
  • 17.2k
15 votes
17 answers
2k views

The second even sublime number

easy mode of my previous challenge A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 + 2 + 4 + 7 + 14 = 28) are perfect. ...
  • 66.1k
10 votes
10 answers
2k views

Play a dumb coinflip game

Write an interactive program or function which allows the user to play The Coinflip Game! The object of the game is to repeatedly flip a coin until you get the same result \$n\$ times in a row. ...
19 votes
25 answers
1k views

Carry-less sum given a base b

Given a list of positive integers \$\mathcal I=I_1,I_2,I_3,...,I_n\$ and a base \$b>1\$ return their "carry-less sum", i.e. represent \$\mathcal I\$ in base \$b\$ and sum digit-by-digit ...
  • 9,258
17 votes
8 answers
2k views

An algorithm to find even sublime numbers

A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 + 2 + 4 + 7 + 14 = 28) are perfect. A sublime number (OEIS A081357) is ...
  • 66.1k
19 votes
14 answers
3k views

Is this graph a tree?

Given an undirected graph, find out if it is a tree. A tree is an undirected graph in which there is exactly one path between any two vertices. In other word, the graph is both acyclic and connected. ...
  • 37.5k
0 votes
3 answers
270 views

All permutations of range from \$1\$ to \$n\$ [duplicate]

Given a positive input \$n\$, output all permutations of either \$\{0,1,\ldots,n-1\}\$ or \$\{1,2,\ldots,n\}\$. Examples Outputting permutations of \$\{1,2,\ldots,n\}\$. Input Output ...
1 vote
0 answers
211 views

Solve the Greek Computer Puzzle Toy [closed]

Solve the Greek Computer Puzzle Toy There is a small toy of a series of stacked dials -- loosely inspired by the Antikythera Device. The puzzle, made by Project Genius, has a series of dials that must ...
30 votes
29 answers
4k views

A challenge for rookies

Print or return the following string: ...
  • 12.9k

1
2 3 4 5
226