All Questions

Filter by
Sorted by
Tagged with
41 votes
67 answers
4k views

Consolidate an Array

The task is simple: consolidate an array of ints. Consolidating this array consists of the following: All instances of 0 need to be moved to the end of the array. There should be no 0s between the ...
146 votes
76 answers
24k views

Interpret brainfuck

Write the shortest program in your favourite language to interpret a brainfuck program. The program is read from a file. Input and output are standard input and standard output. Cell size: 8bit ...
51 votes
31 answers
9k views

Covering a Skyline with brush strokes

Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it. [1,3,2,1,2,1,5,3,3,4,2]...
13 votes
12 answers
2k views

Play a game of memory

Playing the game of memory against a machine is highly unfair, because they play almost as good as small children. So let's make the machine play alone, but in a fair way: Input: 1...26 pairs of ...
97 votes
44 answers
11k views

Survival Game - AlienWar

AlienWar This game takes place in a very crowded planet where aliens are the superior race. Your task is to create your own alien and beat all other. The Board It is a 2 dimensional board. The ...
48 votes
105 answers
6k views

Construct the Identity Matrix

The challenge is very simple. Given an integer input n, output the n x n identity matrix. The identity matrix is one that has <...
-1 votes
0 answers
152 views

Add (Some) Combinatorial Games [closed]

Combinatorial game theory is the study of analysing positions in chanceless games like Hackenbush, Nim and Toads and Frogs. Positions are usually given a number (more specifically, a surreal number), ...
20 votes
11 answers
2k views

I (rev)?(pal)? the source code, you (rev)?(pal)? the input!

Just because the reverse and palindrome were not too challenging individually :) Write a program (full program or function) that satisfies the following: given a string input, the program as-is ...
25 votes
83 answers
7k views

Invert a boolean array

A nice simple one Input Given a boolean array (Or an acceptable alternative), you can assume the array will never be more than 32 elements long. ...
20 votes
55 answers
2k views

Determine if an Array contains something other than 2

