All Questions

Filter by
Sorted by
Tagged with
15 votes
5 answers
243 views

Write a set as a union of ranges

In this challenge, we define a range similarly to Python's range function: A list of positive integers with equal differences between them. For example, ...
emanresu A's user avatar
  • 34.8k
3 votes
1 answer
99 views

Tips for radiation hardening

The aim of this post is to gather all the tips that can often be applied to radiation-hardening challenges. Please only post answers which can apply to a large number of languages, and one tip per ...
Command Master's user avatar
13 votes
4 answers
1k 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 \$...
Wheat Wizard's user avatar
  • 95.6k
7 votes
7 answers
2k views

Print 100 digits of π

Your challenge is to print any 100 consecutive digits of π. You must give the index at which that subsequence appears. The 3 is not included. For example, you could print any of the following: ...
emanresu A's user avatar
  • 34.8k
5 votes
9 answers
637 views

Decrypt an Autokey Cipher

The autokey cipher is closely related to the Vigenère cipher (both were invented by Blaise de Vigenère). Decryption involves the encrypted message and the key. For simplicity, let us assume all ...
SquareFinder's user avatar
10 votes
7 answers
631 views

Longest sequence of Egyptian fractions with n as denominator

Background From Wikipedia: An Egyptian fraction is the sum of distinct unit fractions. That is, each fraction in the expression has a numerator equal to 1 and a denominator that is a positive integer, ...
Anm's user avatar
  • 201
13 votes
9 answers
671 views

Convert a non-negative integer to Barbrack

Barbrack Your task is to write a program or function that takes a non-negative integer (in decimal or any other convenient base for your language), and output a number in the numbering system Barbrack....
Someone's user avatar
  • 285
-1 votes
0 answers
184 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), ...
HelloWorld's user avatar
1 vote
2 answers
520 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 \$...
Simd's user avatar
  • 1,545
4 votes
1 answer
121 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 ...
noodle man's user avatar
  • 4,186
13 votes
5 answers
923 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 ...
Rydwolf Programs's user avatar
10 votes
12 answers
3k 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 ...
Joseph's user avatar
  • 109
-2 votes
1 answer
68 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 ...
Olle Härstedt's user avatar
21 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 ...
Bubbler's user avatar
  • 73.2k
20 votes
8 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 ...
Bubbler's user avatar
  • 73.2k
16 votes
16 answers
1k views

Reconstruct an array by successive insertions

Given an array of letters in the range 'a' to 'o', compute how to construct the array by successively inserting the letters in alphabetical order. You will always start the insertion with a base array ...
Simd's user avatar
  • 1,545
20 votes
10 answers
925 views

Implement Subleq

Subleq is a Turing-complete esolang with only one instruction, SUBLEQ. This instruction takes in three parameters, A, B, and <...
97.100.97.109's user avatar
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 ...
bsoelch's user avatar
  • 4,781
-2 votes
1 answer
183 views

Comparator function in Javascript [closed]

Need to write a JS function compare(a,b) for numbers which return 1 when a > b, 0 when a == b, -1 when a < b. Also following properties should hold: compare(NaN, NaN) = 0 NaN is bigger than any ...
Ihromant's user avatar
16 votes
10 answers
1k views

Find the longest permutations of integers from 1..k such that all neighbouring pairs sum to a square

OEIS A090461 details the ‘numbers k for which there exists a permutation of the numbers 1 to k such that the sum of adjacent numbers is a square’. This has also been the subject of Matt Parker’s ...
Nick Kennedy's user avatar
  • 17.1k
6 votes
1 answer
334 views

Self-referencing tuple in python

Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only. Answers meeting this extra ...
Shuri2060's user avatar
  • 171
15 votes
13 answers
2k views

Keep jumping till a cycle

Objective You're on a nonempty list of integers that wraps around. You start at the leftmost entry of the list, and keep jumping to the right to the amount of the integer entry you're at. Eventually, ...
Dannyu NDos's user avatar
  • 5,143
10 votes
16 answers
1k views

Numbers with distinct decimal digits

Write a program or function that outputs all positive integers with distinct decimal digits (OEIS: A010784) Examples: ...
bsoelch's user avatar
  • 4,781
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 ...
Philippos's user avatar
  • 680
0 votes
1 answer
110 views

What is the shortest regular expression (REGEX) you can create for file extensions for image formats? [duplicate]

What is the shortest regular expression (REGEX) you can create for file extensions for all of the following image file formats (photographs, paintings, sketches, and drawings)? ...
Samuel Muldoon's user avatar
5 votes
5 answers
676 views

Count the size of the Levenshtein neighborhood

Input A binary string \$s\$ of length \$n\$ and a positive integer \$k \leq n\$. Output The number of binary strings with Levenshtein distance exactly \$k\$ from the string \$s\$. Example outputs Each ...
Simd's user avatar
  • 1,545
11 votes
8 answers
841 views

Shortest English prompt to produce LLM falsehood [closed]

Since programming is predicted to become natural linguisized by the unstoppable advances in LLM technology, perhaps we can code golf LLMs themselves. Produce the shortest question that is not an ...
Innuo's user avatar
  • 227
6 votes
4 answers
367 views

Sums of Euler's totient function in sublinear time

Related. Given a number \$n\$, Euler's totient function, \$\varphi(n)\$ is the number of integers up to \$n\$ which are coprime to \$n\$. That is, no number bigger than \$1\$ divides both of them. For ...
Command Master's user avatar
11 votes
26 answers
1k views

