Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
3 votes
6 answers
84 views

Calculate the Lowest Even-Harmonic of the Values in a List

PROBLEM For a list of numbers, list: Find the lowest possible integer, x, which is optimally close to the whole number even-...
user avatar
1 vote
0 answers
109 views

Figure out the least amount of duplicate data to fill a quota [closed]

You are given 100 arrays/sets of 5-8 numbers between 1-20. If you combine all the arrays you will always get at least one of each number (1-20), so don't worry about an "unsolvable" case. ...
user avatar
16 votes
11 answers
1k views

Straighten my corners... diagonally

We can arrange the positive integers like this: 1_| 2 | 5 | 10 4___3_| 6 | 11 9___8___7_| 12 16 15 14 13 That is, in L-shaped brackets expanding down and right ...
user avatar
  • 27.6k
29 votes
31 answers
3k views

Previous Fibonacci number

The sequence of Fibonacci numbers is defined as follows: \$ F_0 = 0 \\ F_1 = 1 \\ F_n = F_{n-1} + F_{n-2} \$ Given a Fibonacci number, return the previous Fibonacci number in the sequence. You do not ...
user avatar
  • 18.7k
15 votes
25 answers
1k views

Reverse hex cipher

Characters in strings are sometimes represented as their ASCII hexadecimal codes. Printable characters have two hex digits in their representation. Swapping those digits leads to another character, ...
user avatar
  • 10.9k
32 votes
32 answers
4k views

Eh, codegolf shmodegolf

This challenge is about implementing Shm-reduplication, originating in Yiddish, where one takes a word, duplicates it, and replaces the first syllable in the second word with "Shm" in order ...
user avatar
  • 601
15 votes
16 answers
1k views

Divisible subset sums

Inspired by the recent 3Blue1Brown video Consider, for some positive integer \$n\$, the set \$\{1, 2, ..., n\}\$ and its subsets. For example, for \$n = 3\$, we have $$\emptyset, \{1\}, \{2\}, \{3\}, \...
user avatar
12 votes
8 answers
862 views

Can a run ascending list be made?

A run ascending list is a list such that runs of consecutive equal elements are strictly increasing in length. For example [1,1,2,2,1,1,1] can be split into three ...
user avatar
  • 85k
17 votes
25 answers
3k views

Generate All 8 Knight's Moves

Introduction In chess, Knights can move two squares in one direction, and then one square in an orthogonal direction. On an x/y plane, these can be thought of as being a relative change of coordinates,...
user avatar
  • 170
13 votes
12 answers
2k views

I want 8 bits for every character!

This is the reverse of this challenge. Given an encoded list of codepoints and the characters used to encode it, you need to decompress it to its original string. For example, given the encoded list <...
user avatar
  • 4,206
18 votes
12 answers
1k views

In between fractions

Given two positive integer fractions \$x\$ and \$y\$ such that \$x < y\$, give the fraction \$z\$ with the smallest positive integer denominator such that it is between \$x\$ and \$y\$. For example ...
user avatar
  • 85k
6 votes
24 answers
2k views

Find the nth Fibonacci number, where n is the mth Fibonacci number

Introduction If fib(x) calculates the xth Fibonacci number, write a program that calculates ...
user avatar
  • 185
-1 votes
0 answers
94 views

Find the Lowest Allowable Integer Which is an Optimal Even-Harmonic of the Values in a List [closed]

PROBLEM For a list of numbers, list: Find the lowest possible integer, x, which is optimally close to the whole number even-...
user avatar
14 votes
13 answers
703 views

Find the dimensions of a ragged list

For any ragged list its dimensions will be a list of non-negative integers defined as follows: Elements that are not a list will have dimensions \$\textbf{[}\,\,\textbf{]}\$. An empty list has ...
user avatar
  • 85k
6 votes
2 answers
202 views

Solve the Zany car game

The Zany Car Game is a tile matching game. You are given a number of tiles, with coloured cars split into a top and bottom half. To win the game, you need to find a square arrangement of the tiles so ...
user avatar
  • 1,011
12 votes
15 answers
5k views

LOOOOONG TEEEEEXT