Take an array which consists of positive integers or arrays, output if it only contains 2s. Output should be a truthy or falsey value (Sorry if this destroys ...
30 votes
15 answers
2k views

Generate Keyboard Friendly Numbers

Most common computer keyboard layouts have the decimal digit keys 1234567890 running along at their top, above the keys for letters. Let a decimal digit's neighborhood be the set of digits from ...
20 votes
9 answers
2k views

Do you win a Numeric Mahjong?

Background Numeric Mahjong is a hypothetical variation of Japanese Mahjong, played with nonnegative integers instead of Mahjong tiles. Given a list of nonnegative integers, it is a winning hand if it ...
26 votes
98 answers
3k views

Raise integer x to power x, without exponentiation built-ins

Task - The title pretty much sums it up: raise an integer x to power x, where 0<x. Restrictions: Use of exponentiation, ...
149 votes
330 answers
42k views

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...
121 votes
403 answers
30k views

Print a 10 by 10 grid of asterisks

Background This is a standard textbook example to demonstrate for loops. This is one of the first programs I learnt when I started learning programming ~10 years ago. Task You are to print this exact ...
193 votes
412 answers
73k views

1, 2, Fizz, 4, Buzz

Introduction In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other ...
11 votes
5 answers
582 views

Print the answer before a given answer

In this challenge, you'll take an answer as input, and print the answer before it. If the answer passed as input is the first answer, print your own submission's source. You'll be passed any answer in ...
54 votes
102 answers
11k views

Is it double speak?

In an earlier challenge I asked code golfers to produce strings which copy each character in a string. For example: TThhiiss iiss ddoouubbllee ssppeeaakk!! This ...
301 votes
450 answers
125k views

Add a language to a polyglot

This is an answer-chaining challenge in which each answer builds on the previous answer. I recommend sorting the thread by "oldest" in order to be sure about the order in which the posts are ...
2 votes
2 answers
424 views

Compute how many are no larger than each item in an array

Input: an array of length \$n\$ containing integers in the range \$0\$ to \$2n\$. For each integer \$x\$ in the array, compute the number of integers that occur before \$x\$ that are no larger than \$...
92 votes
241 answers
19k views

"DDoouubbllee ssppeeaakk!!"

Super simple challenge today, or is it? I feel like we've heard a fair bit about double speak recently, well let's define it in a codable way... Double speak is when each and every character in a ...
241 votes
446 answers
63k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
21 votes
111 answers
3k views

Print last inputted byte

Challenge You have one string of input bytes, output only the last byte in it. Rules Your submission may be a program or function outputting the last byte in the input which is either a string, stdin ...
68 votes
61 answers
7k views

N-dimensional N^N array filled with N

In: Enough memory and a positive integer N Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by... Examples: 1: [1] ...
20 votes
12 answers
1k views

Sums of sum of divisors in sublinear time

Given a number \$n\$, we have its sum of divisors, \$\sigma(n)\ = \sum_{d | n} {d}\$, that is, the sum of all numbers which divide \$n\$ (including \$1\$ and \$n\$). For example, \$\sigma(28) = 1 + 2 +...
22 votes
35 answers
2k views

Make String Waves

Given a string as input, output the string with the following algorithm applied: ...
19 votes
14 answers
2k views

The Area of Rectangles

Getting the area covered by a rectangle is really easy; just multiply its height by its width. However in this challenge we will be getting the area covered by multiple rectangles. This is equally ...
16 votes
26 answers
2k views

Order by Earliest Lower Digit

Given two strings of digits, determine which string, if any, has the earliest digit which is lower than the other string's digit at the same index. Do note that this differs from alphabetization, as ...
34 votes
42 answers
3k views

Disarium Dilemma

Disarium Dilemma A Disarium is defined as a number whose: sum of its digits powered with their respective position is equal to the original number Your Task: You have a strange obsession with ...
11 votes
12 answers
2k views

Funny Numbers :D

The task is to calculate the average "funniness" of a given number given the following scoring system: 1 point for each "420" in it 2 points for each "69" in it 3 points ...
38 votes
8 answers
2k views

Mirror quine (or my head hurts)

I was reading Print your code backwards - reverse quine And I thought, this could be more interesting if your backwards code is also executable. So this challenge will have all the rules and ...
4 votes
1 answer
96 views

I reverse the source code, you reverse the source code! [duplicate]

Write a program that outputs its source code in reverse when run, and outputs its source forwards when I reverse the source. If your program is "abcd", when run with no arguments it should ...
44 votes
14 answers
2k views

Scramble words while preserving their outlines

This is much more advanced than How to randomize letters in a word and Cambridge Transposition because of the rule about which letters may be swapped with which. A simple regex will not suffice here. ...
23 votes
19 answers
2k views

Find the largest sum such that no two elements are touching

Inspired by this (off topic) post Given an array of numbers, find the largest sum over a subarray not containing two adjacent elements ...
54 votes
146 answers
8k views

The vanilla factorial challenge

Task Given a non-negative integer \$n\$, evaluate the factorial \$n!\$. The factorial is defined as follows: $$ n!=\begin{cases}1 & n=0\\n\times(n-1)!&n>0\end{cases} $$ Rules All default I/...
6 votes
1 answer
383 views

Further golfing this C# code from Scramble words while preserving their outlines

I'll start off by saying I checked and checked again that this question should be on topic. I will also clearly state that this is a tips question about further golfing a certain set of code not a ...
25 votes
41 answers
4k views

Mixed Number to an Improper Fraction

In this challenge you will be converting a mixed number to an improper fraction. Because improper fractions use fewer numbers, your code will need to be as short as possible. Examples ...
18 votes
29 answers
1k views

Smallest groups in an array

Introduction Let's observe the following array: [1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1] A group consists of the same digits next to each other. In the above ...
-1 votes
1 answer
64 views

PHP+C polyglot solution to mixed types

Some built-in functions in PHP return mixed types, like file_get_contents that returns both string or ...
55 votes
36 answers
5k views

Turing-Complete Language Interpreter

A challenge I thought that would be very cool is to make an interpreter for a Turing-complete language of your choosing. The rules are simple: You may use any language to create this interpreter ...
18 votes
19 answers
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: <...
34 votes
73 answers
8k views

"Multiply" two strings

This was inspired by a function I recently added to my language Add++. Therefore I will submit an short answer in Add++ but I won't accept it if it wins (it wouldn't be fair) Don't you hate it when ...
20 votes
20 answers
2k views

Finite Cantor's Diagonal

Given a list of N integers, each with N digits, output a number which differs from the first number because of the first digit, ...
39 votes
63 answers
5k views

All ASCII characters with a given bit count

(Title with thanks to @ChasBrown) Sandbox The Background This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are ...
68 votes
47 answers
6k views

Write the shortest self-identifying program (a quine variant)

Write a program that will generate a "true" output iff the input matches the source code of the program, and which generates a "false" output iff the input does not match the source code of the ...
22 votes
12 answers
3k views

Is it a substring of itself?

Given a string, return whether the string is a substring of the program's source code. Standard quine rules apply, meaning you cannot read your own source code. The length of the input is guaranteed ...
23 votes
34 answers
2k views

Shortest digid-app GetPercentageRounds function

Context So the Dutch "Ministerie van Binnenlandse Zaken en Koninkrijksrelaties" (NL) - "Ministry of the Interior and Kingdom Relations" (EN) recently released the source code of ...
14 votes
43 answers
6k views

Last digit large number

For a given list of number \$[x_1, x_2, x_3, ..., x_n]\$ find the last digit of \$x_1 ^{x_2 ^ {x_3 ^ {\dots ^ {x_n}}}}\$ Example: ...
72 votes
95 answers
7k views

Is the number binary-heavy?

An integer is binary-heavy if its binary representation contains more 1s than 0s while ignoring leading zeroes. For example 1 is ...
234 votes
362 answers
64k views

Is this number a prime?

Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in ...

15 30 50 per page
1
2 3 4 5
277