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
6
votes
1answer
178 views

Radio station hopping

Introduction You are listening to a car radio. You are pressing seek up/down, moving you to the next frequency some radio station broadcasts on, to avoid all this pointless music and listen to all the ...
18
votes
15answers
634 views

Sum on a Fenwick Tree

Background Information: What is a Fenwick Tree? With a normal array, it costs \$O(1)\$ to access and modify an element, but \$O(n)\$ to sum \$n\$ elements. Working with a prefix sum array (an array ...
15
votes
3answers
412 views

Compute the uncomputable … sort of

Implement a function \$f\$ (as a function or complete program), such that \$ \displaystyle\lim_{n\rightarrow \infty} f(n) \$ converges to a number which is not a computable number. Answers will be ...
15
votes
16answers
758 views

Random Move 2x2 Scrambling

A simple way to scramble a 2x2x2 Rubik's cube is to make a sequence random moves. This is not how official scrambles are done, but can get pretty close to a uniform distribution of all possible ...
5
votes
12answers
698 views

Base-ically Guard

Base: part 1 This is part 2, Strongly suggest you go try out the first one if you haven't tried it. Story As one of the solvers, You've managed to get to the door of the base heaven. In front of the ...
19
votes
7answers
2k views

How can this code be more “golfed”?

I'm not sure if this is the right place to ask, but I found this similar question so I'll go ahead. I'm very new to code golfing, so keep your smothered laughs and throw-up emoji's to yourselves ...
-1
votes
0answers
121 views

Generate a uncomputable number [closed]

An uncomputable number is a number that some digit can't be computed in finite time. Now you're to generate and output one of them, in decimal(base 10). You can(and need to) use ...
15
votes
22answers
712 views

Longest Sublist with Equal Occurrences

Given a non-empty list of integers between 1 and 9 inclusive, find the longest contiguous sublist such that the number of occurrences of each element (of the sublist) within the sublist is equal (not ...
17
votes
19answers
2k views

Guide my eyes in the right direction

Inspired by this: http://nolandc.com/smalljs/mouse_reveal/ (source). A valid answer: Takes a number \$w\$ and (assumed non-negative) integer \$x\$. Starts with an integer list with a length of \$2^w\$...
1
vote
0answers
122 views

Sine of x using ONLY arthemetic operators [closed]

The challenge. Implement a sin function without using any builtin sin function. The sin function must be implemented using only ...
20
votes
21answers
1k views

Find Abecedarian Words

An Abecedarian Word is a word whose letters are in alphabetical order. Your goal is to write a program that outputs all abecedarian words from a given lexicon. Rules: Standard Loopholes are forbidden....
8
votes
11answers
992 views

Implement cowsay

Introduction cowsay is a Unix command made by Tony Monroe, written in Perl. It outputs a picture of a cow saying given text. For example: ...
8
votes
18answers
1k views

Least notes money exchange

Suppose A and B are two good friends. A has borrowed \$n\$ dollar from B. Now B wants the money back from A and A is also ready to give it. But the problem is A has only \$x\$ dollar notes and B has \$...
17
votes
22answers
2k views

Delannoy numbers

Consider a grid from \$(0,0)\$ in the bottom-left corner to \$(m,n)\$ in the top-right corner. You begin at \$(0,0)\$, and can only move in one of these three ways: Directly north \$(+0, +1)\$, ...
23
votes
5answers
587 views

Recover polynomial \$f(x)\$ from \$f^2(x)\$

Related: Calculate \$f^n(x)\$, Polynomialception Challenge Given a polynomial \$f(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_k x^k\$ of order \$k\$, we can compute its composition with itself \$f\left(f(...
22
votes
33answers
2k views

Apply at indices

Given: a blackbox function \$f : \mathbb N \to \mathbb N\$, a list of positive integers \$L\$, and a list of indices \$I\$, apply \$f(x)\$ to the elements of \$L\$ at the indices specified in \$I\$. ...
21
votes
6answers
1k views

Inserting digits to satisfy equation

You are given 3 non negative numbers: \$x\$, \$y\$ and \$z\$, and must minimize the number of digits (non negative) inserted at any place in the numbers \$x\$, \$y\$, or \$z\$ to make $$x + y = z$$ (a ...
17
votes
8answers
2k views

What's my lucky factor?

Lucky numbers (A000959) are numbers generated by applying the following sieve: Begin with the list of natural numbers: ...
10
votes
21answers
3k views

Exciting Mario Kart Grand Prix - Minimize the point difference!

Introduction When playing Mario Kart the other day, an interesting question popped up when a Grand Prix with my 2 roommates, 9 AI drivers and myself seemed to be fairly close and therefore exciting ...
14
votes
15answers
1k views

How many Faro shuffles for a cycle?

Background Inspired by this video by Matt Parker A Faro shuffle is a perfect riffle shuffle where the deck is exactly interleaved with its other half. This is how to perform one: the deck of 52 cards ...
22
votes
4answers
2k views

Is it a chess cycle?

Inspired by a discussion from the Esolangs.org unofficial Discord Server. Instructions A chess cycle is an arrangement of a chess board where each piece must attack one other piece, and only one other ...
19
votes
13answers
1k views

Collatz, Sort, Repeat

Background The Collatz (or 3x+1) map (A006370) is defined as the following: $$ a(n) = \begin{cases} n/2, & \text{if $n$ is even} \\ 3n+1, & \text{if $n$ is odd} \end{cases} $$ Now, let's ...
9
votes
1answer
145 views

Are We Fast And Furious? [closed]

There are currently nine feature length films in the core Fast & Furious/The Fast and the Furious media franchise, a series of films about bald men scowling and driving cars very fast. The names ...
13
votes
3answers
443 views

Implement Minecraft's Rails

Background Information Inspired by this answer on Arqade SE Minecraft has rails which allow you to move minecarts around on them for transporting players, entities, and items. There are many types of ...
10
votes
6answers
302 views

Generate the ticks of a graph

A challenge many developers face when drawing a graph from scratch to plot some data is generating its ticks. In below graph, there are 6 horizontal ticks (1750, 1800, 1830, 1860, 1880 and 1900) and ...
6
votes
0answers
93 views

Tips for golfing in Binary Lambda Calculus

BLC (Binary Lambda Calculus) is a binary encoding of untyped lambda calculus which was created to “provide a very simple and elegant concrete definition of descriptional complexity.” What are some ...
5
votes
12answers
2k views

Drawing the Stack Overflow logo

From here. Every new game is the first day of the month, 12:00 PM UTC. The goal is to create the Stack Overflow logo using ASCII characters. It looks like this. The exact output should look like this:...
17
votes
14answers
904 views

Implement swap encoding

Swap encoding is an encoding method where you iterate through a string, reversing sections of it between pairs of identical characters. The basic algorithm For each character in the string: Check: ...
0
votes
0answers
66 views

First N Terms of the Van Eck Sequence [duplicate]

Output the first n terms of the Van Eck sequence. Not the nth term. The Van Eck Sequence is defined as: Starts with 0. If the ...
12
votes
17answers
2k views

Write a program with infinite expected output

Write a program that halts producing a random finite numerical output with probability 1. The expected value of the outputs of the program must be infinite. For physical limits, you can assume your ...
8
votes
1answer
236 views

CDGLF: TMN to APL

In this challenge you will remove one of my least favorite features, operator precedence from traditional math notation, to acheive the syntax of one of my favorite languages, APL. The APL subset we ...
23
votes
16answers
2k views

Generate all solvable 2xN mazes

Your job is to write a program that takes a number N as input and outputs all 2-by-N mazes that are solvable. Output format can be in the form of any two distinct values representing wall and empty - ...
15
votes
11answers
1k views

Phibonacci - Relation between Phi and Fibonacci

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ. Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost ...
8
votes
17answers
1k views

Base-ically god

Story The god of base is opening heaven’s gate for mortals to join the base party. You, as one of the believers, want to follow their steps to ascend to heaven. But not everyone can get in. The god ...
5
votes
4answers
234 views

Print the Najdorf Sicilian

The Najdorf Variation of the Sicilian Defence is an opening often played at the highest level of chess. It is named after GM Miguel Najdorf and is known for being extremely sharp and theory heavy. ...
14
votes
8answers
2k views

Solve the Alien Probe puzzle

Introduction In this TED-Ed video (which I'd recommend watching first), a puzzle is presented. 27 unit cubes must be painted with one of red, green, or purple on each face, so that they can be ...
15
votes
12answers
7k views

Plz Halp, Need Investors ASAP

Bob has a startup that is developing a product that uses “advanced AI” and “black magic” to automatically code-golf computer programs. Unfortunately, Bob is running out of cash and desperately needs ...
15
votes
12answers
2k views

Restricted-source, take this!

a.k.a. You Can Output Anything With Labyrinth Or Hexagony™ Challenge In a recent restricted-source challenge, I could print any character with only half of the allowed digits with very small character ...
13
votes
5answers
379 views

Interpret Gelatin

Gelatin is a worse version of Jelly. It is a tacit programming language that always takes a single integer argument and that has 7 (or maybe 16) commands. You are to take in a Gelatin program and its ...
7
votes
20answers
865 views

Best Rolling Ao5

In speedcubing, an Ao5 (Average of 5) is computed for a set of five times by removing the fastest and slowest times, and then computing the mean of the remaining three times. A "rolling ao5" ...
15
votes
17answers
1k views

Wolstenholme numbers

The generalised harmonic number of order \$m\$ of \$n\$ is $$H_{n,m} = \sum^n_{k=1} \frac 1 {k^m}$$ In this challenge, we'll be considering the generalised harmonic numbers of order \$2\$: $$H_{n,2} = ...
18
votes
7answers
1k views

May the wind be always at your back

You are Odysseus, and are finally free from Calypso (who has kept you captive for many years) after you drugged her while she was sleeping1. You wish to return to your homeland of Ithaca, but the ship ...
38
votes
53answers
9k views

Implement Minceraft

Introduction The game Minecraft has a 1 in 10000 chance of showing "Minceraft" instead of "Minecraft" on the title screen. Your challenge Your challenge is to code a function or ...
14
votes
19answers
2k views

Do I need a win streak?

You have played \$N\$ matches in some game where each match can only result in one of the two outcomes: win or loss. Currently, you have \$W\$ wins. You want to have a win percentage of \$P\$ or more, ...
14
votes
16answers
303 views

Sum over an Interval [duplicate]

Inspired by this challenge, and similar to this and this. After seeing these, I figured I would continue the trend as there was no inclusive/exclusive sum. The goal here is to sum an interval of ...
11
votes
1answer
162 views

Pretty-print my BQN Arrays

Marshall Lochbaum's online BQN REPL has an interesting(and aesthetically pleasing) method of displaying arrays. Your task is to implement a version with simpler rules. ...
9
votes
2answers
337 views

Quote a rational number

Quote notation[1] is a way of expressing rational integers in a precise, finite manner, based on the concept of \$p\$-adic numbers. The notation is in the form of a string of digits (\$0123456789\$) ...
23
votes
29answers
2k views

Count the trailing zeros

Given two positive integers \$n\$ and \$b\$, such that \$n > 2\$ and \$n > b > 1\$, count the trailing zeros when converting \$n\$ to base \$b\$. Your program should be able to handle any ...
11
votes
1answer
193 views

Determine if a dot(comma) program halts

Dotcomma is a simple esolang I made a while ago that only uses four operators: [.,]. In this challenge, you'll determine if a dotcomma program consisting only of <...
27
votes
5answers
2k views

I before E, except after C

You may be aware of the famous old rhyme, "I before E, except after C". It is a rule taught to aid in the spelling of certain English words. Quoting Wikipedia: If one is not sure whether a ...

1
2 3 4 5
207