Definition of long text Long text usually shows emphasis, for instance, loooooool or yaaaaaaaaaay. Usually the vowel is ...
user avatar
  • 529
16 votes
21 answers
2k views

Apartment Building

Draw an "apartment" building according to the specifications below. Basic Rules Take, as input, the number of floors of the building. Return a building with that many floors meeting the ...
user avatar
  • 1,270
12 votes
8 answers
758 views

Count the Liberties - Advanced

Here's an advanced version of the Count the Liberties challenge. The definitions of the terms liberty and group are the same as the previous challenge, so have a look at the previous one for details, ...
user avatar
  • 2,121
16 votes
25 answers
1k views

Alternating sums of multidimensional arrays

Given a multidimensional array, find the recursive alternating sum. An alternating sum is simply the sum of an array, where every other item (starting with the second) is negated. For example, the ...
user avatar
13 votes
9 answers
2k views

Magic: the Gathering - Colour Sorting

Related: Deck Names Friends or Foes Paying for Spells The Magic: the Gathering card game has five colours of magical mana: white (W), blue (U), black (B), red (R), and green (G). Cards can be any of ...
user avatar
14 votes
23 answers
2k views

There's more than one way to skin a set

Given a set of positive integers \$ S \$, output the set of all positive integers \$ n \$ such that \$ n \$ can be made by summing a subset of \$ S \$ in more than one different way, i.e., that are ...
user avatar
  • 18.7k
17 votes
23 answers
2k views

Crossing a Lily Pond

The Narrative You are a frog who is at the edge of a pond with waterlilies. You would like to cross the pond without getting wet, so you plan to jump from lily to lily. There is, however, one problem: ...
user avatar
  • 995
12 votes
9 answers
332 views

Convert Alpha-2 to Alpha-3

The Task The task is easy: given an Alpha-2 country code, output the Alpha-3 equivalent. The input may be in any case you choose, and the output in any consistent case of your choosing. Here are the ...
user avatar
  • 2,537
7 votes
2 answers
244 views

Write a (simplified) BitCycle interpreter

Implement a function or program that can run simplified BitCycle code. The functions you must implement are: <^>v: Change the direction of a bit to the ...
user avatar
  • 1,270
10 votes
13 answers
1k views

Draw the Archimedean Spiral

Overview I was playing with Desmos and discovered a really cool spiral: Doing some research, I discovered that this spiral was the Archimedian spiral. Every point on the spiral is exactly \$\theta\$ ...
user avatar
  • 2,537
10 votes
15 answers
330 views

center a matrix [closed]

The words "center a" probably give flashbacks to any decent HTML developer. Luckily, we are not working with divs, we are working with matrices. Given a matrix where w=h, and given a "...
user avatar
  • 691
8 votes
6 answers
232 views

Random Pixels Image Compression

Challenge: Given an integer \$n\$, guaranteed to be \$\geq2\$ and a power of 2, we are going to draw multiply boards either side-by-side or below one another, where the first has dimensions of \$n\$ ...
user avatar
20 votes
13 answers
2k views

Bitwise XOR of floats

This is different from Floating Point XOR, and more in the spirit of a comment by R.. GitHub STOP HELPING ICE on that challenge, but I thought of this idea independently. Generalized XOR The bitwise ...
user avatar
-4 votes
2 answers
64 views

Is it a good chord?

Is it a good chord? Definition of a chord: We define a chord as three notes together. Definition of a ...
user avatar
  • 529
4 votes
18 answers
2k views

Palindromic Powers

Powers We define an important power as a number that can be represented as \$ x^y \$ where \$ x ≥ 2 \$ and \$ y ≥ 2 \$. Palindrome We define an ...
user avatar
  • 529
27 votes
5 answers
3k views

Haplololololololology!

Haplology Haplology is a linguistic term: the omission of one occurrence of a sound or syllable that is repeated within a word, for example probly for probably. For this challenge, it means ...
user avatar
14 votes
10 answers
1k views

Storing a band matrix

