instruction_seed
stringlengths
292
48.7k
found_ngrams
listlengths
0
21
Challenge Given a list of bases for positional numeral systems as input, output the lowest positive integer that when represented in those bases they have no common digits. The input list can be assumed to have two or more unique positive integers >= 2. Example For the input list of bases 2, 8, 10, 16 (binary, octal, d...
[]
An Egyptian fraction is a representation of a rational number using the sum of distinct unit fractions (a unit fraction is of the form \$ \frac 1 x \$ where \$ x \$ is a positive integer). For all[1] positive integers \$ n \ne 2 \$, there exists at least one Egyptian fraction of \$ n \$ distinct positive integers whose...
[]
Your task is simple, just remove the odd indices and double the even indices Example the input is Hello, World! and we get indices H e l l o , _ W o r l d ! 1 2 3 4 5 6 7 8 9 10 11 12 13 and remove the odd indices el,Wrd Double! eell,,WWrrdd and you are done 1-Indexing Test cases abcdef => bbddff umbrella => mmrr...
[]
The \$\text{argwhere}\$ function takes a list of values and a predicate/boolean function as arguments and returns a list of indices where the predicate function returns true in the input list. For example, argwhere([1, 2, 3, -5, 5], x -> x > 2) would produce an output of [2, 4] because those are the (0-indexed) indice...
[]
Your lab needed to simulate how a particular cell evolves over time in a 2D grid space. A sample 2D grid space below shows a single cell at the centre of the grid. 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 The cell evolution follows these rules: '0' indicates no live cell A positive number indicates a live ce...
[]
TLDR: This is the hexagonal version of Is this square symmetrical? Given a hexagonal grid, decide if it is symmetric. The shape of the grid is a regular hexagon. Each cell in the grid has two possible states. Let's only consider reflections and rotations. Here are all the possible symmetries: Reflection symmetry, wher...
[]
Your input is a non-empty set of non-empty sets of positive integers. For example: {{1}, {2, 3}, {2,4}, {1,4}} Your task is to output the maximal number of elements that can be picked from the sets with the following conditions: You can only pick at most 1 element from a set You can't pick the same element from 2 dif...
[]
1d version Given a multidimensional array of positive integers where all dimensions are the same length, animate finding the centre of it. Simply output the array, then remove the first and last items of every array within it and output it, until the length of each dimension is less than 3 and can't have the first and ...
[]
The challenge is simple, find the matching parentheses for every one of the parentheses in a given string input E.g. ()()() -> [1, 0, 3, 2, 5, 4] Always start with the ending parentheses index before the starting parentheses, which is why () becomes [1,0], not [0,1], unless the parentheses is stacked e.g. (()), where ...
[]
Rubik's Clock is a round(ish) puzzle with two flat sides. On each side, front and back, there are 9 clock faces, arranged on a 3x3 grid. In addition, there are 4 pegs (switches) in between the clock faces, and they can be set to protrude either from the front or the back. Lastly, there are 4 dials on the edge of the pu...
[]
A Steiner quadruple system \$SQS(n)\$ is a collection of subsets (blocks) of size 4 of a set \$S\$ of size \$n\$ such that every subset of \$S\$ of size 3 is in exactly one block. It is easy to show that the number of blocks is \$\frac14\binom n3\$ and that a necessary condition for an \$SQS(n)\$ to exist is \$n\equiv2...
[]
My final-year project at the National University of Singapore is on Zarankiewicz's problem: What is the maximum number of 1s in an \$m×n\$ binary matrix (\$m\$ rows and \$n\$ columns) with no \$a×b\$ minor (intersection of any \$a\$ rows and any \$b\$ columns) being all 1s? For example, the matrix below contains a \$...
[]
Your task is to check the volume of water in a pool. Your have to create a program that takes in a input that is represented by an 10 by 10 grid of integers, with heights ranging from A=1 to Z=26 from the latin alphabet. Find the volume of water each pool can hold. You have to output the volume of water that the pool c...
[]
A superpowerset (analogous to superpermutation) on \$n\$ symbols is a string over the alphabet \$\{1,2,...,n\}\$ such that every subset of \$\{1,2,...,n\}\$ appears as a substring (in some order). For instance, 12342413 is a superpowerset on four symbols because it contains 1, 2, 3, 4, 12, 13, 41, 23, 24, 34, 123, 241,...
[ [ 220, 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220 ] ]
Background In a 2d game that I play, each screen is a 2d grid of tiles with walls and walkable tiles, with the player only able to travel on walkable tiles, and being stopped by walls. When the player walks past the edge of the screen, he will travel to the adjacent screen on the map, with the player's relative screen ...
[]
Starting with a binary list (just 1s and 0s) we are going to roll a ball over it. The ball has a position and a direction. At every step the ball does the following: If the number at it's position is 1, then flip the direction. It "bounces". Flip the number, if it's 0 replace it with 1, if it's 1 replace it with 0....
[]
Make a program that outputs a sequence of integers so that every finite sequence of positive integers is a substring (continuous subsequence) of the output. For example, the following sequence satisfies the rules: 1,1,1,2,1,1,1,1,2,2,1,3,1,1,1,1,1,1,2,1,2,1,1,3,2,1,1,3,1,4,... To see the underlying pattern, let's forma...
[]
Let's define a grouping as a flat list, which is either: just 0 2 groupings followed by the literal integer 2 3 groupings followed by 3 4 groupings followed by 4 etc. (for all integers \$ \ge 2 \$) Note that 1 is not included in this definition, because otherwise groupings could be infinite. For example, these are va...
[]
A skyline is an array of positive integers where each integer represents how tall a building is. For example, if we had the array [1,3,4,2,5,3,3] this would be the skyline in ascii art: # # # ## ### ###### ####### Your task is to find the area of the largest rectangle in the skyline. In this case, the largest ...
[]
More advanced version of this The aim of this puzzle is to simulate the impact of the shock wave of bombs on a square grid. The grid initially contains cells labelled 0 along with several bombs of type A, H, or B. Display the greatest intensity of shockwaves felt at each cell after the bombs explode. The three bombs ha...
[]
The Fibonacci Sequence is a sequence of positive integers where the first two elements are 1 and the rest are the sum of the previous two. It begins \$1, 1, 2, 3, 5, 8, 13\$ and continues forever. But what if you started with numbers other than \$1, 1\$? You could start with \$3, 4\$ and have the sequence go \$3, 4, 7,...
[ [ 16, 11, 220, 16, 11, 220, 17, 11, 220, 18, 11, 220, 20 ], [ 11, 220, 16, 11, 220, 17, 11, 220, 18, 11, 220, 20, 11 ] ]
Given a undirected graph \$G\$ and a integer \$k\$, how many \$k\$-coloring does the graph have? Here by a \$k\$-coloring, we mean assigning one of the \$k\$ colors to each vertex of the graph, such that no two vertices connected by an edge have the same color. For example, the following graph can be 3-colored in 12 di...
[]
Your input is the height map of a tower. The tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example [1,5,4,3,2] is a valid input. Here is a visualization: # ## ### #### ##### 15432 Your task is to wiggle the tower. Wi...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20, 11 ] ]
Your input is a matrix (2d array) of positive integers. For example: \begin{matrix} 1 & 1 & 4 & 7\\ 1 & 3 & 5 & 6\\ 2 & 1 & 4 & 5 \\ \end{matrix} A semi-continuous transformation of this matrix is a rearranging of elements that preserves immediate neighbors. For example, we can swap the \$2\$ in the bottom left, and th...
[]
A band matrix is a matrix whose non-zero entries fall within a diagonal band, consisting of the main diagonal and zero or more diagonals on either side of it. (The main diagonal of a matrix consists of all entries \$a_{i,j}\$ for which \$i=j\$.) For this challenge, we will only be considering square matrices. For examp...
[]
You've arrived on an alien planet. The writing system, the culture and the language there are completely foreign to any language you know. But somehow they are all playing wordle already. So as a method to learn their language and culture you start playing their version of wordle. Their wordle works a little bit dif...
[]
Inspired by @emanresu A's Is it a fibonacci-like sequence? Make sure to upvote that challenge as well! We say a sequence is Fibonacci-like, if, starting from the third term (\$1\$-indexed), each term is the sum of the previous two terms. For example, \$3, 4, 7, 11, 18, 29, 47, 76, 123, 199\cdots\$ is a Fibonacci-like s...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20, 11 ] ]
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. Also look at Digit root challenge. Input: Given integers m and n which are the modular and multiplier for sequence. Outpu...
[ [ 16, 488, 220, 17, 488, 220, 18, 488, 220, 19, 488, 220, 20 ], [ 220, 16, 488, 220, 17, 488, 220, 18, 488, 220, 19, 488, 220 ] ]
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 (jokers are taken out of the deck) are put in the center. Each turn, a player can put one of their cards (which is chosen at...
[]
Your task is to make a program that decides if a real number between 0 and 1 is irrational or not. As stated, this is obviously impossible, so instead we will use the following definition: p is your program, which takes in a decimal expansion of a number (list of integers), and returns 0 (≈Rational) or 1 (≈Irrational)....
[]
A Gray code is a permutation on binary numbers where incrementing or decrementing a number only ever causes a single bit to change. For example, a Gray code for the binary numbers up to 7 (so, with 3 bits) are: 000 001 011 010 110 111 101 100 You can see that only one bit is different between each consecutive pair. Th...
[]
The Challenge The challenge is simple: given an input list a and another list b, repeat a until it is longer than b. As an example, call the repeated list ra. Then the following condition must hold true: len(b) < len(ra) <= len(b) + len(a). That is, a must not be repeated more than is required. Sample Python Implementa...
[]
My third word search related challenge in a row. :) Challenge: Brief explanation of what a word search is: In a word search you'll be given a grid of letters and a list of words. The idea is to cross off the words from the list in the grid. The words can be in eight different directions: horizontally from left-to-right...
[]
What? Let's say I have this graph: 1 \ \ 2 3 \ / \ / 4 I can represent it in 2 ways: A list of connected vertices. [[1,3],[2,4],[3,4]] A boolean matrix which shows where edges are: c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],...
[]
There are times when a large number of people need to choose something. They all want to get the stuff they choose, obviously, but it's impossible to please everyone that way, so a usual compromise is to give people three choices and try to make sure that everyone gets one of their choices. For instance, consider three...
[]
In Super Auto Pets, players build teams of animals that face off in battles to the death unconsciousness. Each animal has an Attack and Health value, and combat occurs in iterations of the following process: The front animals of each team deal damage to each other equal to their Attack at the same time. Both animals ...
[]
Input An \$m\$ by \$n\$ binary matrix, with \$m\$ and \$n\$ both at least 2. Think of the ones as gobs of melted cheese, which stretch as we expand the matrix horizontally and vertically. More precisely... Output A \$2m-1\$ by \$2n-1\$ binary matrix, constructed as follows... First insert rows of zeros between the rows...
[]
Imagine throwing a rock into a pond. You get to see perfect circles of ripples spreading out over the pond, bouncing off of each other. Of course, nothing can be as serene as that in coding, but, we can try! Given a point on a 2D array (x, y) and the dimensions of a 2D array/pond (w, h), and a "frame" count, f, return ...
[]
Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array a such that no entry is farther than k from its initial position. Example Given the array [1, 2, 3, 4, 5, 6] and k = 1, this means the entry 3 can be at following positions: [*, 3, *, *, * ,*] [*, *, 3, *, *, *] (original ...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20, 11 ] ]
Sieve of Eratosthenes is a method for finding prime numbers: take the sequence of all positive integer numbers starting from 2 then for each remaining number drop all its multiples. 2 3 x 5 x 7 x 9 x 11 x 13 x 15 x 17 x ... 2 3 _ 5 _ 7 _ x _ 11 _ 13 _ x _ 17 x ... Task Given a number \$n \ge 2\$, find the minimum amo...
[]
Background Piet is an esoteric stack-based programming language in which programs are images meant to resemble abstract paintings. To keep the challenge from being unnecessarily complex, you will not have to consider most of the colors present in Piet, which determine what instructions are executed; instead, each type ...
[]
Let's say we have a 2-D list, like the following one: \$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} \\ \color{blue}{5} & \color{blue}{6} & \color{blue}{7} & \color{red}{8} \\ \color{green}{9} & \color{green}{10} & \color{blue}{11} & \color{red}{12} \end{bmatrix} \$ Notice how the ...
[]
Inpired by recent Stand-up Maths' video. Task Wrapping a list x can be seen as inserting "line-breaks" into x every n-th element, or forming a matrix from x with n columns (feeding rows first). To be perfectly rigorous in the definition of x wrapped into a matrix, we can pad the last row with 0s. Given a list x of posi...
[]
This part is somewhat detached from the actual array manipulation side of the challenge, scroll down for an explanation that is much more array-based You've been learning how to shuffle poker chips recently, but, as you're still learning, you don't always get the perfect alternating shuffle that you're aiming for. Inst...
[]
A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is 0. For example, the matrix [[0,1,0],[0,0,1],[1,1,1]] represents the following shape: o----o |////| |////| o----o----o |////| |////| o----o----o----o |////|/...
[]
A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is 0. For example, the array [[0,1,0],[0,0,1],[1,1,1]] represents the following shape: o----o |////| |////| o----o----o |////| |////| o----o----o----o |////|//...
[]
Related challenge A band matrix is a matrix whose non-zero entries fall within a diagonal band, consisting of the main diagonal and zero or more diagonals on either side of it. (The main diagonal of a matrix \$A\$ consists of all entries \$A_{i,j}\$ for which \$i=j\$.) For this challenge, we will only be considering sq...
[]
This is different from Floating Point XOR, and more in the spirit of a comment by R.. GitHub STOP HELPING ICE on that challenge, but I thought of this idea independently. Generalized XOR The bitwise exclusive or (XOR) operation is usually considered in terms of integers, but it can be naturally generalized (extended, i...
[]
The words "center a" probably give flashbacks to any decent HTML developer. Luckily, we are not working with divs, we are working with matrices. Given a matrix where w=h, and given a "length" to extend it by, make a new matrix and center the old one in it, populating blank squares with the length. For example: m = [ [1...
[ [ 220, 16, 11, 220, 16, 11, 220, 17, 11, 220, 18, 11, 220 ] ]
King of the Hill: Greed Control What is Greed Control Greed control is a multiplayer round-based game in which in every round, a player bet a number inside a specific range, say 1~100. Say 2 people betted 100, then they'd both get 100/2 which is 50 points in the game. Basically, the players that choose the same numb...
[]
Given a set of positive integers \$ S \$, output the set of all positive integers \$ n \$ such that \$ n \$ can be made by summing a subset of \$ S \$ in more than one different way, i.e., that are the sums of more than one subset of \$ S \$. To be clear, a subset of \$ S \$ means that you can't use numbers from \$ S \...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ] ]
The Zany Car Game is a tile matching game. You are given a number of tiles, with coloured cars split into a top and bottom half. To win the game, you need to find a square arrangement of the tiles so that only whole, correctly coloured cars are formed at each tile join , like the image below. Challenge Given a square ...
[]
Inspired by the recent 3Blue1Brown video Consider, for some positive integer \$n\$, the set \$\{1, 2, ..., n\}\$ and its subsets. For example, for \$n = 3\$, we have $$\emptyset, \{1\}, \{2\}, \{3\}, \{1,2\}, \{1,3\}, \{2,3\}, \{1,2,3\}$$ If we take the sum of these subsets, we can then ask ourselves the following ques...
[]
In this question I asked you to determine if a run ascending list could be made. It was code-golf so naturally most the answers are very slow. But what if we want it to be fast. In this challenge I ask you to solve the same task except your goal will be to minimize asymptotic time complexity. Here's the challenge re...
[]
The "standard" polyhedral game dice have 4, 6, 8, 10, 12 and 20 sides. (Yes, I know that there are two 10-sided dice which together make a d100, but we're ignoring that right now.) If I want to generate a random number between 1 and \$n\$ where \$n\$ is not one of those sides, I have a couple of options. One option is ...
[]
aka. implement an easier version of 05ab1e's canvas element. Description The canvas element is used to draw ASCII lines on the screen. The (easier version of the) canvas element takes a list of integers and returns a multi-line string (or a list of strings). The integers map to the following directions: 7 0 1 ↖ ↑...
[]
Given a multi-dimensional rectangular array of non-negative integers, pad it with the minimal number of zeroes so that only zeroes are "touching the edges" of the array, in every dimension. The output must remain rectangular, have the same number of dimensions as the input, and be no smaller than the input. Example For...
[]
Say I have a ragged list, like: [ [1, 2], [3, [4, 5] ] ] And I want to iterate over each item and delete it one-by-one. However, I don't know the structure of the list. So, I have to iterate over the list, with the following algorithm: Look at the first item of the list. If it's a list, concatenate it to t...
[]
Given a multidimensional, rectangular array and a list of dimensions, such as: [ [1, 2], [3, 4] ] [3, 4] Your challenge is to extend the matrix to the dimensions given in the list. To extend an array to a length in a single direction, simply repeat its elements; for example, if we want to extend [1, 2, 3] to length...
[]
Background In the online graphing calculator Desmos, there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed "Bernard". You can see an example of it in this graph and an isolated version of it in this graph. This shape is a consequen...
[]
This is a simpler variant of my previous challenge Don't touch the walls!, as suggested by Jonah. Given a multi-dimensional rectangular array of integers between 0 and 9, output all the elements which are "touching the edges". Output is very flexible: it can be in any order, and may be flattened or partially nested, bu...
[]
For this challenge, we will define the "complement" of a list of integers A as being any list B such that the union of A and B is a list of consecutive integers with no repeats. In other words, B is the complement of A if B has all of the integers between the minimum and maximum of A which are missing from A, and B ha...
[]
Related. Given a list of 3 or more positive integers, remove every number X for which there is another number Y in the list and the average of X and Y is also in the list. In other words, if X, Y, and the average of X and Y are all in the input, neither X nor Y should appear in the output. Note: Pairs of numbers are no...
[]
Say I have a grid with some obstacles: ---- | X | | | |XX | | | ---- I can fill this with numbers, as distance from the top left corner. But, because there are obstacles in the way some cells will take further to reach than a straight line: ---- |01X5| |1234| |XX45| |7656| ---- This can be done through f...
[]
Given a list \$X\$ of 2 or more integers, output whether, for all \$n\$ such that \$0 \leq n < length(X)-2\$, there exists a pair of equal integers in \$X\$ separated by exactly \$n\$ elements. In other words: output whether, for all overlapping slices/windows of the input, there exists at least one slice/window of eac...
[]
Background In programming, there is a recursive algorithm called binary exponentiation, which allows for large integer powers to be calculated in a faster way. Given a non-zero base \$x\$ and a non-negative exponent \$n\$, the algorithm goes something like this (based on the example code from Wikipedia): Function exp_b...
[]
Background When searches return many pages of results, GitHub avoids cluttering their UI by eliding page links. Instead, their UI lets you select: Pages at the beginning of the results. Pages near the current page. Pages at the end of the results. In this way, no more than 11 page links are ever displayed at one tim...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20, 11 ] ]
In this challenge you will be given a list of positive integers which represents some range of integers which has been truncated for display. Your job is to find the missing bits and insert ellipses to show that that part has been truncated. The input will always be strictly ascending and if two consecutive values dif...
[]
If you place the positive integers together and read each set of two adjacent digits at the same time, you get: (A136414) 12, 23, 34, 45, 56, 67, 78, 89, 91, 10, 1, 11, ... However, if you squash that sequence again: 12, 22, 23, 33, 34, 44, 45, 55, 56, 66, 67, 77, 78, 88, 89, 99, 91, 11, 10, 1, 11, 11 and so on. Your...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ] ]
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 cases, yet is well enough defined that it could make a nice challenge! Explanation of pin codes and typo resistant sets...
[]
Related We start with the string a, and forever append to the string a comma followed by the string quote-escaped, where quote-escaping means doubling all quotes in a string, and then surrounding it with an additional pair of quotes. In the first few steps we will get: a a,'a' a,'a','a,''a''' a,'a','a,''a''','a,''a'',...
[]
Special String We call a binary string \$S\$ of length \$N\$ special if : substring \$S[0:i+1]\$ is lexicographically strictly smaller than substring \$S[i+1:N]\$ for \$ 0\leq i\leq N-2\$, Note: \$ S[a:b] \$ is substring \$S[a]S[a+1]...S[b-1]\$ Given a binary string \$T\$ of length \$N\$ we are interested in the fi...
[]
The exponential generating function (e.g.f.) of a sequence \$a_n\$ is defined as the formal power series \$f(x) = \sum_{n=0}^{\infty} \frac{a_n}{n!} x^n\$. When \$a_0 = 0\$, we can apply the exponential function \$\exp\$ on this formal power series: \$\begin{align} \exp(f(x)) &= \sum_{n=0}^{\infty} \frac{1}{n!} f(x)^n ...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 16, 11, 220, 16, 11, 220, 17, 11, 220, 18, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11,...
Suppose you have an array with some known set of values (e.g. a string of \$0\$ and \$1\$) and you want to get all the locations of \$1\$s. Instead of storing a list of all the indices, if the \$1\$s come in "clumps" you can sometimes save space by storing starting and ending indices of "runs" of values -- i.e. substri...
[]
Background Here on CGCC, a commonly seen subgenre is radiation-hardening – writing a program that works even if one character is deleted. A similar problem is studied in the field of coding theory: finding an encoding that can be decoded even if one symbol is deleted from the encoded string. In this challenge, we're lo...
[]
Searching for rotatable numbers, like: 68089 If you consider numbers upside-down, 6 looks like 9, 8 looks like 8, 9 looks like 6 and 0 looks like 0. The others digits (1, 2, 3, 4, 5 and 7 ) look like nothing... I wonder how many number could be rotatable between 0 and 1000! The answer is definitively 11: 0, 8, 69, 8...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ] ]
Solve the Greek Computer Puzzle Toy There is a small toy of a series of stacked dials -- loosely inspired by the Antikythera Device. The puzzle, made by Project Genius, has a series of dials that must be arranged in a particular configuration to win. In this challenge, you will write a function/program to find that sol...
[]
Given a positive input \$n\$, output all permutations of either \$\{0,1,\ldots,n-1\}\$ or \$\{1,2,\ldots,n\}\$. Examples Outputting permutations of \$\{1,2,\ldots,n\}\$. Input Output 1 [(1)] 2 [(1, 2), (2, 1)] 4 [(1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), (1, 3, 4, 2), (1, 4, 2, 3), (1, 4, 3, 2), (2, 1, 3, 4...
[]
Given an undirected graph, find out if it is a tree. A tree is an undirected graph in which there is exactly one path between any two vertices. In other word, the graph is both acyclic and connected. Input You can take input in any reasonable format. Here are some example formats: an adjacency matrix, e.g., [[0,1,1,0]...
[]
A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 + 2 + 4 + 7 + 14 = 28) are perfect. A sublime number (OEIS A081357) is a positive integer whose count and sum of divisors (including itself) are both perfect. E.g. 12 is a sublime number bec...
[ [ 16, 17, 525, 220, 16, 11, 220, 17, 11, 220, 18, 11, 220 ], [ 220, 16, 17, 525, 220, 16, 11, 220, 17, 11, 220, 18, 11 ], [ 17, 525, 220, 16, 11, 220, 17, 11, 220, ...
Given a list of positive integers \$\mathcal I=I_1,I_2,I_3,...,I_n\$ and a base \$b>1\$ return their "carry-less sum", i.e. represent \$\mathcal I\$ in base \$b\$ and sum digit-by-digit discarding carry. Worked example: I = 13, 2, 9; b = 3 In base 3: 111 + 2 + 100 ----- = 210 and back to base 10: desired out...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20, 11 ] ]
easy mode of my previous challenge A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 + 2 + 4 + 7 + 14 = 28) are perfect. A sublime number (OEIS A081357) is a positive integer whose count and sum of divisors (including itself) are both perfe...
[ [ 16, 17, 525, 220, 16, 11, 220, 17, 11, 220, 18, 11, 220 ], [ 220, 16, 17, 525, 220, 16, 11, 220, 17, 11, 220, 18, 11 ], [ 17, 525, 220, 16, 11, 220, 17, 11, 220, ...
Level-index is a system of representing numbers which has been proposed as an alternative to floating-point formats. It claims to virtually eliminate overflow (and underflow, in its symmetric form) from the vast majority of computations. The usual floating-point format internally represents a number \$x\$ in terms of a...
[]
Introduction: I'm old-fashioned and still read a physical newspaper in the morning while eating my breakfast. Although I don't like Sudoku that much, I do solve the Light-complexity ones, which are extremely easy. With these, I always try to solve all the numbers using only the Hidden Single technique†, in increasing o...
[]
In a given 2d grid of positive integers (representing different types of "bubbles"), there are one of two actions that you can do each "step". You can either: Pop an island (a connected group of bubbles - two bubbles that are diagonally adjacent are not considered connected) of the same type of bubbles, given that th...
[]
Given a relation, and a domain, output whether the relation is an equivalence relation. Context For this challenge, a relation is defined as being a set of ordered pairs that is a subset of the cartesian product of a domain with itself. That is, \$R \subset X \times X\$. For a relation \$R\$ to be an equivalence relati...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ] ]
The persistence of a number \$x = d_1d_2d_3...d_n\$, with \$d_1 \ne 0\$, under some function \$f : \mathbb N_0 \times \mathbb N_0 \to \mathbb N_0\$ is defined as the number of applications of \$f\$ to the digits of \$x\$ before it reaches a single digit integer. That is, if we have the map $$I_f: (x = d_1d_2d_3...d_n) ...
[]
Note: most of the questions that are already in existence about this topic only deal with two numbers as inputs. This question deals with any number (>1) of inputs. GCD The GCD (greatest common divisor) of a list of integers is the largest integer which divides all of the numbers in the list. For example: \$gcd(9, 12,...
[]
Given the diagonals of a matrix, reconstruct the original matrix. The diagonals parallel to the major diagonal (the main diagonals) will be given. Diagonals: [[5], [4, 10], [3, 9, 15], [2, 8, 14, 20], [1, 7, 13, 19, 25], [6, 12, 18, 24], [11, 17, 23], [16, 22], [21]] Rules The matrix will be non-empty and will consis...
[]
Carryless multiplication is an operation similar to binary long multiplication, but with XOR instead of addition: 1011 11 × 101 5 ----- 1011 0 1011 ------ 100111 39 In this challenge, you'll be given a positive integer >= 2, and must return a list of all positive integers which are carryless factor...
[]
Description All cubic equations can be solved, and every cubic has at least one solution. The goal of this challenge is to find the real solutions to a given cubic using inputs, and (obviously) the smallest program size. Rules The solution must find the real solutions of a cubic correctly, using any method. The cubic m...
[ [ 61, 18, 488, 44241, 61, 17, 488, 20716, 488, 294, 284, 220, 15 ], [ 706, 61, 18, 488, 44241, 61, 17, 488, 20716, 488, 294, 284, 220 ] ]
inspired by Longest Increasing Substring Task Given a list of non-negative integers, output the length of its longest alternating subsequence. An alternating sequence is a sequence of numbers which alternates between strictly increasing and strictly decreasing. [], [999], [9, 1], and [0, 5, 0, 3, 2, 4] are examples of ...
[]
Given an array of \$n\$ positive integers we will say its self-sum order is the number of ways to add elements from it to make \$n\$. We will count ways as distinct up to associativity. So \$1+(2+3)\$ and \$(1+2)+3\$ are not counted as separate ways to make 6, but \$2+4\$ and \$4+2\$ are counted as separate. Two sums...
[]
Determine whether a given sequence could be a winning sequence for the game shut the box. Background There are a few variants to this game, so I'll clarify the rules here. Play begins with 12 tiles (1 through 12) face up. Each turn the player rolls two six sided dice, and must then flip over one or more tile(s) which s...
[ [ 16, 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20 ], [ 11, 220, 17, 11, 220, 18, 11, 220, 19, 11, 220, 20, 11 ] ]
Ruby has a strange operator, .., called flip-flop (not to be confused with the range operator, which looks the same). Used in a loop, flip-flop takes two conditions as operands and will return false until the first operand is truthy, then return true until the second operand is truthy, whereupon it returns true one mor...
[]
From the infinite triangular array of positive integers, suppose we select every 2nd numbers on every 2nd row as shown below: $$ \underline{1} \\ \;2\; \quad \;3\; \\ \;\underline{4}\; \quad \;5\; \quad \;\underline{6}\; \\ \;7\; \quad \;8\; \quad \;9\; \quad 10 \\ \underline{11} \quad 12 \quad \underline{13} \quad 14 ...
[]
The look-say sequence is a sequence of lists of numbers where each element is the previous element with run length encoding. Run length encoding is the process of grouping together like elements and then giving the element and the size of the group for each group. So for example: 1 1 1 2 2 1 To run length encode thi...
[]
A Young diagram is a rectangular binary mask whose every row and every column are sorted in descending order. It is easy to check that every rectangular binary mask can be formed by xor-ing together a finite number of Young diagrams. This decomposition is by no means unique, but there will be a minimum number of Young ...
[]
There exists a bijection between the natural and rational numbers that works (approximately) like this: You create a 1-indexed 2-dimensional grid. In every field of this grid with position (x, y), put the number x / y. You start at (1,1) and iterate over the field in the following way: However, this task is not abou...
[]
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 tasks. For example, printing “Hello, world!” or writing a quine (a program that prints itself) couldn’t be any simpler. U...
[]