Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

10
votes
5answers
294 views

Amidakuji (阿弥陀籤) simplification

If you have ever had any exposure to Japanese or East Asian culture you will have surely encountered the Amidakuji game: As Wikipedia explains, it is a type of lottery drawn on paper and used to ...
13
votes
16answers
817 views

Length of a UTF-8 byte sequence

Determine the length of a UTF-8 byte sequence given its first byte. The following table shows which ranges map to each possible length: ...
13
votes
15answers
2k views

Logic Gates Manually

Make a program that simulates the basic logic gates. Input: An all-caps word followed by 2 1 digit binary numbers, separated by spaces, such as OR 1 0. The gates <...
14
votes
46answers
2k views

The max() is not enough

Intro A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?". While we didn't find a way ...
15
votes
9answers
602 views

Stagger, stack, sum

Inspired by this Stack Overflow question. The challenge Input An array of square matrices containing non-negative integers. Output A square matrix built from the input matrices as follows. Let \$...
15
votes
16answers
1k views

Supreme Sum String

Supreme Sum String Given an input string, return the word with the highest sum of each of its unicode characters. Rules The input should be seperated by whitespace The value of each word is based ...
12
votes
2answers
358 views

Making a Mountain out of a Molehill

You are given a string of terrain, with molehills and mountains: ...
16
votes
21answers
2k views

Same number letters

Letters of the words want fairness. They decided to appear same number of times in a sentence equally. Example: Priorities Will become: ...
19
votes
64answers
5k views

Display numbers lacking 2's

Display numbers from one to one-hundred (in increasing order), but number 2 shouldn’t appear anywhere in the sequence. So, for example, the numbers two (2) or ...
13
votes
8answers
1k views

Backhanded Compliments

This challenge is created in celebration of my first esoteric language, Backhand! Backhand is a one dimensional language with a non-linear pointer flow. The pointer moves three steps at a time, only ...
7
votes
44answers
2k views

Letters challenge

Using the word “conemon” print each character 2 times more than the last. The first letter, “c”, should be printed 10 times, the second 12 and so on. Each repeated-letter-string should be printed on a ...
15
votes
25answers
4k views

The Work Day Countdown

I just had I genius idea for making the work-life easier - a countdown to a specific date which only counts workdays. The basic task is to create a countdown to a specific date which only includes ...
9
votes
12answers
1k views

Different combinations possible

Problem Given a value n, imagine a mountain landscape inscribed in a reference (0, 0) to (2n, 0). There musn't be white spaces between slopes and also the mountain musn't descend below the x axis. ...
26
votes
23answers
2k views

Equalize the array

Challenge You are given an array \$a\$ of integers. With a move you can increase or decrease an element of the array by 1. Your task is to equalize the array, that is make all the elements of the ...
13
votes
5answers
471 views

Self Scoring Program

We have a challenge to output your own score, but it seems like all the answers there just hardcode the output and that's boring1. So lets have a new challenge. Your program must output its own ...
26
votes
18answers
3k views

Make them sum to 10,000

We've recently reached the threshold of 10,000 questions on PPCG. Hooray! Let's celebrate this with a simple challenge. Input Two integers \$A\$ and \$B\$, both in \$[1..9999]\$, such that \$A+B<...
10
votes
13answers
877 views

Multiply and Divide

Given a value x find the smallest numerical value greater than y that is capable of being multiplied and divided by x while retaining all original digits. The new numbers do not lose digits. The new ...
21
votes
9answers
694 views

Compute the superset

