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
19 votes
7 answers
1k views

Expand a matrix goo-ily

Input An \$m\$ by \$n\$ binary matrix, with \$m\$ and \$n\$ both at least 2. Think of the ones as gobs of melted cheese, which stretch as we expand the matrix horizontally and vertically. More ...
user avatar
  • 26.9k
10 votes
7 answers
281 views

Maximum population of a \$n \times n\$ still life in Conway's Game of Life

This is OEIS sequence A055397. In Conway's Game of life, a still life is a pattern that does not change over time. We can see from the rules of Conway's Game of life that, a pattern is a still life if ...
user avatar
  • 34.5k
12 votes
5 answers
243 views

Resolve a Super Auto Pets Round

In Super Auto Pets, players build teams of animals that face off in battles to the death unconsciousness. Each animal has an Attack and Health value, and combat occurs in iterations of the following ...
user avatar
9 votes
11 answers
1k views

Smallest numbers whose square has even number of digits

...
user avatar
  • 9,416
15 votes
11 answers
2k views

Satisfy as many people as possible

There are times when a large number of people need to choose something. They all want to get the stuff they choose, obviously, but it's impossible to please everyone that way, so a usual compromise is ...
user avatar
  • 2,829
13 votes
17 answers
1k views

The interstice of two binary numbers

Given two integers, compute the two numbers that come from the blending the bits of the binary numbers of equal length(same number of digits, a number with less digits has zeros added), one after the ...
user avatar
  • 426
12 votes
9 answers
483 views

Draw an ASCII envelope based on size input

You want to send an ASCII letter to someone, but you need an envelope to put it in. Your task is to output an envelope given a size as input. Rules: Given positive integer input ...
user avatar
-1 votes
5 answers
267 views

Output this string from the `kolmogorov-complexity` tag info page [closed]

kolmogorov-complexity is one of the tags on this site, representing challenges that test how much code is needed to output a given fixed result (usually a piece of text). The info page for this tag ...
user avatar
  • 1,719
19 votes
30 answers
2k views

Convert from variable-width Two's Complement to Integer

Take an input, and convert it from Two's Complement notation (binary where the first bit is negated, but the rest are taken as normal) into an integer (in a somewhat standard output form). Input can ...
user avatar
  • 1,278
10 votes
8 answers
2k views

How many times do I break my own rule?

Introduction: In my recent Strikethrough the Word Search List challenge I mentioned the following: When I do the word-search puzzles, I (almost) always go over the words in order, and strike them ...
user avatar
6 votes
15 answers
907 views

Spaceship shooter

Your task is to output a spaceship of size n with shooters/guns and n bullets of character - ...
user avatar
  • 3,041
40 votes
13 answers
4k views

Recreate Minecraft's lighting

Minecraft has a fairly unique lighting system. Each block's light value is either one less than the brightest one surrounding it, or it is a light source itself. Your task is to write a method that ...
user avatar
  • 691
11 votes
14 answers
876 views

Arrange a Haft-Sin table

It's Nowruz and you want to set up a Haft-Sin table by words. This means finding seven words that start with letter s. The Challenge Write a program which its input is a list of words separated by ...
user avatar
12 votes
14 answers
2k views

Sandbox overflow

Your task is to output a square sandbox of size n+2 with / characters in the corners and | ...
user avatar
  • 3,041
3 votes
2 answers
328 views

Calculate the highest possible period oscillator in Conway's Game of Life

Input: a whole positive number greater than 4 Output: A whole positive number that describes the highest possible period an oscillator could have inside a square space of size (input)x(input) in a &...
user avatar
  • 363
19 votes
12 answers
906 views

Convert between graph representations

What? Let's say I have this graph: 1 \ \ 2 3 \ / \ / 4 I can represent it in 2 ways: A list of connected vertices. ...
user avatar
  • 1,614
73 votes
57 answers
11k views

Draw the Ukrainian Flag

