instruction_seed stringlengths 292 48.7k | found_ngrams listlengths 0 21 |
|---|---|
Four integer sequences
In this challenge, you will test four different properties of a positive integer, given by the following sequences.
A positive integer N is
perfect (OEIS A000396), if the sum of proper divisors of N equals N. The sequence begins with 6, 28, 496, 8128, 33550336, 8589869056, 137438691328, 23058430... | [] |
The input is an array (or space-separated string, as you wish), zero-indexed, consisting of one strictly increasing array and one strictly decreasing array (in this order, not other vice versa), each having a length of 2 at least. Example is:
-10 -2 4 18 38 46 28 19 10
The goal is to write the fastest algorithm to fin... | [] |
The rules are as follows:
Take in a string of integers separated by spaces. Add the first and last numbers, the second and second-last numbers, and so on.
The program must output the numbers separated by newlines.
The program must handle negative numbers, but may not handle decimals.
If an odd amount of integers are i... | [] |
Alice (A) and Bob (B) decided to have a battle.
Each combatant has 10 health.
They take turns to roll a 6 sided die for damage.
That damage is removed from their opponent's health.
In the end either Alice or Bob, will vanquish their foe.
Show me how the battle went. Outputting these codes for the actions which have ... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
Self-limiting lists
Consider a nonempty list L containing nonnegative integers.
A run in L is a contiguous sublist of equal elements, which cannot be made longer.
For example, the runs of [0,0,1,1,3,3,3,2,1,1] are [0,0], [1,1], [3,3,3], [2], [1,1].
The list L is self-limiting if for each integer N ≥ 1, the number of oc... | [] |
This challenge already describes dropsort. However, I'm kinda lazy and I really only need my array to be a bit more sorted than before, it doesn't need to be sorted all the way.
In Drop Sort, we drop every element less than any element before it. In Lazy Drop Sort, we drop every element less than the one strictly prece... | [] |
Inspired by this.
Agatha Stephendale, a sophomore who is really into raster graphics, has taken a course in linear algebra. Now she imagines matrices as rectangles, but in her artistic mind, she attaches diagonal lines to those rectangles and tries to compute traces along them. In fact, she wants to compute traces of a... | [] |
Overview
Given the integer representation of three elements in GF(2^64), give the product of the first two elements over GF(2^64) with the reducing polynomial defined as the polynomial m such that m(x) = x^64 + n(x), where n is the polynomial representation of the third element.
You want me to what?
A finite field GF(... | [] |
Your task is to accept as input two gene sequences, and a sequence of "cross over points", and return the gene sequence that results from the indicated cross overs.
What I mean by this is, say you have the sequences [A, A, A, A, A, A, A] and [Z, Z, Z, Z, Z, Z, Z], and cross over points of 2 and 5. The resulting sequenc... | [] |
In this simple challenge you are given an input array L of non-negative integers and a number of bins b greater than 0 but no more than the length of L. Your code must return a new array M whose length is b and which has binned the array L. This is easiest explained with examples.
L = [1,0,5,1] and b = 2 returns M = [1... | [] |
Introduction
For as long as programmers have been programming and as long as English teachers have been teaching, there's a controversy over the datasets called Arrays and Lists (or hashes).
Arrays have almost always had their first index at 0. Which, for the programmer, is understandable because of math. But along the... | [
[
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
]
] |
Background
IEEE 754 Double-precision floating-point format is a way to represent real numbers with 64 bits. It looks like the following:
A real number n is converted to a double in the following manner:
The sign bit s is 0 if the number is positive, 1 otherwise.
The absolute value of n is represented in the form 2**y... | [] |
Input:
A 2D array containing two distinct (optional) values.
I'll use 0 and 1 when explaining the rules. The input format is of course flexible.
Challenge:
Zeros are water, and ones are islands. In order to ensure loneliness, your task is to surround all islands with water by inserting rows and columns of zeros. You d... | [] |
Description :
Given a string of space separated binary digits or space separated booleans or an array of binary digits or array of booleans . Your job is to find the xor of each until you end up with one answer either 0 or 1. The inputs will always be valid and will only be either 0 or 1.
Example :
1 0 0 1 0 --> 0
1 0 ... | [] |
You're given the map of a cinema theatre as a boolean matrix: 0 represents a free seat, 1 - occupied. Each Finn who walks in chooses the seat farthest away (Euclidean distance) from the nearest occupied one, or if several such exist - the first among them in row-major order. Output a matrix showing the order seats will... | [] |
For a computer language, a reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label. For other computer languages, keywords can be considered as the set of the language instructions.
Challenge
Using your language of choice, write a code in the chosen language that... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
Recursively define a "valid arithmetic expression":
Any natural number is a valid arithmetic expression.
If s is a valid arithmetic expression, then so is (-s).
If p and q are valid arithmetic expressions, then so is (p+q).
In the above, a "natural number" is recursively defined as follows:
0 1 2 3 4 5 6 7 8 9 are n... | [] |
Back in the day, telephone autodialers used punched cards with one column for each digit of the number to be dialed. Columns had seven rows. The first three rows represented the numbers (1,2,3), (4,5,6), and (7,8,9) respectively. The last three rows rotated this arrangement by 90°: (1,4,7), (2,5,8), and (3,6,9). The mi... | [] |
Interleaved sequences represent an arbitrary merging of some number of sequences.
An interleaved sequence can be made by appending elements to a list one by one from some number of lists, choosing the next element from some list each time. Therefore, an interleaved sequence will contain exactly the same elements of all... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
Take the numbers 0, 1, 2, 3, 4, ... and arrange them in a clockwise spiral, starting downward, writing each digit in its own separate square.
Then, given one of four distinct and consistent ASCII characters (your choice) representing an axis, and an input integer n, output the first n terms of the sequence described by... | [
[
220,
16,
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220
]
] |
Write the shortest program or function which generates these 1000 numbers or a sequence (0- or 1-indexed) which begins with them.
[0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1,... | [] |
I've been recently playing through 'The Weaver' and I think it presents an interesting challenge for code-golf.
Premise:
The Weaver is a game wherein you are given a number of ribbons coming from 2 directions 90 degrees apart and your goal is to swap them at certain intersections to achieve a desired output.
Like th... | [] |
Today was AP exam registration day at my school, and while I was meticulously bubbling in the pages and pages of information required, the idea for this challenge hit me. So, given a string of letters and numbers, output an appropriately filled out bubble chart.
Rules:
For each character in the input string, replace t... | [] |
The input consists of i rows with neighbors information. Each ith row contains 4 values, representing the neighbor of i to the North, East, South and West directions, respectively. So each value represents a neighbor at the given direction of the ith row, starting from row 1, and can go up to 65,535 rows. The 0 value i... | [] |
This question is similar to Biggest Square in a grid.
Challenge
Given a matrix of 1 and 0 in a string format "xxxx,xxxxx,xxxx,xx.." or array format ["xxxx","xxxx","xxxx",...], You will create a function that determines the area of the largest square submatrix that contains all 1.
A square submatrix is one of equal widt... | [] |
Find the area of a region of unit cells given its perimeter loop as a sequence of 90-degree turns.
For example, take the three-cell region
XX
X
whose perimeter loop we draw
L<S<L
v ^
S R>L
v ^
L>L
Each turn is marked as left (L), straight (S), or right (R). Starting from the R, the turns are RLLSLSLL. So, given in... | [] |
Let's say that this array is how many press-ups I've achieved each day in the last 28 days:
[
20,20,20,30,30,30,30,
35,35,40,40,40,45,45,
50,50,50,50,50,50,50,
60,70,80,90,100,110,120
]
As you can see, it's taken a steep upward trend in the last week, and that's the part of this data I'm most interested in. Th... | [] |
This was inspired by a math problem I saw somewhere on the internet but do not remember where (UPDATE: The original problem was found on the math riddles subreddit with a proof provided that it is possible, also see this Math SE post), asking for a proof if the following process is possible for any arbitrary pair of in... | [] |
Let an 8x8 chessboard be represented by any two distinct values, with one value being an empty square and the other being a queen. In the following examples, I use 0s as the empty squares and 1s as queens. For example:
is given by
1 0 1 1 1 0 0 0
1 0 1 0 1 0 1 1
1 0 1 0 1 1 0 1
0 1 0 1 0 1 0 0
0 1 1 0 0 1 0 1
1 0 0 0 ... | [] |
Mölkky
Mölkky is a Finnish throwing game. The players use a wooden pin (also called "mölkky") to try to knock over wooden pins of almost similar dimensions with the throwing pin, marked with numbers from 1 to 12. The initial position of the pins is as follows:
(07)(09)(08)
(05)(11)(12)(06)
(03)(10)(04)
(01)... | [] |
Challenge
Let's imagine an N-tuple of integers between 0 and M inclusive, and let's call it F.
There are (M + 1) ** N possible Fs in total.
How many such Fs satisfy all of the following inequalities (index is one-based)?
F[n] + F[n+1] <= M for 1 <= n < N
F[N] + F[1] <= M
Write a program or function that takes two pos... | [] |
Imagine an arsonist walking around the town and picking its victims according to a very specific pattern (Or, alternatively, Imagine a bee flying around the garden and picking its flowers to pollenize according to a very specific pattern). Let's say the town is an N × N matrix, where N is an integer higher than or equa... | [] |
The 21 Hairstyles of the Apocalypse
Given a a list of numbers between 1 and 21 (or 0 and 20) output a "stitched together" drawing of the following faces (see rules for stitching information):
___ ,,, ooo === +++ ### -*~*-
(o o) (o o) ... | [] |
Given a nonempty list of positive integers \$(x, y, z, \dots)\$, your job is to determine the number of unique values of \$\pm x \pm y \pm z \pm \dots\$
For example, consider the list \$(1, 2, 2)\$. There are eight possible ways to create sums:
\$+ 1 + 2 + 2 \to +5\$
\$+ 1 + 2 − 2 \to +1\$
\$+ 1 − 2 + 2 \to +1\$
\$+ 1... | [
[
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
]
] |
Input: An array I of k positive integers. The integers will be no larger than 100 and k ≤ 100.
Output: Your code must output all possible arrays O of non-negative integers of length k with the restriction that 0 ≤ Oi ≤ Ii. To get from one array to the next you may add or subtract 1 to one value in the array. Your co... | [] |
Given this list of all the words in english and a string with s_me missi_g lett__s, find one way to fill in the letters. Do note that some words on the list contain special characters (! & ' , - . /) and numbers
Input:
This list and a string with missing letters.
The input sentence can contain or be missing any of thes... | [] |
Challenge
Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other. The value of a permutation pi is the sum of abs(pi[i] - i) for all indices i.
Examples
(1, 3, 0, 2) has value 6
(0, 2, 4, 1, 3) has value 6
(0, 2, 4, 1, 3, 5) ha... | [] |
You are probably familiar with the Fibonacci sequence where the first two terms are 0, 1 (or sometimes 1, 1) and every term after that is the sum of the previous two. It starts like this:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Sometimes, the sequence contains numbers that have a particular pattern that I find int... | [
[
220,
16,
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220
],
[
16,
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
20
],
[
11,
220,
16,
11,
220,
17,
11,
220,
18,
11... |
Consider the infinite matrix:
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 0 2 3 0 0 2 3 0 0 2 3 0 0 2 3
0 0 0 4 5 6 0 0 0 4 5 6 0 0 0 4 ...
0 0 0 0 7 8 9 10 0 0 0 0 7 8 9 10
0 0 0 0 0 11 12 13 14 15 0 0 0 0 0 11
...
Each new row of the matrix is co... | [] |
Challenge
Given a matrix of positive integers, determine if there are any "rings" of mountains. The formal definition for this challenge is: given a matrix of positive integers, is there any positive integer n for which there is a closed ring of cells in the matrix that are strictly greater than n such that all cells e... | [] |
Consider a one-dimensional sequence of numbers within a fixed range, i.e.
[1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩
The Ever-Increasing Graph* ** is a line that connects all the points in this sequence left to right, and always goes upwards or stays level. If necessary, the line wraps around from top to bottom and ... | [
[
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
]
] |
Your task is to write a program or a function that outputs n random numbers from interval [0,1] with fixed sum s.
Input
n, n≥1, number of random numbers to generate
s, s>=0, s<=n, sum of numbers to be generated
Output
A random n-tuple of floating point numbers with all elements from the interval [0,1] and sum of all el... | [] |
Given an integer matrix a and a nonnegative integer i, output a mapping b that maps the distinct values in the ith column of a to rows of a who have that value in the ith column.
You may assume that i is in the half-open range [0, num_cols(a)) (or [1, num_cols(a)] if you choose to use 1-based indices), and that all int... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
We all know that a lot of exercises only affect one half of your body, so you have to do them twice, once for each side. Such exercises have two counterparts, one for the left side and one for the right. However, there's no need to execute the two counterparts consecutively, as long as the exercises for both sides are ... | [] |
The task is taken from an MIT lecture by Prof. Devadas called You can read minds. A detailed explanation of the trick can be found in the linked video, or in this document. I'll try to explain it in simpler terms.
It turns out this was invented in the 1930's, and is known as the "Five-Card Trick of Fitch Cheney".
The ... | [] |
There's a type of n×n matrix W called the basic Weyr canonical form. Such a matrix is described by its blocks and has the following properties, using the following reference diagram:
the main diagonal blocks Wii are ni×ni matrices of the form λIni where Ini is the ni×ni identity matrix.
n1 ≥ n2 ≥ ... ≥ nr
the first s... | [] |
Definitions
The kth ring of a square matrix of size N, where 1 ≤ k ≤ ceiling(N/2) is the list formed by the elements of the kth and (N-k+1)th rows and columns, but without the first and last k-1 elements.
Example:
Matrix:
1 2 3 4 5
6 7 8 9 1
8 7 6 5 4
3 2 1 9 8
7 6 5 4 3
Delimited in rings:
+-------------------+
| ... | [] |
Given an array of numbers with length >=3 and length % 3 == 0
[1, 2, 3, 4, ...]
You will split it in sub-arrays of length 3
[[1, 2, 3], [4, 5, ...], [...
And return an array with
[0] => The amount of cases in the sub-array where all numbers are equal
[1] => In case all numbers in sub-array are not equal, the amount ... | [] |
Challenge
Given a sequence of numbers, create a function which returns the sequence steps.
Assume a sequence will be N >= 3
Sequence will repeat it steps at least once
Sequence will only contain natural numbers
Your function or program should return the shortest possible sequence of steps
Example:
Input: [1, 2, 3, 5,... | [] |
Inspiration.
Consider a list l, consisting of numbers. Define a block operation at index i on the list l to be the act of moving 3 consecutive elements starting from i in l to the end.
Example:
l, i (1-indexing) -> l (after applying block operation at index i)
[1,2,3,4,5], 1 -> [4,5,1,2,3]
[1,2,3,4,5,6,7], 3 -> [1,2,6,... | [] |
Background
Nonogram, also known as Picross or Griddlers, is a puzzle where the objective is to determine if each cell on the 2D grid should be colored or left blank, using the numbers of consecutive colored cells on each line.
The following is an example Nonogram puzzle with solution.
The problem is, some commercial N... | [] |
This challenge is really simple (and a precursor to a more difficult one!).
Given an array of resource accesses (simply denoted by nonnegative integers) and a parameter n, return the number of cache misses it would have assuming our cache has capacity n and uses a first-in-first-out (FIFO) ejection scheme when it is fu... | [
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220
]
] |
Introduction
In a private chat, a friend of mine apparently recently stumbled across a security system which has the following two restrictions on its valid pins:
Each digit must be unique (that is "1" may only appear once)
The order of the digits doesn't matter ("1234"="4321")
So to illustrate how bad this padlock s... | [] |
Problem Description
Given:
a function \$f(a, b, c, d, e) = \frac{a \times b}c + \frac de\$
an array \$x = [x_1, x_2, x_3, x_4, ..., x_n]\$ of non-distinct integers
a target value \$k\$
What is the most efficient way, in terms of worst-case \$n\$, to find 5 distinct indices \$x_a, x_b, x_c, x_d, x_e\$ from \$x\$ such ... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
First, let's talk about Beatty sequences. Given a positive irrational number r, we can construct an infinite sequence by multiplying the positive integers to r in order and taking the floor of each resulting calculation. For example,
If r > 1, we have a special condition. We can form another irrational number s as s =... | [
[
16,
11,
220,
16,
17,
11,
220,
16,
19,
11,
220,
16,
21
],
[
11,
220,
16,
17,
11,
220,
16,
19,
11,
220,
16,
21,
11
],
[
220,
16,
17,
11,
220,
16,
19,
11,
220,
16,
... |
I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back from the beginning if there are not enough items.
As usual, you can compete in any programming language and can take inpu... | [] |
The digital root (also repeated digital sum) of a positive integer is the (single digit) value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital... | [
[
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
]
] |
For the purposes of this question, a deck of cards is formatted in this way:
[
"AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD",
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "K... | [
[
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20,
11
]
] |
Background
In the game of Nim, players alternate removing "stones" from "piles": on each turn, a player must remove between one and all stones from a single pile. The object of Nim is to take the last stone or, in the misere variant, to force your opponent to do so -- however, it turns out the strategies are nearly id... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
Introduction:
Although I originally had a Dutch song in my head, where the lyrics are: "Doe 'n stapje naar voren, en 'n stapje terug" (which translated to "Take a little step forward, and a little step back"), when I searched for the full lyrics, I realized they only got back and forth, and never sideways.
So, instead ... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
According to this question a Superb Shuffle™️ is defined as a full deck of cards (including jokers) which follows this set of rules:
No two cards (except Jokers) of the same suit are adjacent.
No card (except Jokers) is adjacent to one of the same value.
No card (except Jokers) is adjacent to one of an adjacent value ... | [
[
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20,
11
]
] |
Challenge
You are given three integers as input - min_value, max_value, sample_size, that you can pass to your answer as either array or several parameters.
Your task is to output a diagram in any convenient format, that shows the frequency of numbers in the (min_value, max_value) range showing up when a random number ... | [] |
Given a pattern (string or array format) of Bits :
[0,1,1,1,0,1,1,0,0,0,1,1,1,1,1,1]
The tasks is to replace any number of consecutive 1-Bits with an ascending number sequence starting at 1.
Input
Pattern (can be received as an string or array) Example:
String: 1001011010110101001
Array: [1, 0, 0, 1, 0, 1, 1, 0, 1,... | [] |
Introduction
In the not so distant future with the AI revolution, we will need a way to solve their captchas to prove we're not humans.
This challenge was inspired by CommitStrip.
Challenge
One such captcha is the challenge of calculating the sum of all odd digits of Pi from digit 1 to digit n, including the first digi... | [] |
I work at a bakery that serves Wheat, Rye, Barley, Grain, and French bread, but the baker's a little weird - he stacks the loaves in random order, and sometimes just leaves some shelves at the end empty.
Each day, the same customer comes in and asks for one of each loaf of bread, but the tricky thing is, he's a germoph... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
A perfect square is an integer that is the square of an integer; in
other words, it is the product of some integer with itself.
Calculate the number of perfect squares below a number \$n\$ where \$n\$ will be taken as an input
Examples:
There are 9 perfect squares below 100: 1, 4, 9, 16, 25, 36, 49, 64, 81
Constrain... | [] |
Challenge:
Given a list of nonempty lists of integers, return a list of tuples of the following form: First list tuples starting with each element of the first list followed by the first element of every subsequent list, so the ith tuple should be [ith element of first list, first element of second list, ... , first el... | [] |
Description
OEIS sequence A096004 gives the
Number of convex triangular polyominoes [polyiamonds] containing n cells.
It begins:
1, 1, 1, 2, 1, 2, 2, 3, 2, 2, 2, 3, 2, 3, 3, 5
For example, a(8)=3 with the following three convex polyiamonds:
Input: 8
Output:
*---*---*---*---*
/ \ / \ / \ / \ /
*---*---*---*---*
... | [] |
Defintion
A centrosymmetric matrix is a square matrix that is symmetric about its center. More rigorously, a matrix \$A\$ of size \$n \times n\$ is centrosymmetric if, for any \$i,\: j \in ([1, n] \cap \mathbb{Z})\$ the following relation is satisfied:
$$A_{i,\:j}=A_{n+1-i,\:n+1-j}$$
Examples of such matrices
Here is a... | [] |
...or Toroidal Moore Neighbourhoods
Given positive integers h, w and a non-negative integer i, return all of the indices surrounding i.
You are to assume a matrix consisting of h rows of w elements, numbered from lowest, in the top left-hand corner, to highest, in the bottom right-hand corner, and return, in any reaso... | [] |
Challenge
Given nine numbers, a, b, c, d, e, f, g, h, i, as input which correspond to the square matrix:
$$\mathbf{M} = \begin{pmatrix}a& b& c\\ d& e& f\\ g& h& i\end{pmatrix}$$
Find the inverse of the matrix, \$\mathbf{M}^{-1}\$ and output its components.
Inverse Matrix
The inverse of a matrix 3 by 3 obeys the followi... | [] |
Challenge
Given a list of integers and a velocity, \$v\$, implement a sorting algorithm which simulates a program sorting the list from smallest to biggest at the given velocity.
Einstein's Theory of Special Relativity
What do I mean? Well assume your program takes a time, \$T\$, to sort a particular list. If you ran t... | [] |
This is a 2-dimensional version of this question.
Given a non-empty 2-dimensional array/matrix containing only non-negative integers:
$$ \begin{bmatrix}
{\color{Red}0} & {\color{Red}0} & {\color{Red}0} & {\color{Red}0} & {\color{Red}0} \\
{\color{Red}0} & {\color{Red}0} & 0 & 1 & 0 \\
{\color{Red}0} & {\color{Red}0} & ... | [] |
Motivation: Sometimes certain items in a list don't count towards your totals. For example, counting plane passengers in rows, where babies sit on a parent's laps.
Challenge: write a program to split a list of items into chunks. Each chunk (except possibly the last) is the same size, where size is defined as the number... | [] |
I'm trying to get the shortest way (character possible) to obtain List 3.
List 1 and List 2 are already given to me as arguments and are the same length.
l1 = [1, 2, 3, 4, 5]
l2 = ['a', 'b', 'c', 'd', 'e']
And List 3 should look like (yes, it needs to be a list):
l3 = ['a', 1, 'b', 2, 'c', 3, 'd', 4, 'e', 5]
| [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Input
A non-empty binary matrix consisting of 3x3 sub-matrices put side by side.
Task
Your task is to identify valid dice patterns (as described below) among the 3x3 sub-matrices. Each valid pattern is worth the value of the corresponding dice. Invalid patterns are worth 0.
Output
The sum of the valid dice values.
Dice... | [] |
You will be given a sequence of memory requests and a cache size. You must return the least possible number of cache misses under any cache replacement strategy.
An optimal strategy is Belady's algorithm, which you can use if you want to.
A caching system works as follows: The cache starts out empty. Memory requests c... | [
[
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20,
11
]
] |
This challenge is based on a sandbox post by user48538. Since he is no longer active on this site, I took over this challenge.
apgsearch, the distributed soup search program for Conway's Game of Life and the search results database, Catagolue use apgcodes to classify and denote patterns. apgcodes themselves use the ex... | [] |
Topically related.
Objective: Given a matrix of positive integers \$M\$, output the smallest centrosymmetric matrix which contains \$M\$ (this matrix may contain non-positive integers as well).
A centrosymmetric matrix is a square matrix with rotational symmetry of order 2—i.e. it remains the same matrix after rotating... | [] |
Not to be confused with Least Common Multiple.
Given a list of positive integers with more than one element, return the most common product of two elements in the array.
For example, the MCM of the list [2,3,4,5,6] is 12, as a table of products is:
2 3 4 5 6
---------------
2 | # 6 8 10 12
3 | # # 12 15 ... | [] |
When you roll a die, you have a 6:1 chance of any given option.
There's a bookmaker taking bets on die rolls. He owns £20 at the start of the game.
The bookmaker offers odds of 4:1, but gamblers take it, because there's money on offer.
There are 10 gamblers. A, B, C, D, E, F, G, H, I, and J. Each gambler owns 10 pounds... | [
[
425,
11,
356,
11,
422,
11,
468,
11,
434,
11,
479,
11,
472
],
[
11,
422,
11,
468,
11,
434,
11,
479,
11,
472,
11,
358,
11
],
[
11,
356,
11,
422,
11,
468,
11,
434,
11,
... |
Let \$L\$ be a list of positive integers with no particular ordering, and which can contain duplicates. Write a program or function which outputs a list of positive integers \$M\$ (whose ordering is unimportant) such that merging \$L\$ and \$M\$ results into the smallest list which can entirely split into identical ran... | [
[
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
]
] |
Introduction:
(Source: Wikipedia)
When we look at a rainbow it will always have the colors from top to bottom:
Red; orange; yellow; green; blue; indigo; violet
If we look at these individual rings, the red ring is of course bigger than the violet ring.
In addition, it's also possible to have two or even three rainbow ... | [] |
Honestly, I can't believe this hasn't already been asked, but here it is
Background
Given a simple undirected planar (the graph can be drawn in the plane without intersections) graph, it is a proven theorem that the graph is 4-colorable, a term we will explore in a bit. However, it's far easier to 5-color a graph, whic... | [] |
Background
Consider the following sequence (A051935 in OEIS):
Start with the term \$2\$.
Find the lowest integer \$n\$ greater than \$2\$ such that \$2+n\$ is prime.
Find the lowest integer \$n'\$ greater than \$n\$ such that \$2 + n + n'\$ is prime etc.
A more formal definition:
$$a_n=\begin{cases}2 & \text{if }n=0 ... | [
[
64,
62,
16,
11,
264,
62,
17,
11,
1124,
67816,
11,
264,
1089
]
] |
Okay, so I saw this in a meme and decided it'd be the perfect code golf challenge:
I prefer to increase the side of my indents according to the Fibonacci sequence:
class Kls
def method
t = Time.now
if t.hour >= 12
puts "It's afternoon"
if t.hour == 18
puts "It's time for your meal of:"
%w(bre... | [] |
Introduction
There is a group of people that have to cross a rickety bridge that can only support two people at a time. It is a dark and foggy night, but unfortunately, the group only has one lamp. The bridge must be crossed by an individual or pair that is holding the lamp. When a pair is traveling together, they must... | [] |
Given a non-negative integer, \$n\$, yield the \$(n^2)^\text{th } n\$-gonal number.
Further Detail:
The \$x\$-gonal numbers, or polygonal numbers, are also known as the two-dimensional figurate numbers.
Many people will be familiar with the triangular numbers, these are the \$3\$-gonal numbers:
$$F(3,n)=\sum_{i=1}^{n}(... | [] |
Find the runs inside an array
A run is defined as three or more numbers that increment from the previous with a constant step. For example [1,2,3] would be a run with step 1, [1,3,5,7] would be a run with step 2, and [1,2,4,5] is not a run.
We can express these runs by the notation i to j by s where i is the first numb... | [
[
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
]
] |
You run a political website, and have determined that people have a better intuitive understanding when the chance of winning or losing an election is expressed as a ratio ("5 in 7") than when it is expressed as a percentage ("71%").
But you also don't want to display confusing ratios like "58 in 82", you'd like them ... | [] |
Given an N-dimensional orthogonal (non-ragged) array of non-negative integers, and an indication of which dimensions to reverse, return the array but reversed along those dimensions. The indication may be given as a Boolean list of length N or a list of a subset of the first N dimensions indexed from 0 or 1.
Please sta... | [] |
Introduction:
Inspired by this comment of @MagicOctopusUrn on @Emigna's 05AB1E answer for my "It was just a bug" challenge:
8F9ÝÀNð×ý}».∊ I done did made a spaceship maw! And I was all excited about suggesting a 12-byte edit. – Magic Octopus Urn Jul 17 '17 at 20:10
Which is a 05AB1E (legacy) program resulting in this... | [] |
It is 20th anniversary of Casio's S-VPAM calculators and it is worth celebrating.
Task: Process input string as Casio S-VPAM calculator does. The infix notation and precedence of mathematical operations must be followed. Angle values are expected in radians. Since there were multiple updates, sin 15, sin15 and sin(15 a... | [] |
The Dihedral group \$D_3\$ represents the symmetries of an equilateral triangle, using the identity (represented by id), rotations (represented by r1 and r2), and reflections (represented by s0, s1, and s2).
Your task is to compute the composition \$yx\$ of the elements \$x, y \in D_3 \$. They are given by the Cayley ... | [
[
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
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220... |
Introduction
For the purposes of this challenge, we will define the neighbours of an element \$E\$ in a square matrix \$A\$ (such that \$E=A_{i,j}\$) as all the entries of \$A\$ that are immediately adjacent diagonally, horizontally or vertically to \$E\$ (i.e. they "surround" \$E\$, without wrapping around).
For peda... | [] |
Challenge:
Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer).
An example:
Input: 7888885466662716666
The longest subsequence of a single digit would be 88888 (7[88888]5466662716666) with a length of 5. ... | [] |
Edit: I haven't played D&D before so when I initially made this question I didn't properly research it. I apologize for this, and I'm making a few edits that might invalidate answers to stay as true as possible to the dnd 5e rules. Sorry.
A D&D fan from a recent Hot Network Question seems to have some trouble working ... | [
[
220,
16,
17,
11,
220,
16,
19,
11,
220,
16,
21,
11,
220
]
] |
Definitions
Quadratic residues
An integer \$r\$ is called a quadratic residue modulo \$n\$ if there exists an integer \$x\$ such that:
$$x^2\equiv r \pmod n$$
The set of quadratic residues modulo \$n\$ can be simply computed by looking at the results of \$x^2 \bmod n\$ for \$0 \le x \le \lfloor n/2\rfloor\$.
The challe... | [
[
220,
16,
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220
]
] |
The ChatRoom is here
I love playing the card game BS, but sometimes, it just doesn't have enough oomph for my short attention span. Instead, let's play some Russian BS.
Rules
Here is a quick guide to the rules.
The game begins with a random player declaring the card type of the round (out of 14 options: A,2,3...10,J,Q... | [] |
In this task your code will be given an integer \$n\$ as input. Your code should then output the greatest number of multiples of \$3\$ that can be concatenated (in base \$10\$) to form \$3n\$ (with no leading zeros). For example if you were given \$26042\$ as input,
\$26042\times3=78126\$
and \$78126\$ can be made ... | [] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.