Questions tagged [code-challenge]
A code challenge is a competition for creative ways to solve a programming puzzle with an objective winning criterion not covered by other scoring tags (e.g. code-golf).
904
questions
16
votes
2
answers
1k
views
Fast leap year check
The task is to find parameters that make a fast leap year check correct for the widest range of years.
We assume the Proleptic Gregorian calendar, which extends the Gregorian calendar backward from ...
4
votes
8
answers
2k
views
Convert 8 Bit brainfuck to 1 bit Brainfuck / Boolfuck
Goal
Input is a Brainfuck program for 8 bit cells, output it for 1 bit cells.
Explanation
We all know Brainfuck, normally it uses 8 bit cells. But there are implementations where a cell is just 1 bit, ...
2
votes
2
answers
498
views
Largest possible relative error
Output
\$20\$ float64s with absolute value between 1 and 2 inclusive whose sum has the largest possible relative error. We can assume the true sum is not zero.
The sum is to be computed from left to ...
16
votes
3
answers
2k
views
Find 10 float64s that give the least accurate sum
Input
Integer \$n > 1\$
Output
Ten 64 bit floating point numbers between \$-n\$ and \$n\$, inclusive, whose sum is the least accurate.
Details and examples.
These examples are not claimed to be ...
-3
votes
5
answers
253
views
Create the characters you can write on a MacOS US English Keyboard (as another OS will read them)
Introduction
This is a small challenge I came up with while trying to make some compact code for my younger brother to use. I don't think it's particularly interesting, but I believe it presents some ...
4
votes
9
answers
2k
views
nimi ale lon toki pona! (Every word in Toki Pona!)
"nimi ale lon toki pona" is a song by YouTuber jan Misali which lists 137 common words in the constructed language Toki Pona. This challenge is not a duplicate of "How high can you ...
7
votes
2
answers
273
views
Convert maximum values to bit widths
Background
The newest version of the C standard, C23, adds preprocessor macros like INT_WIDTH, ULONG_WIDTH, and ...
18
votes
3
answers
951
views
Magical BF: BF code that works in two ways
Challenge
In this challenge, we will use a language that is very similar to Brainfuck but slightly different.
This variant of BF does not have any input and output commands; instead, it simply takes ...
0
votes
2
answers
231
views
The many ways to skin a `cat` [duplicate]
The well known cat command simply copies its stdin directly to stdout unchanged. But there are plenty of other commandline tools that exist...
What other commands ...
-2
votes
2
answers
276
views
Forward foo, reverse bar, but avoid dead code [closed]
So simple: Provide some code that outputs foo and with the reversed source outputs bar. But before you come up with something ...
5
votes
11
answers
1k
views
Print the banned characters based on the most common characters
This is an answer-chaining post, so in this challenge every answer (except the first answer) depends on the previous answer.
The goal of this challenge is to output the restricted characters. The ...
20
votes
31
answers
3k
views
Restricted Meta-Cat
Your challenge, should you choose to accept it, is to write a program in a language of your choice that, when given a string (limited to printable ASCII) as input, outputs a new program in the same ...
4
votes
5
answers
786
views
What is the smallest possible binary output you can generate
Here is a challenge:
What is the shortest possible compiled program? Writing one line programs are fun, but they often lean on language libraries that get pulled into the final bits. How lean can you ...
16
votes
6
answers
4k
views
I irradiate your source code, you irradiate your output
Your task is to write a program \$p\$ which outputs a string \$s\$ with the same length as \$p\$, where \$s \neq p\$.
If I remove the \$n\$th byte from your program to get program \$q\$, then either \$...
30
votes
44
answers
4k
views
Repeat your program to print Fibonacci numbers
Write a program fragment so that, when repeated N times it prints the Nth Fibonacci number. For example, if your program is print(x) then:
...
11
votes
14
answers
3k
views
Encrypting Emojis
Problem
You are tasked with creating a program that performs emoji encryption on a given string of emojis. In this encryption scheme, each emoji is replaced by a unique character (from ...
20
votes
10
answers
2k
views
How Turing complete is your language?
Find the maximum possible number of disjoint sets of characters, that are Turing complete subsets of your language.
Rules:
You can assume your Turing complete subset is contained in/called from a ...
8
votes
8
answers
663
views
Magic OEIS formulae (Robbers' thread)
This is the robbers' thread. See the cops' thread here.
In this cops and robbers challenge, the cops will be tasked with writing an algorithm that computes some function of their choice, while the ...
12
votes
9
answers
775
views
Magic OEIS formulae (Cops' thread)
This is the cops' thread. See the robbers' thread here.
In this cops and robbers challenge, the cops will be tasked with writing an algorithm that computes some function of their choice, while the ...
1
vote
1
answer
218
views
Most elegant one-liner to generate sqlite INSERTs
Challenge
You find yourself in a bash terminal, and want to do some simple tests
on sqlite3.
So you issue the following command:
...
1
vote
0
answers
186
views
making a binary string palindrome using xor operations [closed]
Problem
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
Choose two different indices \$i\$ and \$j\$ (\$1 \le i\$, \$j \le N\$)
Change \$...
3
votes
4
answers
1k
views
Write the smallest possible code in x86-64 to implement the "<=>" operator
Languages, such as C++, have introduced a new comparison operator: <=>.
This operator returns -1, 0, or 1† when comparing two items together:
−1 means the ...
19
votes
17
answers
2k
views
Approximate my atomic weight
Each element on the periodic table of the elements has an atomic weight. For example, boron (element 5) has an atomic weight of 10.81. Your challenge is to write a program which takes as input the ...
12
votes
3
answers
485
views
><> numbers metagolf
I struggle to easily encode big numbers in ><>. If only there was a program that could find the best way for me?
What is ><>
...
25
votes
56
answers
3k
views
Range of ASCII values
Your task
Given a string, output the range of ASCII values.
Example
Let's say we have the string Hello.
We get the ASCII values:
...
40
votes
5
answers
5k
views
50 digits of π in HQ0-9+-INCOMPUTABLE?
Background
HQ0-9+-INCOMPUTABLE?! is a half-joke programming language introduced in Internet Problem Solving Contest 2011, Problem H.
HQ9+ is an esoteric programming language specialized for certain
...
3
votes
4
answers
876
views
A multidimensional strategy challenge
The wizard is determined to pose the most challenging challenge yet for which he believes the previous solution techniques will not work. He decides to go multidimensional.
If there is a number line ...
17
votes
11
answers
2k
views
Numbers vs. Strings: Language fitness challenge
inspired by thejonymyster's idea
Rules
This challenge is about finding languages that are very suitable for one task but quite the opposite in the other. The two tasks share a theme, but Task 1 is ...
10
votes
1
answer
492
views
Turing Machine that outputs pi
Turing Machine Preliminaries
A Turing machine is specified by the following data
A finite set of symbols S = \$\{s_1,s_2,...\}\$
A finite set of states M = \$\{m_1,m_2,...\}\$
A partially defined ...
26
votes
12
answers
3k
views
Write a program with the smallest width
Print or return the following text:
Hello world! The quick brown fox jumps over a lazy dog.
However, your submission will not be scored in bytes. Instead, ...
5
votes
4
answers
615
views
Strategy: The cunning cousin witch
The wizard has a cunning cousin who is a witch. She looks down on the wizard, regarding him and his puzzles as mathematically naive. On reading his latest puzzle, she scorned him for always asking ...
5
votes
2
answers
930
views
Optimal strategy to defeat the wizard
In this game, you can look inside one box at a time chosen by you. When you do that, you can see how many coins there are in that box.
The wizard has one last twist for you. At any point, you can ...
20
votes
12
answers
3k
views
Optimal strategy for wandering robots
If the agent is at the origin it always moves right when you choose it.
The goal is to get one agent to 10.
The cost is the sum of the square of the total number of moves (left or right) taken by each ...
6
votes
2
answers
301
views
Case Conversion Polyglot
Your task is to write a program that performs case conversion from plain text, and other case formats, into one of the specified formats below. Inputs will be either plain lowercase text, or one of ...
5
votes
7
answers
840
views
Typo resistant pin codes [closed]
Background
I was working on a system where for convenience (not security) people could use four digit codes to identify themselves. I figured this is something that may actually be useful in many real ...
5
votes
0
answers
259
views
Find the best character arrangement
You want to write your English essay. However, all characters on your keyboard broke other than the arrow keys and the enter key. You want to find out how to place the characters so you can write your ...
19
votes
11
answers
2k
views
Write a near crystalline program
A pristine program is a program that does not have any errors itself but will error if you modify it by removing any contiguous substring other than the entire program.
A crystalline program is sort ...
1
vote
1
answer
265
views
Implement the slowest possible sorting algorithm that retains a fast best case [closed]
I have recently been on a quest to create really really slow sorting algorithms that make Bogosort seem like it is the best.
The task is simple: Sort an array of integers in as long average time as ...
-12
votes
5
answers
387
views
12 with no 1234567890, but polyglot
This is my 12th question, so I thought of this idea.
Goal:
Output 12, with any preceding or trailing whitespace permitted
In as many languages as possible (where different versions or flags count as ...
29
votes
21
answers
4k
views
Add a hidden language to a polyglot
Inspired/mostly copied but I don't think it's a dupe. Also Inspired.
In this challenge, you will create polyglots that include all languages from previous answers, and another language which you won't ...
6
votes
1
answer
683
views
Irradiated Polyglots
Design a function or program that, when run normally, outputs the triangular numbers. However, when any single character is deleted, the program/function should not function in the original ...
5
votes
1
answer
191
views
BitCycle Metagolf
Background
BitCycle is a two-dimensional Turing-complete programming language involves moving bits around a playfield.
Because I am too lazy to write BitCycle programs myself, you will be writing a ...
27
votes
28
answers
4k
views
What's the Missing Code? (Cops)
Cops' Challenge
Robbers' challenge here.
It has now been four days since the challenge was posted so all new answers should be marked as non-competing in the title. These answers can still be cracked ...
3
votes
0
answers
191
views
Calculate the probability of getting this hand in n tries [closed]
Imagine there is a card game where the primary objective of the game is to get 4 of one card in your hand.
Game mechanics
Each player starts of with 10 cards in their hand. The remaining 32 cards (...
4
votes
3
answers
278
views
Find All Digitroot Cyclic Sequences With Length Greater Than One
Digital sum, DR, Digit root is the iterative process of summing digits of a number until you end up with a single digit root number: e.g. digit root of 12345 is 6 since 1 + 2 + 3 + 4 + 5 = 15 = 1+5. ...
3
votes
2
answers
283
views
Implement constant-latency branchless multiplication efficiently
Modern hardware can perform multiplication very fast in a constant latency of 3~4 cycles. But some tiny chips for embedded environments sometimes lack hardware multiplication, which has to be emulated ...
10
votes
3
answers
1k
views
Build an optimizing Brainfuck compiler/interpreter
the goal
Build an optimizing Brainfuck implementation. Whether it is a compiler, an interpreter, a JIT compiler, or whatever else is up to you.
scoring
A reference implementation (...
6
votes
3
answers
346
views
Write a regex that would increment a 2-digit hexadecimal number
Your regex will receive a string of the form
!XX!
#<extra>
where X is any hexadecimal digit (0-9 and A-F capital letters ...
13
votes
1
answer
606
views
Longest infinite loop in 5 states
Challenge Statement
The goal of this challenge is to build the 5 state Infinite Time Turing Machine that takes the longest to halt. Since Infinite Time Turing Machines can run for infinite time your ...
6
votes
2
answers
308
views
Generate Matching Regexes
Write a program that takes two lists of strings and generates a javascript regex that fully matches all the strings in the first list and matches none of the strings in the second list.
To be specific ...