Skip to main content

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
13 votes
13 answers
2k views

Compute the degree of a string

The input is a string made of the letters a,b,c only. The output is an integer representing the degree of the sequence. The degree of a sequence is computed as follows: Assume that each of the ...
Erel Segal-Halevi's user avatar
-3 votes
4 answers
242 views

Integrate a function from -1 to 1 [closed]

Create a function or program that takes any continuous, well-defined, single-input function (f(x)=...) and returns an approximate integration from -1 to 1. (at ...
ThePlaneGuy45's user avatar
11 votes
23 answers
923 views

Construct a uInt from an array of bits

Task is simple! Take an array of binary values (can be boolean, 0/1, etc.) and use those bits to construct an n-th bit long unsigned integer (return type does not need to be an unsigned integer, just ...
ThePlaneGuy45's user avatar
14 votes
2 answers
388 views

Where are zeros? Self-describing sequence

Background A167519: Lexicographically earliest increasing sequence which lists the positions of the zero digits in the sequence. ...
Bubbler's user avatar
  • 77.7k
11 votes
22 answers
2k views

Decode Caesar cipher based on a given text

I can't think of a better name. This is similar to this challenge, but a lot easier. Read three strings which contain only uppercase letters. The length of the first and second strings are the same. ...
None1's user avatar
  • 1,115
16 votes
6 answers
1k views

Golfing the complexity with subtraction

The Mahler-Popken complexity, \$C(N)\$, of a positive integer, \$N\$, is the smallest number of ones (\$1\$) that can be used to form \$N\$ in a mathematical expression using only the integer* \$1\$ ...
Jonathan Allan's user avatar
0 votes
1 answer
281 views

How can I reduce the characters in the following python code? [closed]

The following code is 47 characters. print(("Ekki v","V")["COV"in input()]+"eikur!") How can it be reduced to 46 or less? I ...
LargeHorse's user avatar
8 votes
4 answers
474 views

How far are you?

Write a program that gets coordinates of two objects on Earth, and calculates how far they are from each other directly in space (a straight line through Earth) and on the surface (through the ...
George Glebov's user avatar
13 votes
11 answers
799 views

*Trivial* near-repdigit perfect powers

Task Output the sequence that precisely consists of the following integers in increasing order: the 2nd and higher powers of 10 (\$10^i\$ where \$i \ge 2\$), the squares of powers of 10 times 2 or 3 (...
Bubbler's user avatar
  • 77.7k
13 votes
5 answers
3k views

Anti Tic-Tac-Toe

The rule of Anti Tic-Tac-Toe is like Tic-Tac-Toe. The rules are: There is a 3*3 grid, the squares in the grid are labeled 1 to 9: 123 456 789 ...
None1's user avatar
  • 1,115
8 votes
6 answers
605 views

Find the rule of a cellular automaton

There are already many challenges where you are given a cellular automaton rule and an initial state and you have to find the state after a certain number of steps. This challenge is the opposite: you ...
alephalpha's user avatar
  • 48.7k
14 votes
12 answers
3k views

3 Dimensional Minesweeper

3-Dimensional Minesweeper I've been on a minesweeper kick for a while, but all the questions are for 2 dimensions (or that one in 1D). But 2D is 2 easy! Challenge Write the shortest code possible to ...
pacman256's user avatar
  • 4,155
12 votes
3 answers
1k views

HTML Table Parser

Input a strict subset of HTML <table> string representation as defined below. Output parsed table, while any cells who span multiple rows or columns, record ...
tsh's user avatar
  • 35k
6 votes
3 answers
694 views

Sith TIE-Fighter

Today is May 5th which means it's Star-Wars Day episode II: Revenge of the 5th. For this task, you will output the following image of a Sith TIE-fighter: ...
noodle person's user avatar
6 votes
5 answers
1k views

X-Wing Starfighter

Today is May 4th, Star Wars day, so here's a Star Wars ASCII-art task. Output this image of an X-Wing starfighter: ...
noodle person's user avatar
12 votes
4 answers
1k views

Visually arrange multi-day events on a calendar

The arrangement algorithm I think I've determined the algorithm that Google Calendar uses to visually arrange day-long and longer events at the top of the "Week" view (you may have an ...
Nicola Sap's user avatar
  • 3,684
6 votes
10 answers
980 views

Divisibility patterns

Your inputs are a string and an integer. Your output is the 2d matrix of strings achieved from adding 0 to N spaces between each ...
guest4308's user avatar
  • 1,053
16 votes
19 answers
1k views

Infer pluses and minuses

The problem Consider an equation such as      "3 ± 2 ± 4 ± 1 = 4"      and determine if there exists a sequence of pluses and minuses that makes it arithmetically correct. If it exists, ...
Nicola Sap's user avatar
  • 3,684
14 votes
10 answers
1k views

Enumerate all matches of a regex

related For this challenge, we'll be using a simplified dialect of regular expressions, where: A lowercase letter from a to z ...
emanresu A's user avatar
  • 39.2k
7 votes
25 answers
2k views

Interpret PlusOrMinus

PlusOrMinus is an esoteric programming language invented by Esolang user PythonshellDebugwindow. Language specification There is a wrapping byte accumulator (incrementing ...
None1's user avatar
  • 1,115
26 votes
14 answers
2k views

Is it a cartesian product?

The cartesian product of two multisets \$A\$ and \$B\$ is the multiset of all ordered pairs consisting of an element of \$A\$ and an element of \$B\$. For example, the cartesian product of \$\{1, 2, 7,...
emanresu A's user avatar
  • 39.2k
28 votes
23 answers
2k views

Weave two lists, cycling if necessary

Consider two lists, A and B. To weave them together, we take the first element of A, then the first element of B, then the next element of A, the next element of B, and so on, ending with the last ...
DLosc's user avatar
  • 40k
3 votes
0 answers
103 views

Tips for golfing in Emmental

What general tips do you have for golfing in Emmental? It is a self-modifying language defined by a meta-circular interpreter, so I wonder if there are tips for golfing for this esoteric programming ...
CrSb0001's user avatar
  • 421
7 votes
2 answers
199 views

Tips for golfing in 𝘈𝘤𝘤\$\it{!!}\$

What general tips do you have for golfing in Acc!!? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Acc!! (e.g. "remove comments&...
Mukundan314's user avatar
  • 12.5k
16 votes
16 answers
2k views

Play a sequential game of Rock Paper Scissors

The "sequential" game A number of people stand in a line with their hands hidden in a pre-chosen state of either Rock ✊, Paper ✋ or Scissors ✌️. Here's an example line: Initial Line ✌️ ✋ ✊ ...
Nicola Sap's user avatar
  • 3,684
2 votes
1 answer
179 views

Determine the optimal blackjack move

After the success of my baccarat challenge, I figured we should try a similar challenge for another casino game, blackjack. Blackjack is a game played with two to eight decks of cards shuffled ...
Purple P's user avatar
  • 1,667
11 votes
1 answer
1k views

Flip a coin in Lost

Lost is a 2-D programming language where the start position and direction of the ip are entirely random. Today we will be writing a Lost program which uses this randomness to simulate a coin flip. A ...
Wheat Wizard's user avatar
  • 99.1k
17 votes
4 answers
2k views

Print all legal chess moves

The game of chess has moves. Lots of moves. But how many, exactly? In this challenge, you must print all possible chess moves for a single player (black or white — you choose). Moves are distinguished ...
anatolyg's user avatar
  • 13.7k
10 votes
4 answers
2k views

Output a 1-2-3-5-7... sequence

Follow-up of my previous challenge, inspired by @emanresu A's question, and proven possible by @att (Mathematica solution linked) For the purposes of this challenge, a 1-2-3-5-7... sequence is an ...
Tbw's user avatar
  • 2,093
21 votes
15 answers
2k views

Output a 1-2-3 sequence

For the purposes of this challenge, a 1-2-3 sequence is an infinite sequence of increasing positive integers such that for any positive integer \$n\$, exactly one of \$n, 2n,\$ and \$3n\$ appears in ...
Tbw's user avatar
  • 2,093
16 votes
17 answers
1k views

Maximum number of trailing zeros

Input Positive integers a and b defining an interval of integers [a .. b]. Output The maximum number of trailing zeros in the binary expansion of any integer in the interval [a .. b]. Examples Input: [...
jmchappell's user avatar
16 votes
26 answers
5k views

FizzFizzFizzBuzz!

Given a positive integer n, output the "FizzFizzFizzBuzz" sequence for that number: print the decimal representations of the numbers 1 through ...
3-1-4-One-Five's user avatar
18 votes
60 answers
2k views

Fixed Repeating Output

Fixed Repeating Output is a challenge originally invented by Esolang user AnotherUser05 which shows that a language supports loops and I/O. Challenge A program that solves the challenge has to do ...
None1's user avatar
  • 1,115
11 votes
8 answers
3k views

Should the banker hit?

Baccarat is a casino game where gamblers bet on whether one of two hands, the player or the banker, will have a sum closer to 9 (mod 10) or whether they will tie. It is played with four to eight ...
Purple P's user avatar
  • 1,667
11 votes
4 answers
572 views

Construct the point with two segments

Given a rational point P, return four integral points A, B, C, and D, such that the line segments AB and CD intersect only at P. To make it a bit more interesting, segment AB doesn't include A and B. ...
l4m2's user avatar
  • 25.1k
18 votes
5 answers
3k views

Draw a Fibonacci Swoosh

Title courtesy of Greg Martin For this challenge, I'll define an arc of size \$k\$ as a single piece of a sine wave with a length of \$k\$ units and an height of \$\frac{k}{4}\$ units: And I'll ...
emanresu A's user avatar
  • 39.2k
21 votes
22 answers
1k views

Adding two numbers in Tally marks

Given two positive integers, add them. Both inputs and output are in Tally marks form, which can be expressed as: $$ T(n) := \begin{cases} n,&& n\le 5\\ 5 || T(n-5),&& n>5 \end{...
l4m2's user avatar
  • 25.1k
18 votes
13 answers
2k views

Emulate Jelly's tie-scan

The golfing language Jelly has a built-in ƭ called "tie", that cycles through a list of functions every time it's called. For example, ...
emanresu A's user avatar
  • 39.2k
11 votes
4 answers
271 views

Construct the Irish possessive

In this challenge you will take an Irish word and a personal pronoun and create the possessive pronoun construction combining the two. For example , ...
Wheat Wizard's user avatar
  • 99.1k
13 votes
12 answers
2k views

Odds for second smallest prime factor

Given a prime number \$p\$ output the asymptotic density of the set of positive integers which have \$p\$ as their second-smallest distinct prime factor Input/Output Input: one of the following ...
Mukundan314's user avatar
  • 12.5k
4 votes
5 answers
632 views

Remove filler words from a string

I always stutter and use filler words when speaking to a lot of people at a time. So I need something to remove all my filler words. So here is the challenge. Your program should take input as a ...
3-1-4-One-Five's user avatar
27 votes
6 answers
3k views

How many cacti can I plant here?

Given a Minecraft terrain as a 2-dimensional array of integers or similar datastructure, determine the maximum number of cacti that can be planted on it. The integers represent the height (y) of the ...
Cactusroot's user avatar
11 votes
12 answers
773 views

Rockstar Poetic Number Literals!

The Rockstar programming language has "poetic number literals", allowing you to assign nonnegative, finite (at least one Rockstar interpreter supports infinity) numbers to variables without ...
3-1-4-One-Five's user avatar
11 votes
22 answers
1k views

Map key with value as standard [closed]

Given a non-empty string containing only printable ASCII (codepoints 0x20 to 0x7E), write the shortest program or function that map the key to its value. Inside the string the key will always have a ...
G. Ciardini's user avatar
10 votes
14 answers
757 views

Swifty Argument Labels

For the purpose of this challenge, arguments are things you pass to a function at the call site, while parameters are what the function uses in its implementation. Or, more succinctly: arguments = ...
macOSisthebestOS's user avatar
8 votes
3 answers
788 views

Implement a 2-player version of 1D Chess

The game is played on a 1x8 board with the following setup: KNR..rnk White's pieces are on the left, while black's pieces are on the right. The king (K) can move 1 ...
Quadruplay's user avatar
14 votes
14 answers
2k views

Break an integer into even- and odd-indexed bits

Objective Given an integer \$n\$ interpreted as two's complement binary, output two integers, namely the integer consisting of \$n\$'s bits at places of \$2^0, 2^2, 2^4, \cdots\$, and the integer ...
Dannyu NDos's user avatar
  • 5,961
29 votes
5 answers
2k views

Can I Clear The Grid?

I recently found this game and have been enjoying it. Basically, there is a grid of colored tiles and you act by clicking on empty spaces. When you click an empty space, the first tile (if any) in ...
hyper-neutrino's user avatar
  • 42.5k
18 votes
10 answers
938 views

Next cyclic suffix

We will say a string \$x\$ is cyclic maximal if there is no way to cycle its elements to get a lexicographically larger string. In other words there is no \$a\$ and \$b\$ such that \$a \oplus b = x\$ ...
Wheat Wizard's user avatar
  • 99.1k
35 votes
17 answers
4k views

Create a cactus from words

Introduction: A typical cartoonish cactus usually looks like this: One big stem in the middle, with some L-shaped branches sticking out. We'll use this general shape for this challenge. Challenge: ...
Kevin Cruijssen's user avatar