All Questions
13,814
questions
-1
votes
0
answers
110
views
Add (Some) Combinatorial Games
Input: Two space-seperated strings of one of these forms:
A floating-point number, for example -1234.5678 (support of exponential notation is optional)
...
1
vote
2
answers
263
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 \$...
4
votes
1
answer
89
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 ...
12
votes
5
answers
369
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 ...
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 ...
-1
votes
1
answer
61
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 ...
20
votes
10
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 ...
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 ...
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 ...
20
votes
10
answers
905
views
Implement Subleq
Subleq is a Turing-complete esolang with only one instruction, SUBLEQ. This instruction takes in three parameters, A, B, and <...
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
...
-2
votes
1
answer
181
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 ...
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 ...
6
votes
1
answer
330
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 ...
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, ...
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:
...
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 ...
0
votes
1
answer
108
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)?
...
5
votes
5
answers
675
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 ...
11
votes
8
answers
816
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 ...
6
votes
4
answers
366
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 ...
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.
...
3
votes
1
answer
220
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 ...
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\$ ...
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 (...
15
votes
3
answers
368
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 ...
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: ...
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 +...
24
votes
25
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 ...
1
vote
0
answers
176
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 ...
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 ...
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 ...
4
votes
6
answers
258
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 ...
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 ...
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 \...
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 ...
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-...
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 ...
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 ...
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 ...
8
votes
6
answers
1k
views
Inverse trigonometric functions
There are 3 (commonly used) trigonometric functions sin cos and tan each of these functions ...
6
votes
3
answers
479
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.
...
16
votes
5
answers
554
views
Prefix code generator
In this challenge, we consider an encoding from positive integers (up to a limit) to binary sequences. Some examples:
...
16
votes
9
answers
572
views
Minimal number of jumps to reach a square
A Knight in chess moves two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of a capital L)
Given a Knight current ...
11
votes
6
answers
974
views
Spell date in Japanese
Objective
Given a date, spell it out in Romanized Japanese.
I/O Format
The input format is flexible. The output format is <month spelling> <day spelling>...
9
votes
10
answers
1k
views
Convert a Gaussian integer to its positive form
We already have a challenge for computing the GCD of two Gaussian integers, but that challenge explicitly allows to choose any of the four possible values.
Your task now is to bring the Gaussian ...
21
votes
19
answers
3k
views
Is it an Element?
𝖧ello all, I hope this finds you well.
There are 118 elements on the Periodic table at the moment, each one corresponds to the number of protons in an atom's nuclei.
Each element also has a 'symbol'. ...
7
votes
8
answers
1k
views
Compile TailwindCSS to CSS
TailwindCSS is a utility that lets one write CSS code using only HTML classes, which are then converted to CSS code with the Tailwind compiler. Ordinarily, one would write CSS in a separate file from ...
9
votes
6
answers
938
views
Calculate the Distance to a Line Segment
The Challenge
Given two vertexes and a point calculate the distance to the line segment defined by those points.
This can be calculated with the following psudocode
...
15
votes
12
answers
2k
views
Half even rounding
The round function in Python 3 will round values of the form \$k+\frac{1}{2}\$ (with \$k\$ being an integer) to the nearest even integer, which is apparently better ...