Your task here is simple: Given a list of integer sets, find the set union. In other words, find the shortest list of integer sets that contain all the elements in the original list of sets (but no ...
16
votes
21answers
2k views

How many threes?

In this task your code will be given an integer \$n\$ as input. Your code should then output the greatest number of multiples of \$3\$ that can be concatenated (in base \$10\$) to form \$3n\$ (with ...
24
votes
18answers
5k views

PronunciationSort™

We all know of different fancy sorting algorithms, but none of these give us numbers in a way that's easy to pronounce. To remedy this, I propose using PronunciationSort™, the most natural way to sort ...
18
votes
26answers
3k views

Is the word coprime?

Given a word, treat every letter as it's number in English alphabet (so a becomes 1, b becomes 2, ...
7
votes
2answers
384 views

Is the date alphabetical?

Write a function or program that accepts a date (as a string in YYYY-MM-DD format) as input and returns a truthy value if that date is "alphabetical," and a falsey ...
11
votes
5answers
1k views

Track an object in 2d space

Description The task of this challenge is to devise a program or function that tracks a given object in an \$n×n\$ space. I/O Your program will be given 3 inputs, which may be taken in any sensible ...
6
votes
12answers
607 views

Recursively count lines of code, excluding empty lines and comments

Requirement: Write a program (in any language) that counts the number of lines of code in files matching *.sh in the directory tree starting from the directory that ...
12
votes
33answers
3k views

True color code

True color (24-bit) at Wikipedia is described in pertinent part as 24 bits almost always uses 8 bits of each of R, G, B. As of 2018 24-bit color depth is used by virtually every computer and ...
11
votes
8answers
964 views

Mid-Autumn Festival gambling game

Tomorrow is the Mid-Autumn festival, and in the spirit of that holiday, I will introduce a gambling game that we (people from Xiamen) play during the holiday! Rules The game is played with six 6-...
18
votes
12answers
2k views

Is the Matrix Positive-Definite?

Introduction Today we're gonna take care of the bane of first-year linear algebra students: matrix definiteness! Apparently this doesn't yet have a challenge so here we go: Input A \$n\times n\$ ...
5
votes
3answers
437 views

Ordinary Least Squares Regression

I am quite surprised that a variant of linear regression has been proposed for a challenge, whereas an estimation via ordinary least squares regression has not, despite the fact the this is arguably ...
2
votes
1answer
173 views

I won't not use no double negatives [closed]

The goal is to simplify sentences containing multiple negatives. Like with multiplying negative numbers, two negative words annihilate each other until at most one is left (doesn't matter which one). ...
13
votes
10answers
1k views

Quadratic residues are so much fun!

Definitions Quadratic residues An integer \$r\$ is called a quadratic residue modulo \$n\$ if there exists an integer \$x\$ such that: $$x^2\equiv r \pmod n$$ The set of quadratic residues modulo \...
3
votes
6answers
689 views

No trailing but(t)s please!

This challenge was inspired by Yeah But No But Yeah. maxb´s colleague recently sent him the following piece of JavaScript as a joke: ...
3
votes
4answers
227 views

Build a Board of Napier's Bones

This proposal had few attention for 8 months (though an answer was posted in the sandbox at that time), so I decided to post it anyway. Introduction Napier's bones is a calculation tool, which helps ...
4
votes
2answers
208 views

Nightmare Puzzlang translator

Background Puzzlang is a derivative of Brainfuck, where the symbol X executes a BF command based on three characters on top of it, and anything else does nothing. ...
-13
votes
6answers
325 views

You failed everything! [closed]

Your goal is simple: to fail everything. More precisely, you should write the shortest code that triggers a compilation/interpretation error, or a runtime error. What does not count Failing with ...
9
votes
5answers
491 views

A sorcerer's spellbook

Edit: I haven't played D&D before so when I initially made this question I didn't properly research it. I apologize for this, and I'm making a few edits that might invalidate answers to stay as ...
25
votes
25answers
4k views

Output a Sudoku board

Today's challenge is simple: Without taking any input, output any valid sudoku board. In case you are unfamiliar with sudoku, Wikipedia describes what a valid board should look like: The objective ...
22
votes
24answers
2k views

An ogl-edocf challenge

Input A non-empty shuffled string consisting of ASCII characters in the range \$[32..126]\$. Output The output is obtained by applying successive rotations to the input string. For each letter (<...
6
votes
5answers
522 views

The least weird fact about the US presidency right now

The least weird fact about the US presidency right now is that there have been two unrelated presidents whose last names start with T-R-U-M. That made me think, how many US presidents share other ...
0
votes
2answers
287 views

Transpile Brainstract to Brainfuck

Introduction Brainstract, a newly created dialect of Brainfuck adds a bit more elements to the syntax. In addition to the normal Brainfuck syntax, there are macros. To define a macro: ...
49
votes
65answers
17k views

Helloellolloloo Worldorldrldldd

Make a program that takes the word you input, and adds that word to the back of itself minus its first letter, then repeats until all letters are gone. For example, ...
17
votes
18answers
4k views

Longest Repeating Subsequence of a Single Digit

Challenge: Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer). An example: Input:...
28
votes
18answers
3k views

The Improved Caesar Pig Latin Cipher

The problem with the Caesar cipher is the resulting words are often unpronounceable. The problem with Pig Latin is that it is easy to decode. Why not combine them? Input A word consisting of the ...
10
votes
7answers
629 views

Whose neighbours are hostile?

Introduction For the purposes of this challenge, we will define the neighbours of an element \$E\$ in a square matrix \$A\$ (such that \$E=A_{i,j}\$) as all the entries of \$A\$ that are immediately ...
4
votes
3answers
182 views

Hyperoperation Golfing [duplicate]

Introduction In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the unary operation of successor (n = 0), then ...
-4
votes
3answers
299 views

Without using numbers, Calculate Pi [duplicate]

Inspired by Nicola Sap's Challenge Goal Your challenge is to simply produce π with 232-1 digits. However today's twist, like the title implies, is to produce it without using any numbers or any π ...
3
votes
14answers
648 views

Rest of the path

Consider this file path: C:/Users/Martin/Desktop/BackupFiles/PC1/images/cars/new.png Your goal is to write a program that will return the file path starting from ...
31
votes
41answers
5k views

Half, Half Half, and, Half

Consider the following number sequence: \$ 0, \frac{1}{2}, \frac{1}{4}, \frac{3}{4}, \frac{1}{8}, \frac{3}{8}, \frac{5}{8}, \frac{7}{8}, \frac{1}{16}, \frac{3}{16}, \frac{5}{16}, \frac{7}{16}, \...
13
votes
11answers
2k views

Crop ASCII Art Challenge

ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task? One common task in ASCII art manipulation is to crop text to a rectangle ...
14
votes
20answers
1k views

Block-sorting rows and columns in a 2D array

Given a 2D array of integers, let's sort its rows and columns in blocks. This means that you only have to sort a given row or column, but applying the transformations needed for sorting it to every ...
44
votes
38answers
12k views

Yeah But No But Yeah

My colleague recently sent me the following piece of JavaScript as a joke: ...