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
2answers
91 views

Magic Square, Magic Code

A magic square is an \$ n \times n \$ square grid, such that the sum of the integers on each row and column are equal. Note that the definition which will be used in this challenge is different than ...
12
votes
12answers
276 views

Complete a sequence using its distances

Given \$A = (a_1,\dots,a_k)\ k\ge2 \$ a sequence of positive integers, in which all elements are different. Starting from \$i=2\$, while \$a_i\in A:\$ (until the last element) If \$d=|a_i-a_{i-1}|\$ ...
9
votes
11answers
374 views

Is this a half-sort?

The problem over here introduces an new type of strings: if you split the string into equal halfs and swap the pairs, it produces the same output as sorting the string. We call that a half-sort. ...
9
votes
8answers
536 views

Parse a Unicode vulgar fraction

Objective Given a string with single Unicode vulgar fraction, parse it to a rational number. Valid inputs A valid input is one of: ¼ U+00BC; one quarter ...
7
votes
1answer
66 views

Explicit-ify APL expressions involving trains

Related: Clearly parenthesize APL trains Background In the most basic form, APL has two kinds of tokens: arrays and functions. For this challenge, we will use a lowercase letter ...
2
votes
0answers
95 views

Chinese checkers adjacent squares [closed]

Challenge You have a Chinese Checkers board looking like this: ...
31
votes
12answers
3k views

DON'T… do NOT lowercase UPPERCASE this!

Write a program that outputs its input unchanged. However: If all uppercase characters are removed from the program, it lowercases all uppercase letters. If all lowercase characters are removed from ...
12
votes
5answers
432 views

Extract words with clue numbers in a Crossword puzzle

Related: Read a crossword Task Given a completed Crossword puzzle, extract the words in it with their respective clue numbers, with "across" (horizontal) and "down" (vertical) words grouped and ...
2
votes
3answers
217 views

Checking a Windows 95 OEM Key for validity [closed]

Introduction Windows 95 used a very simple algorithm for verifying license keys. The scheme of an OEM license key always looked like this: xxxyy-OEM-NNNNNNN-zzzzz ...
14
votes
28answers
2k views

Shift the letters, soldier?

Context We're at war! You need to transfer an important message to your general to inform them from an imminent assault. The thing is, your enemy knows a lot about cryptography : you will need to be ...
21
votes
6answers
478 views

Find the longest snake on a grid

Background A snake is a path over the cells of a square grid, such that it doesn't touch itself on a side of a unit square. Touching at a corner is allowed. An example snake: ...
25
votes
29answers
3k views
+150

Determine the Sharpness of a Word

Overview The sharpness of a word is the sum of the sharpness of each of its letters, using the following rules: Sharp letters A, and ...
17
votes
11answers
2k views

The Double-Castle Numbers™

