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
10
votes
11answers
258 views

Animate finding the middle (hypercube edition)

1d version Given a multidimensional array of positive integers where all dimensions are the same length, animate finding the centre of it. Simply output the array, then remove the first and last items ...
8
votes
1answer
114 views

Score a Scrabble Play

Background In Scrabble, players take turns placing tiles on a grid so that each contiguous set of (more than one) tiles in every row and column makes a word. In one play, tiles can be placed anywhere ...
11
votes
11answers
297 views

SuperSquares NxN

Given an integer N from 1-9, you must print an NxN grid of NxN boxes that print alternating 1s and Ns, with each box having an alternating starting integer. Examples ...
1
vote
0answers
40 views

Smallest OCI Container That Handles PID 1 Signals Correctly

Introduction There have been a few examples of the smallest possible OCI container that does "X". However these examples never correctly handle termination signals. Challenge Produce the ...
10
votes
12answers
433 views

Ragged Matrix Indexing

A ragged matrix, is a matrix that has a different number of elements in each row. Your challenge is to write a program in any favorable language to find the indices of all occurrences of target in the ...
18
votes
14answers
984 views

Print a NxN integer involute

Given an integer \$N\$, you must print a \$N\times N\$ integer involute with the numbers increasing in a clockwise rotation. You can start with either 0 or 1 at the top left, increasing as you move ...
14
votes
14answers
866 views

Count count count