Find the smallest integer multiple of a Decimal

The Challenge Given a rational number, determine the smallest number which is a positive integer multiple of it. Eg. ...
ATaco's user avatar
  • 10.2k
3 votes
1 answer
225 views

Sokobunny I (Sokoban, but the boxes are sentient)

Sokobunny 1 You love buns! You love them so much, that you chased one down a bunburrow. The burrows are like mazes, and YOU WANT TO CATCH THE FLUFFBALLS!!!! However, the buns are smart! You can't ...
ToAskOrNotToAsk's user avatar
24 votes
22 answers
3k views

American odds to probabilities

American odds (aka moneyline odds) are numbers like \$+150\$ or \$-400\$ used to express how much a winning bet would pay out. Convert odds to a fair win probability like this: Positive odds \$+n\$ ...
xnor's user avatar
  • 144k
16 votes
6 answers
2k views

What's my score?

The question score on Stack Exchange is the total number of upvotes minus the total number of downvotes a question receives. However, the reputation gained/lost for every upvote/downvote is different (...
math scat's user avatar
  • 7,939
15 votes
3 answers
372 views

Convert numbers to dice patterns

The way points are assigned on a dice follows a regular pattern, the center dot is present if and only if the number is odd. To represent the even numbers, pairs of dots on opposite sides of the ...
bsoelch's user avatar
  • 4,781
23 votes
10 answers
2k views

How many ways to cut a number into an equation?

Too bad! I had such a beautiful equation, but I lost all my =+-*, so there is nothing left but a chain of digits, looking like a number: ...
Philippos's user avatar
  • 680
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 +...
Command Master's user avatar
24 votes
26 answers
2k views

Longest Consecutive Sequence

Description Given a list of positive integers, write the shortest code to find the number count of the longest consecutive sequence of numbers within the list. Input A list of positive integers. You ...
Aitzaz Imtiaz's user avatar
1 vote
0 answers
177 views

DP approach gives TLE [closed]

There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
BlazeRod11's user avatar
21 votes
19 answers
2k views

Simulate Round Robin Scheduling

Alternatively, guess who's doing a course on operating systems Round Robin scheduling is a way to schedule ready processes in an operating system. Each process in the queue is run for a certain amount ...
lyxal's user avatar
  • 31.7k
28 votes
9 answers
3k views

What's my type? Well... Probably

There are a lot™ of pokemon. One of the defining characteristics of pokemon is their type, of which every1 pokemon has up to two types, a primary type and an optional secondary type. There are ...
DJMcMayhem's user avatar
  • 58.8k
4 votes
6 answers
259 views

Pseudo-Quantum Bogosort [closed]

Pseudo-Quantum Bogosort Quantum Bogosort is as follows: Quantumly randomise the list, such that there is no way of knowing what order the list is in until it is observed. This will divide the ...
Pacmanboss256's user avatar
10 votes
13 answers
2k views

Decimalize a Fraction

Preamble A common pain-point when working with rational numbers and decimals is how infrequently one can represent their rational number as a clean, non-repeating decimal. Let's solve this by writing ...
ATaco's user avatar
  • 10.2k
22 votes
14 answers
2k views

Sum of consecutive nth powers

Related. Given a positive integer \$n\$, output all integers \$b\$ (such that \$1<b<n-1\$) where \$n\$ can be written as the sum of any number of consecutive powers of \$b\$. Example: Let's say \...
MTN's user avatar
  • 761
17 votes
27 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 ...
thejonymyster's user avatar
11 votes
20 answers
4k views

Add two really big numbers

Preamble We've already proven we're good at adding two numbers, but many solutions only operate on tiny numbers like 2³²-1, honestly we can do a lot better. The Challenge Given two unsigned, non-...
ATaco's user avatar
  • 10.2k
14 votes
18 answers
2k views

Golf the fast growing hierarchy

The fast growing hierarchy is a way of categorizing how fast functions are growing, defined the following way (for finite indices): \$ f_0(n)=n+1 \$ \$ f_k(n)=f_{k-1}^n(n)\$ with \$f^n\$ meaning ...
bsoelch's user avatar
  • 4,781
18 votes
20 answers
3k views

Be big more often

Related You are a manager at a large number factory. You want to show everyone your business is doing well, by showing randomly chosen samples. Unfortunately, your business is not doing that well. But ...
The Empty String Photographer's user avatar
4 votes
4 answers
520 views

We already have pipes & pattern matching at home! [closed]

Inspired by this tweet where a user stated the following: it's insane how much code would be cleaned up if JS got pipes and pattern matching i often do this since it's the best way to make use of TS ...
Asleepace's user avatar
  • 605
8 votes
6 answers
1k views

Inverse trigonometric functions

There are 3 (commonly used) trigonometric functions sin cos and tan each of these functions ...
bsoelch's user avatar
  • 4,781
6 votes
3 answers
482 views

Pick a random string at a fixed edit distance

I have string \$s\$ of length \$n\$ and some constant integer \$k\$ which is at most \$n\$. Give the fastest algorithm to sample a random string with Levenshtein distance \$k\$ from \$s\$ uniformly. ...
Simd's user avatar
  • 1,545
16 votes
5 answers
557 views

Prefix code generator

In this challenge, we consider an encoding from positive integers (up to a limit) to binary sequences. Some examples: ...
Bubbler's user avatar
  • 73.2k

15 30 50 per page
1
2 3 4 5
277