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
20 votes
17 answers
662 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
  • 39.5k
0 votes
0 answers
41 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
  • 361
6 votes
2 answers
125 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
  • 10.8k
13 votes
15 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
  • 2,991
2 votes
1 answer
128 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,657
9 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
  • 98.7k
15 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
11 votes
4 answers
1k 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
  • 1,955
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
  • 1,955
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
15 votes
24 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
56 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
  • 395
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,657
11 votes
4 answers
546 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
  • 24k
17 votes
4 answers
2k 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
  • 37.9k
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
  • 24k
18 votes
13 answers
1k 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
  • 37.9k
9 votes
3 answers
194 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
  • 98.7k
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
  • 10.8k
4 votes
5 answers
574 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
733 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
741 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
716 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,941
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.4k
18 votes
10 answers
932 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
  • 98.7k
34 votes
17 answers
3k 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
21 votes
4 answers
2k views

Avoiding Loops!

Given a collection of coloured laces, what would be the probability, \$P\$, that Alice won't create any loops if, until impossible, they tie two uniformly chosen, free lace ends of differing colours ...
Jonathan Allan's user avatar
6 votes
12 answers
916 views

Argument of a complex number (Robbers)

V1.1: Added criterion to help with tiebreakers, a bit overkill but still.V1.2: It's April 15th! Task: Crack the scrambled code for calculating the argument of a complex number \$z=x+iy\$ given two ...
CrSb0001's user avatar
  • 361
10 votes
23 answers
2k views

Argument of a complex number (Cops)

This is the cop's thread, where one should post the scrambled code. Here is the robbers' thread where the cracked source should be posted and linked to the cop's answer. NB: I am currently writing up ...
CrSb0001's user avatar
  • 361
4 votes
8 answers
744 views

Evaluate Ternary Logic

Objective Given an expression involving ternary values, evaluate it into a ternary value. Ternary Values The three truth values in question are the values of Haskell's ...
Dannyu NDos's user avatar
  • 5,941
2 votes
3 answers
190 views

Rank poker High Card hands [closed]

In the poker game there are 1277 unique 'High Card' ranks. It's 1287 (13 over 5) if we include all straights. The challenge is to write a function which returns an integer value corresponding to the ...
Ziarek's user avatar
  • 123
14 votes
7 answers
2k views

How quickly can you type this unary string?

If I want to type the string aaa, the least keystrokes I can type it in is 3: a a a. But if I want to type the string ...
emanresu A's user avatar
  • 37.9k
8 votes
12 answers
1k views

Scan input for numbers and add thousands separators

Challenge Given ASCII-encoded text input of any size, detect numbers between -1,000,000,000,000,000,000 and 1,000,000,000,000,000,000 exclusive and rewrite them with thousands separators. Use commas ...
noname's user avatar
  • 391
1 vote
7 answers
111 views

Interlaced array [duplicate]

You are given an array A of length N and an array B of length ...
Daniil Tutubalin's user avatar
12 votes
14 answers
1k views

Lattice points visible from the origin

Challenge Create a program that outputs a square grid showing visible and non-visible points \$(x, y)\$ from the origin based on their greatest common divisor (GCD). A point \$(x, y)\$ is considered ...
vengy's user avatar
  • 2,163
10 votes
5 answers
945 views

Manipulate integers to zero

Objective Given a nonempty unordered list of positive integers, decide whether they can be added, negated, or multiplied to yield a single zero. Each given number must be used exactly once. There is a ...
Dannyu NDos's user avatar
  • 5,941
15 votes
16 answers
1k views

Pretty Palintiples

Imagine you have a positive integer number \$n\$. Let \$m\$ be the number obtained by reversing \$n\$'s digits. If \$m\$ is a whole multiple of \$n\$, then \$n\$ is said to be a reverse divisible ...
Trivaxy's user avatar
  • 487
9 votes
10 answers
1k views

Give two points with the most similar distances to the origin

Consider an \$(n+1) \times (n+1) \$ grid of points places at non-negative integer coordinates. Given two points in the grid at \$(a, b)\$ and \$(c, d)\$, we know that the distance of the first point ...
Simd's user avatar
  • 2,906
0 votes
0 answers
126 views

Shortest Float32Array to Int32Array conversion for audio processing

I'm currently converting a Float32Array to an Int32Array for input to a real-time audio raw PCM to MP3 recording application. <...
guest271314's user avatar
4 votes
0 answers
110 views

Electra "Hello World!" [duplicate]

This will be a bit of a different challenge. Back in 2023, I developed a 2D esolang called Electra, and looking back at my hello world program, (which is 582 bytes by the way) I see a lot of room for ...
DolphyWind's user avatar
22 votes
21 answers
4k views

One-Dimensional Pinball

Consider a finite, one-dimensional grid where each cell is marked with one of two symbols (I will use the symbols < and >, ...
Mukundan314's user avatar
  • 10.8k
21 votes
15 answers
2k views

Can I follow this recipe?

You work in a kitchen which has a peculiar rule. When you mix something into a pot you must always add at least one new ingredient. So you can add pasta, oil, salt then pesto, but not pasta, pesto, ...
Wheat Wizard's user avatar
  • 98.7k
17 votes
15 answers
1k views

Reconstruct a list of strings from its prefixes

emanresu A posted a challenge to reconstruct an ordered list of integers from its unordered set of unordered prefixes. Many users (beginning with xnor's answer) noticed that summing each unordered ...
Greg Martin's user avatar
  • 15.7k
18 votes
18 answers
1k views

Reconstruct a list from its prefixes

A list \$[a_1,a_2,a_3 \cdots a_n]\$ can be uniquely represented as an unordered list of its prefixes - \$ [[a_1],[a_1, a_2], [a_1,a_2,a_3] \cdots [a_1,a_2,a_3 \cdots a_n]] \$. This can be in any order ...
emanresu A's user avatar
  • 37.9k
11 votes
6 answers
405 views

µUnitDC: A unit-aware RPN calculator

Background This challenge is based on a personal project I did, UnitDC. This challenge is a super-miniaturized version of UnitDC. Challenge Please write a simple unit-aware calculator that evaluates a ...
Eternal_flame-AD's user avatar
21 votes
38 answers
2k views

Find the odd one out

Challenge The goal of this challenge is to generate and output a \$16 \times 32\$ (height \$\times\$ width) grid where all cells contain a decoy character, except for a random single cell that ...
vengy's user avatar
  • 2,163
18 votes
26 answers
2k views

Is it a tetrate of two?

The tetration operation consists of repeated exponentiation, and it is written ↑↑. For instance, 3↑↑3 =3 ^(3^3) = 3^27 = 7,625,597,484,987 A tetrate of two is an ...
isaacg's user avatar
  • 42k

1
2 3 4 5
240