Related challenge A band matrix is a matrix whose non-zero entries fall within a diagonal band, consisting of the main diagonal and zero or more diagonals on either side of it. (The main diagonal of a ...
user avatar
  • 31.8k
0 votes
6 answers
455 views

Connecting Dots

Connecting Dots We define a type of question on the test, connecting the dots Question parameters There are two parameters. Suppose they are 5 and ...
user avatar
  • 529
18 votes
6 answers
2k views

Matrix Meets ASCII Art

A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is 0. For example, the array ...
user avatar
  • 529
15 votes
7 answers
1k views

Euler characteristic of a binary matrix

A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is <...
user avatar
  • 32.9k
20 votes
8 answers
2k views

ASCII-Art n'th Root

Challenge: Given two integers \$a\$ and \$b\$, with lengths \$A=length(a), B=length(b)\$, output an ASCII-art of the \$a^{th}\$ root of \$b\$, including the answer rounded to \$A\$ amount of decimal ...
user avatar
5 votes
9 answers
317 views

I Need Moore(less) Chips

If you wanted to compute a very large long problem, that on a machine that you could buy today for an inflation adjusted price, will take some amount of years/decades. The issue is, if you only have ...
user avatar
  • 457
9 votes
2 answers
310 views

Sorting passengers on a plane

A few days ago I made a puzzle about moving people on an airplane. Now I am interested in the general version of this puzzle and the shortest code golf for it. I will briefly summarise the puzzle here....
user avatar
12 votes
5 answers
436 views

Unshuffle my poker chips

This part is somewhat detached from the actual array manipulation side of the challenge, scroll down for an explanation that is much more array-based You've been learning how to shuffle poker chips ...
user avatar
26 votes
28 answers
2k views

Derivative of a product

In calculus, the derivative of a mathematical function defines the rate at which it changes. The derivative of a function f(x) can be marked as ...
user avatar
  • 27.6k
21 votes
16 answers
4k views

Who needs 8 bits for one character?

Given a string and the characters used to encode it, you need to compress the string by only using as many bits as each character needs. You will return the character codes for each character needed ...
user avatar
  • 4,206
14 votes
6 answers
661 views

Rounding a range

You have a line with two endpoints a and b (0 ≤ a < b) on a 1D space. When ...
user avatar
  • 2,121
15 votes
25 answers
1k views

Implement the Conjunction of a Three-Valued Logic

Your task, should you choose to accept it, is to take two input values \$a\$ and \$b\$, where \$a\$ and \$b\$ are in the set \$\{T, U, F\}\$, and compute and output their logical conjunction in a ...
user avatar
  • 1,021
11 votes
7 answers
638 views

Shortest restricted superstring

Given two sets of strings, \$ D \$ and \$ R \$, find the shortest string which contains every string in \$ D \$, but contains none of the strings in \$ R \$. There are almost always multiple possible ...
user avatar
  • 18.7k
12 votes
7 answers
1k views

Is Wally there?

Inpired by recent Stand-up Maths' video. Task Wrapping a list x can be seen as inserting "line-breaks" into x every <...
user avatar
  • 10.9k
3 votes
3 answers
197 views

Plot Slope Fields Given Differential Equation

Slope fields or direction fields, are a graphical representation of the solutions to a first-order differential equation of a scalar function. A slope field shows the slope of a differential equation ...
user avatar
  • 447
12 votes
11 answers
1k views

Convert JSON object of directories to list of paths

Task The input consists of a JSON object, where every value is an object (eventually empty), representing a directory structure. The output must be a list of the corresponding root-to-leaf paths. ...
user avatar
  • 1,282
19 votes
8 answers
2k views

Convert Alpha-3 to Alpha-2

I've been developing some programs involving me fetching a vector from a url using Alpha-2 country codes (such as GET /jp.svg for Japan). Except, oh no! All the ...
user avatar
  • 441
12 votes
17 answers
2k views

Infinite Candle Sequence

I have a cake shop that specialises in birthday cakes. The cakes that I sell must have candles placed in a circle. You would probably think I can just divide 360° by the number of candles, but the ...
user avatar
29 votes
28 answers
3k views

Collatz Encoding

The Collatz Conjecture The famous Collatz Conjecture (which we will assume to be true for the challenge) defines a sequence for each natural number, and hypothesizes that every such sequence will ...
user avatar

1
2 3 4 5
222