instruction
stringlengths
34
53.1k
Input Two positive integers a > b Output The smallest integer c >= a so that c can be factored into two parts with one part an integer power of two (that is at least two) and the other part no larger than b. Examples If b = 100 and a = 101 , then the output should be 102 as 102 is 2 times 51. For the same b, if a = 201...
"Buzzing" Bill is a well respected beaver. He is the hardest working in his home dam. He was a strong beaver and was able to lift more logs than anyone at the dam. Unfortunately Buzzing Bill's career came to an end in a tragic accident. Being such a prominent figure in his town, the Beaver newspaper wanted to write a ...
Write the shortest program or function that will determine if an input is a valid Go type. Spec This challenge will use the following simplified subset of Go types. For more information, see the Golang specification. "Primitive" types: bool int,uint,float(32|64),complex(64|128),byte,rune string *T where T is any ty...
In combinatorics, the rook polynomial \$R_{m,n}(x)\$ of a \$m \times n\$ chessboard is the generating function for the numbers of arrangements of non-attacking rooks. To be precise: $$R_{m,n}(x) = \sum_{k=0}^{\min(m,n)} r_k x^k,$$ where \$r_k\$ is the number of ways to place \$k\$ rooks on an \$m \times n\$ chessboard ...
This challenge was originally posted on codidact. At my job we have to sometimes lay out materials. Materials come in large long rolls and are cut into smaller pieces when being laid out. When we order the rolls we draw up a layout document which describes how we are going to cut them and layout the pieces. This tells...
As in this challenge, the task is to generate the vertices of a polyhedron. The polyhedron here is the one obtained by dividing a regular icosahedron's triangular faces into smaller triangles so that each edge is divided into \$b\$ segments (denoted \$\{3,5+\}_{b,0}\$ here) and projecting onto the unit sphere. Your pro...
Given a sorted list of unique positive floats (none of which are integers) such as: [0.1, 0.2, 1.4, 2.3, 2.4, 2.5, 3.2] Evenly spread out the values that fall between two consecutive integers. So in this case you would get: [0.333, 0.666, 1.5, 2.25, 2.5, 2.75, 3.5] (I have truncated the values 1/3 and 2/3 for ease of...
Two points pand q in a topological space can be separated if there are open sets U and V such that: p is an element of U and q is an element of V U and V do not have any elements in common Your task is given a topology (a set of open sets) and two points p and q (p!=q) to output sets U and V satisfying the above cond...
The title says it all; Given a number in the binary (base-2) number system, output the same number expressed in unary (base-1). You should take the binary number as a string (optionally with a separator), list, or equivalent structure of digits, using any number or digit you like for the digits. The unary output can us...
Most people would cut circular pizzas into circular sectors to divide them up evenly, but it's also possible to divide them evenly by cutting them vertically like so, where each piece has the same area (assume the pizza has no crust): Challenge Your task is to make a program or function that takes a positive integer \...
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 robbers will try to come up with their algorithm. The catch is, the 'algorithm' must be a single closed-form mathematical e...
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 robbers will try to come up with their algorithm. The catch is, the 'algorithm' must be a single closed-form mathematical e...
Braille Patterns in Unicode contains 8 dots(⣿) and occupy area U+2800-U+28FF. Given a Braille Pattern character, where the bottom two dots are not used(aka. U+2800-U+283F), shift it down by one dot. Test cases: ⠀ => ⠀ (U+2800 -> U+2800) ⠅ => ⡂ ⠕ => ⡢ ⠿ => ⣶ Shortest code wins.
Input A single positive integer \$ 10 \geq n \geq 2\$ Output A list of strings, each of length \$2n\$, satisfying the following properties. Each string will contain each of the first \$n\$ lowercase letters of the alphabet exactly twice. No letter can occur twice consecutively. That is abbcac is not allowed. No two st...
In the UTF-8 encoding bytes of the Form 10****** can only appear within multi-byte sequences, with the length of the sequence already being determined by the first byte. When UTF-8 text is split within a multi-byte UTF-8 character sequence, this prevents that the second part of the sequence is wrongly detected as anoth...
This is the cops thread of this cops and robbers challenge. The robbers thread is here. Related, but hashes numbers instead of strings and uses a different scoring system. Definitions A hash collision is when two different strings produce the same hash. Summary In this challenge, the cops will make a hash function, wit...
This is the robbers thread of this cops and robbers challenge. The cops thread is here. Related, but hashes numbers instead of strings and uses a different scoring system. Definitions A hash collision is when two different strings produce the same hash. Summary In this challenge, the cops will make a hash function, wit...
Given a sequence of integers with length \$L\$ and an integer \$1 \le N \le L\$, an "\$N\$-rich" permutation is one whose the longest strictly increasing contiguous subsequence has length exactly \$N\$. For example, let our sequence be [0, 1, 2, 3]. There is exactly one \$1\$-rich permutation, given by [3, 2, 1, 0]. By...
This is a successor to a previous challenge. Input An integer \$1 \leq n \leq 5\$. Task Your code should produce all strings that satisfy the following properties: Your string should contain exactly two each of the first \$n\$ letters of the alphabet. It should not contain the same letter twice in a row It must start ...
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 main-function if that is required by your language The subsets must not share any characters (in the native encoding of th...
How to play the duck game This is a 2-player game. First, we start with a line of blue rubber ducks (represented here as circles): Now, in each turn, the current player can turn either one blue duck or two adjacent blue ducks red. So, a valid move would be indexes 2 and 3 (0-indexed): Then, the other player cou...
This sequence is defined as Starts with 1, 2, 3 The next element of the sequence is the first number greater than the previous three that is co-prime with each of the previous 3 elements in the sequence. In other words, if the previous 3 elements are a, b, c, then the next is the first integer n>c such that gcd(a,n)=...
I have the following Haskell code to generate the the values of the Fibonacci sequence which are even as an infinite list: z=zipWith(+) g=z((*2)<$>0:0:g)$z(0:g)$(*2)<$>scanl(+)1g This works by starting with 0,2 and then defining every following term to be the sum of: twice all prior terms the previous term twice the ...
Given a positive integer n, output a number meter formatted like this: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 The input number is 20 in this example. More formally, the decimal representations of the numbers are arranged vertically, from most significant digits on the last row ...
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 a to z). Your program should take an emoji string as input and output the corresponding encrypted string. The mapping of emojis to char...
(or: Output the plural demonym.) When in Rome, do as the Romans do. This is a well-known English phrase meaning that it’s best to follow what others are doing around you — to go with the flow. Today, you're going to rewrite the phrase to fit most (Western) place names. To get the name of a group that lives within a reg...
Recently I asked for tips on improving some code-golf of mine. The code was supposed to output every third value of the Fibonacci sequence starting with 2: 2,8,34,144,610,2584,10946,46368,196418,832040 However, I made a mistake in deriving my formula, and my code output a different sequence which is accurate for the ...
Your task is to find out how often you need to "shuffle" a given list with the following operation until you get back the original list. start with a list: (1 2 3 4 5 6 7 8 9) split it into the elements at odd and even indices (1 3 5 7 9) (2 4 6 8) concatenate these two list (1 3 5 7 9 2 4 6 8) Input: A list Output: ...
Challenge You just entered a room. Here's how it looks (you are the X): |\ /| | \/ | | X | | | |----| You challenge yourself to see if you can reach where you started by following the walls. You go right until you find a wall. Then, you turn clockwise until you are facing parallel to the wall. For example, if you...
Problem You've stumbled upon a paradoxical mathematical phenomenon related to prime numbers. Consider the following scenario: You have an infinite list of prime numbers: $$2, 3, 5, 7, 11, 13, 17, 19, ...$$ Now, you decide to pair up these prime numbers in a way that each prime is paired with its consecutive prime numbe...
Brief description of the game In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. Each cell has one of five possible colours, which we will denote by the letters \$\mathrm A, \ldots, \mathrm E\$. The use...
One way to generalize the concept of a range from the integers to the Gaussian integers (complex numbers with integer real and imaginary part) is taking all numbers contained in the rectangle enclosed by the two ends of the range. So the range between two Gaussian integers a+bi and c+di would be all Gaussian integers x...
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: print(x) should print 1 print(x)print(x) should print 1 print(x)print(x)print(x) should print 2 print(x)print(x)print(x)print(x) should print 3 print(x)print(x)print(x)print(x)prin...
As the title says, given a valid chess move in algebraic notation, produce the string describing the move. Example: fxg8=Q+ -> Pawn takes g8 promotes to Queen check Bb7# -> Bishop to b7 mate Here is a list of all the keywords and their respective notation R -> Rook x -> takes N -> Knight ...
Problem You're a staircase engineer on a house and realize you only have n rectangles to create a staircase. So you are tasked with finding the number of ways to use n rectangles to tile a stairstep shape for the architects. Your task is to write a program that takes a non-negative integer n as input and calculates the...
Stevin's Notation is a way to represent decimals in a non-fractional way. The Flemish mathematician and engineer Simon Stevin is remembered for his study of decimal fractions. Although he was not the first to use decimal fractions (they are found in the work of the tenth-century Islamic mathematician al-Uqlidisi), it ...
We already have a challenge about multiplying multiply single-variable polynomials. This challenge is about multiply two polynomials with multiple variables Your task is given two multi-variable polynomials (for instance given as nested lists) to return their product. Examples (x²+x+1)*(x²+x+1)=x⁴+2x³+3x²+2x+1 (x+y)*(x...
Background Fibonacci numbers are defined as follows: $$ F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2} $$ The Zeckendorf representation is a representation of positive integers as a sum of one or more non-adjacent Fibonacci numbers, using indices 2 and higher. It is known that such a representation is unique for every posit...
Background Given an elementary cellular automaton rule number like, for example, 28 = 00011100… We can swap \$\color{red}{\text{the 2nd bit with the 5th bit}}\$ and \$\color{orange}{\text{the 4th bit with the 7th bit}}\$ to get a rule that acts the same way but mirrored horizontally. This gets us 01000110 = 70. We ca...
Given two strings \$A\$ and \$B\$ with edit (Levenshtein) distance \$x\$, find a third string with edit distance \$a\$ to \$A\$ and edit distance \$b\$ to \$B\$ so that \$a+b=x\$ and \$a=int(x/2)\$ (that is half of \$x\$ rounded down to the nearest integer). The input is the two strings \$A\$ and \$B\$ and their edit d...
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 than the rounding method taught in school Your task is to recreate this functionality: write a program of function that given a (real) number as input, out...
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 def dist(point, v1, v2): direction := normalize(v2-v1) distance := length(v2-v1) difference := point - v1 pointProgress ...
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 the HTML, and reference named classes: <!-- without Tailwind --> <p class="crazy-monologue">Crazy? I was crazy once. The...
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'. Hydrogen has 'H', Helium has 'He' and so on. I want to know about these! Challenge: Given 1 string as input, output true ...
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 integer computed by the GCD in the following normal form: The result differs from the original number by a factor of 1,i,-1 ...
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>; note the space. You can freely mix cases in output. You may output trailing newline. Mapping Months Month Spelling January Ichigatsu February Nigatsu Mar...
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 square in a chess board and an array of unavailable squares, calculate the minimum number of valid jumps required to reac...
In this challenge, we consider an encoding from positive integers (up to a limit) to binary sequences. Some examples: A. 1 -> 00, 2 -> 01, 3 -> 10, 4 -> 11 B. 1 -> 0, 2 -> 1, 3 -> 01 C. 1 -> (empty sequence) A prefix code is a coding where no code is a prefix of another. B is not a prefix code because the code for 1...
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. Your algorithm should output any of the strings with edit distance exactly \$k \leq n\$ from the input string \$s\$ with ...
There are 3 (commonly used) trigonometric functions sin cos and tan each of these functions has an inverse function You goal is to write 3 programs or functions (one for each inverse trigonometric function asin acos atan) that take a (real) number a input and return the result of the corresponding inverse trigonometric...
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 inference and pattern matching would make it less hacky const result = (() => { if (scenario1) { return { t...
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 luckily, you have a bit of ingenuity... Write a program or function that when given an array of unique, positive numbe...
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 repeated application of the function f Examples f0(5) = 6 f1(3) = f0(f0(f0(3))) = 3+1+1+1= 6 f2(4) = f1(f1(f1(f1(4)))) = 2*...
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-negative integers, add them together and return the output. Input may be taken in any convenient format (String, Array of byt...
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 shown in the following examples: Examples Given inputs 12345000 and 1233999999, the second string would have the earliest...
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 \$n=39\$. \$3^1+3^2+3^3\$ \$= 3 + 9 + 27\$ \$= 39\$ This does not work for any other \$b\$, so our output is [3]. Test cases...
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 a program to decimalize (not to be confused with decimate) them for us! The Challenge Given a fraction, check if it can ...
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 universe into O(n!) universes; however, the division has no cost, as it happens constantly anyway. If the list is not sorted, ...
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 mechanical implications to each type, and so it is very useful to know what type a given pokemon is during battle. But there's ...
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 of time (quantum), interrupted after that time (if not yet finished), and then added back to the ready queue for anothe...
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 not considering every element, and skipping an element depending on whether the previous element was selected or not. I u...
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 can assume the list is not empty and may contain duplicates. Output The length of the longest consecutive sequence of num...
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 + 4 + 7 + 14 + 28 = 56\$. This is OEIS A000203. We can now define the sum of sum of divisors as \$S(n) = \sum_{i=1}^{n}{...
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: 7512. But was it 7+5=12 or 7-5=1*2 or 7=5*1+2 or 7=5+1*2? Or are there even more valid possibilities? Your task: For a given positive integer number, return the number of true equatio...
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 center are added, which will stay present for all successive numbers. 1: O 2: 3: 4: 5: 6: O O O O O O ...
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 (eg. 10/-2 on Code Golf). Given the total reputation earned, the reputation gained by an upvote and the reputation lost ...
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\$ with \$n \geq 100\$ correspond to $$p=\frac{100}{100+n},$$ producing a probability with \$0 < p \leq 1/2\$. Negative odds...
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 catch the bun by by chasing after it, as you wait out of politeness for the buns. Taken from the game Paquerette Down the Bu...
The Challenge Given a rational number, determine the smallest number which is a positive integer multiple of it. Eg. Given: 1.25 x1: 1.25 x2: 2.5 x3: 3.75 x4: 5 Thus: Answer is 5 Clarifications Inputs will be a rational number in the range of (0,100] of which the Decimal Representation has no more than 4 ...
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 example, \$\varphi(6) = 2\$, because the only relevant numbers are \$1, 5\$. This is OEIS A000010. We can now define th...
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 arithmetic problem (we know it sucks at multiplication problems) that produces an obvious falsehood from ChatGPT with screens...
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 example gives the largest possible output for the given \$(n, k)\$ pair. k=1, s=1010, output=14 k=2, s=1010, outupt=55...
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)? .ACAD .AFD .AFP .AOM .AOMA .APNG .ASCII .AVIF .AVIFAV .BMP .BPG .CABAC .CDEC .CDR .CDRAW .CGM .CHEVC .CIEC .CIPA .CMYK .COLLADA .CRT .CWC .DEEP...
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 lowercase letters in random order like zz or gttg or abcdefghiabcdefghi. You can trust each letter appears exactly twice and...
Write a program or function that outputs all positive integers with distinct decimal digits (OEIS: A010784) Examples: 1 2 3 4 5 6 7 8 9 10 12 13 ... 96 97 98 102 103 ... 123456789 123456798 ... 9876543120 9876543201 9876543210 Rules You can output the list of numbers in any convenient format (string with separators, ...
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, you'll end up in a cycle. The objective is to output the length of this cycle. I/O format Provided that the inputted lis...
Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only. Answers meeting this extra condition are prioritised (which may be impossible): this tuple should also be insertable into a dict or set. If the extra condition is impossible, apart fr...
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 Numberphile and Alex Bellos’ Monday puzzle. This code-golf challenge is related to the square sum problem above and asks you ...
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 other number, so compare(NaN, any) = 1 and compare(any, NaN) = -1. compare(-0.0, 0.0) = -1 and compare(0.0, -0.0) = 1. Other ...
Inspired by this (off topic) post Given an array of numbers, find the largest sum over a subarray not containing two adjacent elements [1,2,3,4] -> 6 // [_,2,_,4] [1,2,3,4,5] -> 9 // [1,_,3,_,5] [2,2,1,1,2,1,1,2] -> 7 // [2,_,1,_,2,_,_,2] [3,1,4,1,5,9,2] -> 16 // [3,_,4,_,_,9,_] [9,8,7,9,9,8] ...
Subleq is a Turing-complete esolang with only one instruction, SUBLEQ. This instruction takes in three parameters, A, B, and C, all of which are memory addresses. The instruction subtracts the value in memory address A from that in memory address B, storing it in address B. If the value at B is now less than or equal t...
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 of all the 'o's that are in the array to be reconstructed. Examples Let the input array be: ['o', 'b', 'o', 'b', 'a'] ...
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 satisfies the following: its length is \$3n+2\$ for some nonnegative integer \$n\$, and it can be partitioned into \$n\...
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 outputs the input string unchanged. the program reversed outputs the input string reversed. the program palindromized outputs...
Some built-in functions in PHP return mixed types, like file_get_contents that returns both string or false. Union structs in C can be used to simulate this, but is there a way to make it polyglot, that is, can be run in both PHP and C without (major) modification? Macros is often one way. $result === false can be rep...
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 if its a palindrome (doesn't count if it's just a single digit) 4 points if it has (not for each) "800813" 5 points for ending in "420" 6 points for ...
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 the chain up to and including your own answer, but none after it in the chain. For example, if the first submission is ...
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 output "dcba", and when I run the program "dcba" it should output "abcd." This is a quine challenge, so both your forwards and reve...
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 \$x\$. As an example, if the array is [3, 0, 1, 4, 3, 6] the output should be equivalent to: 3: 0 0: 0 1: 1 4: 3 3: 3 6: ...
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. What's that? Barbrack is a numbering system I made up that can represent non-negative integers. Zero is represented wi...
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, and all the denominators differ from each other. The value of an expression of this type is a positive rational number ...
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 characters in the message and key are lowercase letters (no spaces, numbers or symbols etc.). How to decrypt the cipher Conve...
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: 1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 (index 0) 821480865132823...
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 \$q\$ outputs \$s\$ with the \$n\$th byte removed, or it does something else. Your score is the number of ways a single b...
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 answer.
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, [1, 2, 3] is a range from 1 to 3 with a skip count of 1, because there is a difference of 1 between each item, and [4, 7, 10, 13] is a range from 4 to 13 with a skip c...
In this challenge, we define the complement of a list of positive integers as all positive integers not included in that list. For example, the complement of the even numbers [2, 4, 6, 8...] is the odd numbers [1, 3, 5, 7...]. Your challenge is to, given a monotonically increasing, infinite list of positive integers, ...
Background The look-and-say sequence begins with \$1\$, each following term is generated by looking at the previous and reading each group of the same digit (eg. \$111\$ is three ones, so \$111 \rightarrow 31\$). The first few terms are $$ 1, 11, 21, 1211, 111221, 312211, \dots $$ Conway's cosmological theorem says tha...
The JavaScript compressor RegPack uses a very simple string compression algorithm. Given a piece of code, it will make a list of characters that aren't used in that code and use them to delimit repeated strings that are inserted back into the string. To show how strings are compressed, it's necessary to show how the de...
This challenge is to list out all possible words which are built from a pattern of syllables. Words are composed by joining syllables together. Syllables are composed of a number of vowels with some number of consonants optionally to the left and/or right. Your code should take in: a list of consonants a list of vowel...