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
2 votes
0 answers
79 views

Qat Equation Solver

Qat is a tool that lets you search for words matching a given pattern, often used by crossword and other word puzzle writers and solvers. In this challenge, you will have to implement a specific part ...
7 votes
2 answers
260 views

On The Subject Of Simon Says

This challenge is from a game, Keep Talking And Nobody Explodes. This is like one of those toys you played with as a kid where you have to match the pattern that appears, except this one is a knockoff ...
  • 4,383
21 votes
3 answers
591 views

Detect sonar imposters

You are the sonar captain aboard an underwater submarine. The way sonar works is that every submarine sends out a ping at regular intervals. Each interval is a whole number of seconds. Each submarine ...
  • 94.1k
11 votes
4 answers
437 views

Draw the GKMS aperiodic tile

Chaim Goodman-Strauss, Craig Kaplan, Joseph Myers and David Smith found the following simple (both objectively and subjectively) polygon that tiles the plane, but only aperiodically: Indeed they ...
  • 2,957
13 votes
4 answers
1k views

Is it a Frog List?

Challenge: A Frog List is defined by certain rules: Each frog within a Frog List has an unique positive digit [1-9] as id (any 0...
4 votes
4 answers
748 views

A randomly colored walk

Given two inputs, a distance \$d\$ and a number \$n\$ output a list of \$n\$ random colors which each have distance \$d\$ from the previous. Background A random walk is a path which is defined by ...
-7 votes
1 answer
127 views

Do absolutely nothing [closed]

Write a program that has at least one byte that, when run, does absolutely nothing. I thought this would be done by now, but I can't find any other challenges like this. How to tell if it does nothing:...
5 votes
2 answers
303 views

Shortening this Code to process nested tuple even further without the use of max()

I have the code: ...
9 votes
9 answers
2k views

Great Leap to the Right

Given a string s consisting of characters a-z lowercase, generate 5 arrays a1, a2, ...
19 votes
47 answers
4k views

Implement the `<=>` three-way comparison operator on numbers

In C++, there exists a a <=> b three-way comparison operator that, for numerical types, does the following: If a < b, ...
  • 6,182
7 votes
1 answer
145 views

Is there any less code way to make a leaf (eye) shape in CSS?

I'm trying to solve a CSS challenge. It contains a rotated leaf shape (looks like an eye). Score for the challenge depends on amount of characters of the code. Here's my way to make a leaf shape: <...
16 votes
7 answers
2k views

We're gonna need a bigger podium!

If \$R\$ runners were to run a race, in how many orders could they finish such that exactly \$T\$ runners tie? Challenge Given a positive integer \$R\$ and a non-negative integer \$0\leq T\leq {R}\$ ...
15 votes
16 answers
1k views

How long to carry sort?

Carry sort is an \$O(n)\$ "sorting" algorithm. Here's how it works. The algorithm moves left to right along a list. As it traverses a list it "carries" a single item, the largest ...
  • 94.1k
28 votes
12 answers
3k views

Is it a valid chemical?

Non-metals typically* have a fixed number of covalent bonds in every chemical they are part of. Given the number of bonds every element requires, output whether it's possible to construct a single ...
  • 8,625
28 votes
13 answers
2k views

Is it traversable?

Imagine that a list of integers describes the heights of some two-dimensional terrain as seen from the side. Stamina: [ 4 4 4 4 4 4 3 3 3 3 2 2 2 - ] O ...
  • 16.8k
12 votes
6 answers
732 views

Mapping Passing Through Point

(Inspired by this challenge.) Given six real values in three pairs: \$(x_1, x_2), (y_1, y_2),\$ and \$(x_0, y_0)\$, where \$x_1 < x_0 < x_2\$ and \$y_1 < y_0 < y_2\$, create a function ...
9 votes
2 answers
376 views

Guess The Array

Problem author: https://stats.ioinformatics.org/people/5815 You are given a system with a hidden permutation of the numbers \$1, 2, 3, \ldots, n\$. Your task is to guess this permutation by asking the ...
4 votes
2 answers
177 views

Ragged list pattern matching, Part 2

This is a sequel to Ragged list pattern matching. In this challenge, the wildcard may match a sequence of items of any length instead of just a single item. Given a pattern and a ragged list of ...
  • 40.4k
15 votes
5 answers
866 views

Detect round trips on a hyperbolic grid

You're driving a car in an infinite city whose blocks are pentagons arranged in the order-4 pentagonal tiling. At each step, you proceed to the next intersection and choose whether to continue left, ...
  • 401
10 votes
7 answers
763 views

Language Word Checker

Develop a program to check if a given word is part of a language defined by the following rules: The language has a set of rules. The empty string is considered a valid word in the language. Two ...
13 votes
6 answers
713 views

Guessing on straws

Dedicated to Martin Gardner, taken from his book Background In the old days, the Slavs had a divination method for finding out whether a girl would get married. The girl would clutch six straws in her ...
  • 1,033
15 votes
17 answers
1k views

Sophie Safe primes

Description Write a program or function that takes in a positive integer \$n\$ as input and outputs all Sophie Germain primes that are safe primes less than or equal to \$n\$. A prime number \$p\$ is ...
19 votes
19 answers
1k views

"Sort" by element duplication

Inspired by one of many bugs I ran into while implementing selection sort in trilangle. Given a non-empty list of non-negative integers, "sort" the list using the following procedure: Find ...
  • 1,998
19 votes
8 answers
1k views

Bringing Down the Building

We are going to bring down an imaginary building with a series of explosions. Our building is a 5x5 matrix of integers ranging 1-9, each representing a single brick. The challenge is to set of a ...
  • 2,663
12 votes
2 answers
257 views

Classify a surface from its fundamental polygon

This question is an extension of Who's that Polygon? to arbitrary numbers of sides. A fundamental polygon for a surface is an polygon with a prescribed pairing for all its \$2n\$ sides, each ...
  • 2,957
0 votes
6 answers
388 views

Generate number from given range

Your function must accept three numbers in any order: A signed real number (or ±Infinity) - The number (N) for which you have ...
  • 1,353
14 votes
15 answers
1k views

Imtiaz Germain Primes

Description "Imtiaz Germain primes" is not a technical name in Mathematics, but my weird creation, in the memoir of the famous mathematician Sophie Germain. These primes can be generated by ...
9 votes
32 answers
2k views

Counting Letters in a String

Write a program or function that takes in a string and outputs a count of each modern English alphabet letter in the string, case-insensitive. Input: A string consisting of printable ASCII characters (...
6 votes
24 answers
386 views

String with the smallest sum of ASCII values

Description In this challenge, you need to write a function that takes in a list of strings and returns the smallest string based on their ASCII value. You should assume that the input list contains ...
10 votes
3 answers
267 views

Just Friends… in code golf

We already have challenges dealing with simulating vanilla Conway's Game of Life, Wireworld and rule 110, but so far none corresponding to a (specific) non-totalistic rule. So here is one. In June ...
  • 2,957
10 votes
3 answers
541 views

Voronoi-Lloyd ASCII art [closed]

Voronoi diagram is a partition of a plane (or part of plane) into regions close to each of a given set of objects ("seeds"). Here we’ll be dealing with discrete arrays or even rather with ...
  • 1,033
-1 votes
5 answers
272 views

Mirror a String in Place

Write a program that takes a string as input and modifies it by reversing the string in its place by mirroring the position. The first position goes to last, second to second last and so it goes on. ...
15 votes
13 answers
2k views

Tips for golfing in SVG

SVG is an XML vector graphics markup language embeddable in web content. Your tips should be at least somewhat specific to SVG. Please post one tip per answer.
2 votes
0 answers
130 views

Custom Games of Life

There's a lot of questions about Conway's Game of Life, but nothing about customization (Related: 2-Player Life). Given an input, determine the result on a 100x100 grid after some iterations. The ...
  • 399
16 votes
7 answers
1k views

Largest Binary Area

Take the sequence of all natural numbers in binary, (1, 10, 11, ..) then write them vertically beside each-other like this (least significant bit on top; 0s have ...
  • 8,625
10 votes
6 answers
2k views

Draw Parcly Taxel's cutie mark

I've been a fan of My Little Pony: Friendship Is Magic for a long time, and very early on I created a pony version of myself also called Parcly Taxel (warning: may be too cute to look at). The symbol ...
  • 2,957
-8 votes
2 answers
214 views

Find the average, median, mode, and range

It's easier to put this into coding terminology, so here we go: First find the average, median, mode, and range. Then, put those values in another array, then find the new average, median, mode, and ...
  • 399
5 votes
2 answers
212 views

Canonical form of a cubic Bézier curve

On Pomax's Primer on Bézier Curves this "fairly funky image" appears: This is related to the fact that every cubic Bézier curve can be put in a "canonical form" by an affine ...
  • 2,957
4 votes
1 answer
154 views

Encrypt AES256 (ECB Cipher Mode)

I've looked and could not find a post for this, if there is one, I'll remove it quick! Related and also related The goal is (hopefully) clear: create the shortest code (in bytes) that implements the ...
  • 399
0 votes
0 answers
86 views

Shape Animation

In PowerPoint, there's just one overly used feature: animations. For simplicity, that shape will be a non-rotated rectangle. The data is specified as an array of eight integers: ...
  • 399
11 votes
14 answers
908 views

Multibase Numbers

(Similar: Through the bases) Normally, our number system is base ten, with the digits 0123456789. However, we can increase or decrease the base count (so ...
  • 399
11 votes
28 answers
2k views

The number of distinct words in a sentence

Challenge: Find the number of distinct words in a sentence Your task is to write a program that takes a sentence as input and returns the number of distinct words in it. For this challenge, words are ...
13 votes
15 answers
855 views

Sum of strings (UTF-16 codepoints)

Your function must accept two strings and return new string where are UTF-16 code of all symbols is the sum of UTF-16 codes of inputs symbols If the resulting sum is greater than ...
  • 1,353
12 votes
16 answers
2k views

Longest Valid Parentheses

Given a string of parentheses ( and ), find the length of the longest substring that forms a valid pair of parentheses. Valid ...
13 votes
13 answers
567 views

Generate a permutation from the high-water marks

Given a permutation, we can define its high-water marks as the indices in which its cumulative maximum increases, or, equivalently, indices with values bigger than all previous values. For example, ...
17 votes
24 answers
2k views

Shortest code to generate all Pythagorean triples up to a given limit

Generate the shortest possible code in any programming language that can generate all Pythagorean triples with all values not exceeding a given integer limit. A Pythagorean triple is a set of three ...
31 votes
63 answers
3k views

Number to Binary

It seems we've managed to go all this time without a plain vanilla Number-To-Binary challenge! Whilst this will inevitably be only one element in many languages, it should put a few esolangs through ...
  • 9,215
10 votes
5 answers
369 views

Consolidate a 6-axis 2-dimensional Vector

Typically, when we want to represent a magnitude and direction in 2D space, we use a 2-axis vector. These axes are typically called X and Y: This isn't always convenient, however. The game BattleTech ...
  • 9,241
11 votes
2 answers
203 views

Making one shape out of dissections of another

Introduction One question that I have come across recently is the possibility of dissecting a staircase of height 8 into 3 pieces, and then re-arranging those 3 pieces into a 6 by 6 square. Namely, is ...
  • 11.3k
26 votes
47 answers
3k views

Shortest Code to Find the Smallest Missing Positive Integer

Description Given an unsorted array of integers, find the smallest positive integer that does not appear in the array. Your task is to write the shortest code possible to solve this problem. Input A ...

1
2 3 4 5
231