Introduction A double-castle number™ is a positive integer number that has a pattern of $$\underbrace{a\cdots a}_{m\text{ }a\text{s}}b\underbrace{a\cdots a}_{m\text{ }a\text{s}}b\underbrace{a\...
4
votes
0answers
236 views
+50

Solve the Rook's Round Trip

The riddle In yesterday's newspaper, I found a puzzle in which a Rook should start in the lower-left corner of a 12x12 checkerboard and then, during a round trip, visit each field exactly once except ...
16
votes
5answers
816 views

Solve a separable differential equation

A first order separable ordinary differential equation is (arguably) the easiest type of differential equation to solve, and takes the form of $$N(y)\frac{dy}{dx} = M(x) \\ y(x_0) = y_0$$ For two ...
14
votes
10answers
1k views

Quines that print what their index is

We all know what a quine is. A quine is a program which prints its own source code. And we also know about the printable ASCII characters. Well... this challenge mixes both. Your mission, should you ...
26
votes
11answers
3k views

Make true and false global!

We all know true and false, but what do speakers around the globe say? ...
26
votes
11answers
3k views

Your code has an uncanny mirror twin…

Write two programs, each taking a string s and a number n ≥ 0, such that: The first program prints ...
42
votes
5answers
4k views

Compute xkcd's Wrong Times Table

The 2020-05-29 xkcd comic showed us the numbers that Randall Munroe feels would be most likely to result from multiplication, other than the correct answers. The table does seem to have some sort of ...
15
votes
20answers
2k views

Zero the byte (eventually)

Given an infinite arithmetically-progressive¹ sequence, compute the minimum length of a prefix with a product divisible by 2^8. Sample cases & reference implementation Here is a reference ...
17
votes
15answers
1k views

Bubbler numbers

Background My user ID is 78410, or \$1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0_2\$. One interesting property of this number is that, in binary, it doesn't have three consecutive identical digits, and yet it ...
-2
votes
2answers
148 views

Get a middle-ish string [closed]

You are the first engineer in a hot new startup, Lexographical. Our company is making waves by digitizing and indexing all words, real or not. The core of our product... Our secret sauce... Well, that'...
1
vote
2answers
101 views

Brainfuck movement [closed]

A normal Brainfuck program starts out with an array of cells, all containing the number 0. This program, on the other hand, must be able to run starting with any ...
15
votes
12answers
2k views

Pass The ⚽️ Around The Circle

The ball game is a game in which a number of players sit together in a circle. Each player is first assigned a number \$ n \$, either 1, ...
22
votes
20answers
1k views

Cut resistance of a list

Background Define a run in a list as a maximal contiguous subsequence of identical values. For example, the list 0 0 0 1 1 0 3 3 3 2 2 has five runs of lengths ...
40
votes
18answers
3k views

Judge a book by its cover

Overview The cover of a book will be provided in the following ASCII format: ______ | | | | | | | | ------ The input can be in any reasonable format ...
19
votes
19answers
2k views

Pairs with Sum divisible by 5

You will be given two integers \$M\$ and \$N\$. Find the number of pairs \$(x,y)\$ such that \$1 \le x \le M\$, \$1 \le y \le N\$ and \$(x+y)\mod5 = 0\$. For example, if \$M = 6\$ and \$N = 12\$, ...
11
votes
10answers
757 views

Find all Belphegor primes

A Belphegor number is a number of the form \$(10^{n+3}+666)*10^{n+1}+1\$ (1{n zeroes}666{n zeroes}1) where \$n\$ is an non-negative integer. A Belphegor prime is a ...
6
votes
3answers
280 views

Program ordinals and omega squared

A program ordinal is a (possibly transfinite) ordinal which can be assigned to programs in some language depending on their output. To be more specific: Strings that give no output have ordinal 0 ...
11
votes
9answers
1k views

Cheat activated

Background The game Grand Theft Auto: San Andreas went down in history also thanks to its wide selection of cheats. They're almost 90 and anyone who has ever touched this game, no doubt has tried ...
36
votes
22answers
2k views

Let's study Neil numbers

Congratulations to Neil for hitting 100k rep! As a tribute, we are going to study 'Neil numbers'. Neil's user ID is 17602 and there's something special about the binary representation of this number: ...
0
votes
1answer
290 views

Sunset in every capital [closed]

This is a very simple challenge. Task Whenever your code is run, your code should output the next sunset date and time in GMT for all capital cities on Earth. You should get the list of capitals ...
23
votes
17answers
3k views

Remove loops from a walk

I've been playing around with a robot on the coordinate plane. This robot is able to tell me if it goes left, right, up, or down by reporting back a string consisting of the letters ...
14
votes
21answers
1k views

Counting characters

Write a function or program that accepts one character (or a string of length 1) as input, and outputs the number of times that character occurs inside the code. This program must be a Proper Quine, ...
1
vote
2answers
333 views

Golf Me A Text-Editor [closed]

Golf Me a Text Editor (similar challenges: Create a simple line editor and Line editor (more text here)) I seem to have forgotten which program to use to open, read, and write text files. Something ...
-4
votes
11answers
246 views

Produce the string “deno” from the string “node” [closed]

The string "node" must be hard-coded in plain ascii to obtain a string with the value "node", which must be transformed into the string "deno". You cannot include "deno", any other variations, any ...
16
votes
41answers
2k views

Check if an array (or equivalent) has the same number of odd and even numbers - Code Golf Edition!

Inspired by this code review question, I am curious to see what happens if we turn that into a code-golf challenge! The description is easy, the input is an array or any similar data structure with ...
12
votes
10answers
824 views

Stepping Through Time

Given a 24 hour time, e.g. 20:48, output the nearest time where each adjacent pair of digits has an absolute difference of 1, e.g. 21:01. That is, each number in the output must differ from the ...
11
votes
12answers
1k views

Lead your team to win the wrestlers world championship!

You are the captain of a world-famous wrestling team. An Olympic-grade match is coming up, and you are determined not to let your team down. You also happen to be a competent programmer, so you are ...
15
votes
31answers
2k views

Reverse factorial function

Given a number n, find x such that x! = n, where both x and n are positive integers. Assume the input n will always be the factorial of a positive integer, so something like n=23 will not be given as ...
3
votes
0answers
108 views

Make paper snowflakes! [closed]

The task Given a folded and cut in places snowflake, "unwrap" it and output the result Input The base folded snowflake, without any cuts, looks like: ...
21
votes
35answers
4k views

Write a microwave timer!

You are an employee of Microteque, a leading Silicon Valley startup creating smart microwave ovens for all kinds of strange places. Your customers can get their microwaves printed with patterns to ...
34
votes
14answers
4k views

Maintain Social Distancing!

Task Given the situation with this global pandemic, you've been enlisted to help maintain social distancing. Your challenge, should you choose to accept it, is to write a program that takes in the ...
4
votes
0answers
207 views

SELECT ALL FROM SelectQL WHERE (answer=“short” OR NOT length=10000)

I've invented an SQL-like language. Let's call it SelectQL. You can't INSERT anything, you can only SELECT, and I don't have the ...
24
votes
9answers
1k views

Bilibili AV/BV Code Conversion

Background Bilibili is a China-based video sharing platform, similar to Nico Nico Douga in Japan, and Youtube around the world. Since the establishment, Bilibili had been using the AV code to ...
41
votes
7answers
6k views

Build a Turing *incomplete* language

The world is full of Turing-complete programming languages. Just about every useful language (and most useless ones) are Turing-complete. Some even became Turing-complete by accident. Often this is ...
16
votes
8answers
1k views

Omit needless spaces for me

A great Python golfing tip is to omit needless spaces. But if you are like me, you don't always have the time to search for which spaces to remove. If only there was a way to speed up the process... ...
17
votes
20answers
3k views

Generate a “Poem”

Given a strictly positive integer, N, produce an output satisfying the following: Produce an array of length N. Every string (i.e. "word") in the array is of ...
5
votes
3answers
214 views

Can I trade today?

Back in 2018, there has been introduced new law in Poland to ban trading on sundays, but certain exceptions have been made (listed below). The task today is to determine, can one trade on the sunday ...
7
votes
9answers
437 views

Convert a string to sentence case

Input: A string (or the closest thing to that in your language) Output: The same string but converted to sentence case Rules: For this challenge, sentence case can be considered "...

1
2 3 4 5
195