Description You have a list of integers and start counting from the first term to the next and continue from that to the next and so on.. How many times have you counted? For example given [ 2, 5, 3, ...
3
votes
6answers
342 views

Don't output the file

This rar file, when decompressed, gives a 65024-byte exe file. Requiring you to output the contents of that file would be ...
15
votes
4answers
516 views

Probability breaking sequences

If we have a finite list of elements we can determine the probability of any one element being drawn at random as the number of times it occurs divided by the total number of elements in the list. For ...
-8
votes
1answer
187 views

The right way to return [[0, 0, 0], [0, 1, 0], [0, 0, 0]] [closed]

Here is the program to return [[0, 0, 0], [0, 1, 0], [0, 0, 0]] [[0]*3,[0,1,0],[0]*3] Try it online! Can you shorten this code?...
12
votes
3answers
313 views
+50

Trap the hero in a maze

You are an evil wizard, doing evil wizard business, when suddenly your crystal ball alerts you of a hero on their way to defeat you. To crush their hopes and dreams, you decide to trap the hero in a ...
9
votes
8answers
401 views

Count the ways to transform

A rigid transformation of a square array is a mapping from square arrays of a certain size to square arrays of the same size, which rearranges the elements of the array such that the distance to each ...
25
votes
11answers
3k views

Highlight a Wordle guess

In Wordle, you try to guess a secret word, and some letters in your guess are highlighted to give you hints. If you guess a letter which matches the letter in the same position in the secret word, the ...
14
votes
1answer
223 views

Shanghai ascii game sticks

Remove one stick and output the stack updated. Description You can remove only sticks on top( completely drawn). You can assume: there are 5 sticks on the table. there's one and only one stick you ...
22
votes
12answers
2k views

Squishy vectors

If we have a list of integers we can "squish" one of them by: decrementing it replacing adjacent values with its new value For example in this list: ...
0
votes
0answers
66 views

Computing Abelian Sandpile Zeros [closed]

Check out this video for more context: https://youtu.be/1MtEUErz7Gg Write a program that computes the zero of an abelian sandpile with the following parameters: m : height of matrix n : width of ...
16
votes
13answers
1k views

Square-free words of a length

A square-free word is a word consisting of arbitrary symbols where the pattern \$XX\$ (for an arbitrary non-empty word \$X\$) does not appear. This pattern is termed a "square". For example, ...
-3
votes
0answers
108 views

DNA Match: Who did the crime? [closed]

Figure who did the crime by seeing the matches in the suspects and the crime scene. Hint: The person with the most matches is the person who did the crime. Output format is something such as "...
15
votes
16answers
1k views

Sort every dimension

Given a multidimensional, rectangular array of nonnegative integers, sort it at every depth (lexicographically), starting from the innermost. For example, with this array: ...
17
votes
13answers
938 views

Build a list from a depth map

You will be given as input a non-empty list of positive integers. For example: [1,2,2,2,1] You want to produce a ragged list as output which has this as its "...
12
votes
11answers
580 views

Only one from each set

Your input is a non-empty set of non-empty sets of positive integers. For example: {{1}, {2, 3}, {2,4}, {1,4}} Your task is to output the maximal number of ...
8
votes
1answer
122 views

Is this continuous terrain? Part II

Caves and Cliffs edition Part 1, Very related You're given a piece of ASCII art representing a piece of land, like so: ...
30
votes
21answers
2k views

How many times can I skip a stone?

Let's have a list of positive integers [6,1,9,3,7,4,6,3,2,7,6,6] this will represent a river. We would like to skip a stone across this river. We can throw the ...
19
votes
4answers
746 views

Is this hexagon symmetric?

TLDR: This is the hexagonal version of Is this square symmetrical? Given a hexagonal grid, decide if it is symmetric. The shape of the grid is a regular hexagon. Each cell in the grid has two possible ...
1
vote
2answers
137 views

Perl: eval an unpacked hex value passed through any level of ssh

Task Make code given on the command line that takes an unpacked hex value as input and evals that in Perl. Like this: ...
28
votes
9answers
644 views

Predicting pumpkin planting plans' potential problems

You are going to be planting pumpkins soon, and you are preparing your supplies. Pumpkins come in all sorts of sizes and have their sizes written on the seed bag. A pumpkin that is size n will grow ...
13
votes
12answers
598 views

Replicate "dotnet ef" unicorn

.Net Technology is an incredible framework with marvellous functionalities, and among all of them, the most important one obviously stands out: Yep, your simple task is create a program that when it ...
12
votes
7answers
474 views

Crack the Caesar cipher

The Caesar cipher is a simple and famous cipher, where the letters of the alphabet are rotated by some secret amount. For example, if our secret rotation is 3, we ...
9
votes
18answers
748 views

Move to Right and left

Task Your task is to take an array of numbers as input, and produce a new one where each number has been shifted both right and left, leaving 0s if no number fills ...
15
votes
22answers
1k views

Is this word in standard order?

Let \$ A \$ represent the alphabet, such that \$ A_1 = \$ a and \$ A_{26} = \$ z. Let's define that a word \$ W = w_1 w_2 ... ...
17
votes
4answers
482 views

Egyptian fractions summing to n

An "Egyptian fraction" is a list of distinct fractions with a numerator of \$1\$. For example: \$ \frac 1 1+ \frac 1 2 + \frac 1 3 + \frac 1 6 \$ The "size" of an Egyptian ...
10
votes
7answers
228 views

Cell Evolution Matrix

Your lab needed to simulate how a particular cell evolves over time in a 2D grid space. A sample 2D grid space below shows a single cell at the centre of the grid. ...
4
votes
6answers
223 views

Shrink ASCII art

The inverse of this question. Your challenge is to, given a piece of ASCII art generated by the above question and its enlargement factor, shrink it down to its original size. The enlargement process ...
-2
votes
1answer
130 views

Program compressor

Choose a language and write a program in the language that: Take a valid program of the language as input, Output a string(bytearray, etc.). It needn't be a valid program. Only finite valid inputs ...
25
votes
18answers
3k views

Help me sell day-old bagels

You work at a bakery and every day you make exactly 100 bagels. However your customers are not as reliable and every day a random number of bagels will be ordered. So sometimes you will run out of ...
14
votes
25answers
1k views

Implement an argwhere function

The \$\text{argwhere}\$ function takes a list of values and a predicate/boolean function as arguments and returns a list of indices where the predicate function returns true in the input list. For ...
15
votes
13answers
1k views

Recursive palindromes

A palindrome is a word which is spelled the same backwards and forwards. For example, "racecar" is a palindrome as is "redder". A double palindrome is a palindrome whose halves are ...
0
votes
6answers
191 views

Code Golf Birthday Cake

Your task is to print this exact text: ...
15
votes
42answers
1k views

Remove odd indices and double the even indices

Your task is simple, just remove the odd indices and double the even indices Example the input is Hello, World! and we get indices ...
13
votes
8answers
519 views

Compress and decompress

Your task is to make a bidirectional compressor. It takes a list of bytes as input and returns a list of bytes as output. It has the property than whenever it is iterated twice it returns the original ...
7
votes
8answers
238 views

Products all the way down

You are probably familiar with the Cartesian product. It takes two lists and creates a list of all pairs that can be made from an element of the first and an element from the second: \$ \left[1,2\...
23
votes
14answers
2k views

Egyptian fraction representations of 1

An Egyptian fraction is a representation of a rational number using the sum of distinct unit fractions (a unit fraction is of the form \$ \frac 1 x \$ where \$ x \$ is a positive integer). For all[1] ...
12
votes
12answers
397 views

Mat Printing Matrix

A manufacturing company wants to print a design on mats of varying dimensions, and they hired you to program a robot to make these mats. The design consists of alternating rings of any 2 symbols on a ...
30
votes
12answers
2k views

Golf Conway's Primordial Still-Life

Background Note: This configuration was co-found by one of our fellow code golf enthusiasts, Zgarb A 29 year old conjecture by John Conway about the Game of Life was recently solved. To quote Conway ...
15
votes
4answers
296 views

Sides of a polygon

Given an ASCII-art shape made of the characters /\|_, your challenge is to return the number of sides it has. A side is a straight line of one of those, for example:...
10
votes
6answers
423 views

Mirror an integer... in NDos' way

NDos' Numeral System NDos' numeral system is a numeral system invented by me. It represents every nonnegative integer by a binary tree. Given a nonnegative integer \$n\$: If \$n=0\$, it is ...
8
votes
4answers
209 views

Split along groups (hard mode)

This is an alternate version of this earlier challenge with a twist that adds a significant bit of difficulty. Like last time, you are going to be given a string containing some alphabetic characters ...
-2
votes
0answers
106 views

Tips for golfing in !@#$%^&*()_+

What general tips do you have for golfing in !@#$%^&*()_+? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to !@#$%^&*()_+ (e.g. &...
6
votes
1answer
182 views

Busy beaver in a coin

\$BB\$ is the busy beaver function, an uncomputable function. Write a program which when given an integer \$n\$ as input, will output \$BB(n)\$, with at least \$\frac 2 3\$ probability. You can do ...
-2
votes
5answers
148 views

Rotate a grid 90 degrees clockwise

The task is simple, given an integer n of how many lines the next n lines is and, a multi-line input, output the resulting 90 ...

1
2 3 4 5
218