As you will probably know, there is a war going on in Ukraine. I noticed that it seems nobody has posted a Ukrainian flag challenge yet, so I thought I'd do it myself in support of Ukraine. The ...
user avatar
  • 3,330
10 votes
6 answers
418 views

The Missing Match

You are given a string of unknown length that contains a varied amount of (, {, [ and their ...
user avatar
  • 431
18 votes
15 answers
1k views

Long period primes

A long period prime is a prime number \$p\$ such that decimal expansion of \$1/p\$ has period of length \$(p-1)\$. Your task is to output this number sequence. For purposes of this challenge we will ...
user avatar
  • 11.4k
21 votes
26 answers
2k views

Randomly Rounding

Input a decimal number and round it to an integer, randomly rounding up or down with a probability based on its fractional part, so the expected value of the output equals to the input value. If ...
user avatar
  • 29k
15 votes
13 answers
1k views

Recursively rotate a ragged list

Given a ragged list of positive integers return a full cycle of recursive rotations starting with the unchanged input and ending with the state immediately before revisiting the initial state. ...
user avatar
  • 6,530
23 votes
32 answers
5k views

Negative of an ASCII photo

Task Given an \$m\times n\$ binary ascii "photo", return the negative of the photo Example: ...
user avatar
  • 1,151
4 votes
19 answers
552 views

Double bit rotation to the right [closed]

Given a positive integer as input, output that integer, but with its bits rotated two times to the right. Also, think of the number as a donut of bits, eg. ...
user avatar
12 votes
3 answers
273 views

Line Islands in a Word Search

My third word search related challenge in a row. :) Challenge: Brief explanation of what a word search is: In a word search you'll be given a grid of letters and a list of words. The idea is to cross ...
user avatar
19 votes
14 answers
1k views

Sort numbers in a ragged list

Given a ragged list, e.g. [[4, 7], [5, 3, [], [6, [2]]]] Your challenge is to sort only the numbers in it. For example, with the above, the result would be ...
user avatar
  • 29.9k
12 votes
26 answers
1k views

Circular chained compound

Task Given a positive integer n, output the joined compound of circles The circles are of square of size n+2 but removing the ...
user avatar
  • 3,041
7 votes
13 answers
1k views

Complex permutation

Given an array of integers as input(including negative integers), find all (can include duplicates) permutations that do not have the same number next to each other, then print them all out. If no ...
user avatar
19 votes
25 answers
2k views

Zip uneven lists

In this challenge you will take two lists as input and you will zip them. The zip can be defined with this recursive expression: \$ \mathrm{zip}(a,b) = \begin{cases} \left[\,\,\right] & a = \left[...
user avatar
  • 87.4k
3 votes
9 answers
1k views

int, float or neither?

Given a string, determine if it is an int, a float or neither. Examples 123 - int 62727.0033 - float 644c.33 - neither Your code should output a different value depending on which it is. For example ...
user avatar
  • 393
11 votes
7 answers
440 views

Sort musical pitches

Given an unordered list of musical pitches, write the shortest program/function (scored in bytes) to sort the list from lowest pitch to highest. Pitches will be given in scientific pitch notation, ...
user avatar
  • 10.3k
22 votes
17 answers
947 views

Pairs of integers ordered by their exponentiation

Output the infinite list of pairs of integers (a, b), where both \$ a > 1 \$ and \$ b > 1 \$, ordered by the value of \$ a^b \$. When there are multiple pairs ...
user avatar
  • 20.7k
26 votes
13 answers
869 views

Resolve references in a chat discussion

Sometimes in chat, if someone says something you agree with, you'll send a message with an ^, which points at the message above: ...
user avatar
28 votes
29 answers
2k views

Repeat List Until Longer

The Challenge The challenge is simple: given an input list a and another list b, repeat a ...
user avatar
  • 2,547
15 votes
9 answers
900 views

Count the Liberties

Background This challenge is about the game of Go. Go is a game played on a board with a square grid N x N. You don't have to know how to play the game to do this ...
user avatar
  • 2,213
2 votes
5 answers
145 views

Generate this string table [duplicate]

For the given string s, generate generate a table like below. ...
user avatar
  • 1,625
14 votes
16 answers
1k views

Building spikes

Inspired by this building (United States Air Force Academy Cadet Chapel, Colorado) Your task is simple, given a positive integer n, output the spiked building to ...
user avatar
  • 3,041
6 votes
2 answers
355 views

Reveal all clues of Black Box

Black Box is a board game, Your task is to reveal all clues. What is black box Black box is a board game with hidden atoms, Your task is given input, All atoms, reveal all clues. I/O Input The atoms ...
user avatar
  • 2,499
3 votes
5 answers
321 views

The Nineteenth Bakery [duplicate]

Yes, this is very similar to this question. However, that concerns infinite linked lists, and you do not need to handle out of bounds indexes in that question. You are in a strange city, looking for ...
user avatar
  • 2,547
16 votes
10 answers
1k views

Gray code on N symbols

A Gray code is a permutation on binary numbers where incrementing or decrementing a number only ever causes a single bit to change. For example, a Gray code for the binary numbers up to 7 (so, with 3 ...
user avatar
  • 20.7k
18 votes
9 answers
2k views

Is it irrational?

Your task is to make a program that decides if a real number between 0 and 1 is irrational or not. As stated, this is obviously impossible, so instead we will use the following definition: ...
user avatar
  • 6,655
12 votes
7 answers
660 views

S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ the Word Search List

Introduction: Every workday I read the newspaper in the morning while eating breakfast, and also do some of the puzzles at the back. When I do the word-search puzzles, I (almost) always go over the ...
user avatar
14 votes
2 answers
519 views

Find the magic numbers to divide a number without division

An integer \$x\in[0,2^{32}-1]\$ divided by an integer \$d\in{[1,2^{31}]}\$ will produce an integral quotient \$q\$ and a remainder \$r\$, so that \$x=d\times q+r\$. Any \$q\$, in fact, can be ...
user avatar
  • 2,213
15 votes
3 answers
345 views

What was my Wordle play?

Task Given a winning Wordle play results (clues), the target ("secret") word and a list of words, output a possible sequence of words leading to such results. The words in the list will be ...
user avatar
  • 11.4k
17 votes
12 answers
2k views

Random Point from a 2D Donut Distribution

A donut distribution (for lack of a better term) is a random distribution of points in a 2-dimensional plane, forming a donut-like shape. The distribution is defined by two parameters: the radius <...
user avatar
  • 6,269
25 votes
27 answers
2k views

Fill in the next numbers

Given a list of integers, output a list where the \$ i \$th element of the list equals the first number in the input list which is \$ \ge i \$, until there are no such numbers. For example, if the ...
user avatar
  • 20.7k
14 votes
14 answers
997 views

Lexicographically Smallest Decreasing Integer Partition

For a given number n, output an strictly decreasing array whose sum is n and its lexicographical order is the smallest for any ...
user avatar
  • 3,041
21 votes
1 answer
536 views

Can you draw this in one stroke?

Related | Related Given an ASCII art with |, _, and , check if you can draw the art in one ...
user avatar
  • 4,243
20 votes
20 answers
2k views

Can the Tune be Played?

Can the Tune be Played? Explanation A broken musical keyboard has keys labelled with positive integers. It is broken in two ways: It takes a long time to process key presses: after pressing the key ...
user avatar
  • 837
5 votes
1 answer
324 views

Convert 256-wrap brainfuck into 257-wrap brainfuck

Usually each cell in brainfuck has 256 states, which is not enough to tell whether input is EOF or a character (usually \xFF). To fix it we can add one more state ...
user avatar
  • 12.8k
8 votes
8 answers
346 views

Ascii Fibonacci spiral

Let's continue the fibonacci based challenges stream, here's the next one: Task Draw a Fibonacci spiral ascii-art of n segments where starting from the first term: each nth segment has a length of ...
user avatar
  • 9,416