instruction_seed stringlengths 292 48.7k | found_ngrams listlengths 0 21 |
|---|---|
Introduction:
Although we have a lot of challenges where swapping two items in a list is a subtask, like Single swaps of an array; Swap to Sort an Array; \$n\$ swaps into a nop; etc., we don't have the simple challenge of just swapping two items given a list and two indices.
Input:
A list with some positive integers \$... | [] |
Prefix normal words arise in the context of binary jumbled pattern matching. A binary word \$w\$ consisting of \$0\$s and \$1\$s is said to be prefix normal * if, among all of its substrings, none contains more \$1\$s than the prefix of \$w\$ of the same length does. In other words, if \$w\$ contains \$n\$ \$1\$s then ... | [] |
Background
One kind of river-crossing problems involves two kinds of animals. One such problem reads like this: (all wordings, including animal species, are arbitrary)
A farmer has to cross a river with three chickens and three dogs. There's a boat which can only fit the farmer and at most two animals. On either side ... | [] |
Output the flattened version of the sequence A297359, which starts like the following:
1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 2, 4, 6, 4, 2, 1, 6, 10, 10, 6, 1,
1, 7, 16, 20, 16, 7, 1, 3, 8, 23, 36, 36, 23, 8, 3, 3, 11, 31, 59,
72, 59, 31, 11, 3, 1, 14, 42, 90, 131, 131, 90, 42, 14, 1,...
----------------
1,
... | [] |
Challenge
Given two integer values \$a \ge 2\$ and \$0 \le b < a\$, generate a \$(2a-1) \times (2a-1)\$ matrix consisting of the integers 0, 1, and 2 as follows:
Create a checkerboard of 0s and 1s of the given size, corners being 0.
If \$b > 0\$, overwrite the checkerboard with 2s in the X shape at the center, each le... | [] |
Challenge
Generate the 2D sequence of bits of A141727. (Allowed I/O methods explained at the bottom.)
1
1 0 1
1 0 0 1 0
1 0 1 0 1 0 0
1 0 0 1 1 0 1 1 1
1 0 1 0 0 0 0 0 1 1 0
1 0 0 1 0 0 0 0 1 1 1 0 0
1 0 1 0 1 0 0 0 1 1 0 0 1 1 1
... | [] |
There is a division-free algorithm for computing determinants published by R.S.Bird in 2011 that uses only matrix multiplications. Given a \$n×n\$ matrix \$X\$, the matrix \$Y=μ(X)\$ is another \$n×n\$ matrix which entries are given by
$$Y_{i,j} = \begin{cases}
0 & \text{ if } j < i \\
X_{i,j} & \text{ if } j > i \\
-(... | [] |
A triplet of real tensors \$(A,B,C)\$ of size \$\gamma \times \gamma \times \sigma\$ represents a matrix multiplication algorithm with \$\sigma\$ elementary multiplications iff the following function evaluates to zero:
$$ \text{error}(A,B,C) \equiv \sum_{i,j,k,l,m,n=1}^\gamma\left(\sum_{r=1}^{\sigma}{A_{ij}^r B_{kl}^r ... | [] |
Similar to this.
Input a list and rotate N numbers in it given their indices. The following example uses 1-indexing, but feel free to use either.
In other words, take a list of indices and a list of numbers:
[1,2,3,4,5,6,7]
[1,3,6]
Separate out the elements at those indices:
[ 2 4 5 7]
1 3 6
Rotate those... | [
[
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
]
] |
The objective is to make the smallest SB3 file that can simply be imported into Scratch 3.0 without a "The project file that was selected failed to load" error. Any means can be used, like editing the JSON or better compression. Here's where I am with project.json, the only file inside mine:
{"targets":[{"isStage":true... | [] |
Background
A bijective base \$b\$ numeration, where \$b\$ is a positive integer, is a bijective positional notation that makes use of \$b\$ symbols with associated values of \$1,2,\cdots,b\$.
Bijective base 2 representations of positive integers look like this:
1 -> 1
2 -> 2
3 -> 11
4 -> 12
5 -> 21
6 -> 22
7 -> 111
8 -... | [] |
Background
J has trains similar to APL's. Given a sequence of verbs (functions), three rightmost verbs are grouped to form a derived verb (a fork) recursively, until one or two verbs remain. If the sequence has odd length, the entire train is a chain of forks. Otherwise, two verbs remain at the end, forming a hook.
... | [] |
Given a sorted array of unique positive integers \$A\$ \$(A_0<A_1<\cdots<A_{n-1})\$, and an integer \$t\$, where \$A_0\le t\le A_{n-1}\$. Output the value \$i\$ such that:
If \$t \in A\$, \$A_i=t\$.
If \$t \notin A\$, \$ \left(i-\left\lfloor i\right\rfloor\right)\cdot A_{\left\lceil i\right\rceil} +\left(\left\lceil i... | [] |
Consider all arrays of \$\ell\$ non-negative integers in the range \$0,\dots,m\$. Consider all such arrays whose sum is exactly \$s\$. We can list those in lexicographic order and assign an integer to each one which is simply its rank in the list.
For example, take \$\ell=7, s=5, m=4\$, the list could look like:
(0... | [] |
Consider a linear system of equations, in \$n\$ unknowns, expressed as
$$A \textbf x = \textbf b$$
where \$A \in M_{n,n}(\mathbb Z)\$ is an \$n \times n\$ matrix of integers, \$\textbf x\$ is a column vector of unknowns \$(x_1, x_2, \dots, x_n)\$ and \$\textbf b = (b_1, b_2, \dots, b_n)\$ is a column vector of integers... | [
[
15,
609,
220,
15,
24984,
220,
15,
609,
220,
16,
609,
220,
15
],
[
609,
220,
15,
24984,
220,
15,
609,
220,
16,
609,
220,
15,
24984
],
[
220,
15,
609,
220,
16,
609,
220,
15... |
Your task is to write a short program that represents a large (infinite) ordinal, using a well-ordering of the set of positive integers. Your program will take two different positive integers and indicate which one is greater in your chosen well-ordering. The order type of the well-order is the represented ordinal. 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
]
] |
A digit small number is a positive integer \$n\$ such for any two numbers that multiply to \$n\$, their total number of digits is more than the digits in \$n\$.
In otherwords: there are no two positive integers \$a\$ and \$b\$ such that:
\$
ab = n
\$
and
\$
\left\lfloor\log_{10}(a)\right\rfloor+\left\lfloor\log_{10}(b)... | [] |
Consider the \$4\$ divisors of \$6\$: \$1, 2, 3, 6\$. We can calculate the harmonic mean of these numbers as
$$\frac 4 {\frac 1 1 + \frac 1 2 + \frac 1 3 + \frac 1 6} = \frac 4 {\frac {12} 6} = \frac 4 2 = 2$$
However, if we take the \$6\$ divisors of \$12\$ (\$1, 2, 3, 4, 6, 12\$) and calculate their harmonic mean, we... | [] |
Task :
Wonky numbers are 3-or-more digit numbers that meet one or more of the following criteria:
Any digit followed by all zeros: 100, 70000
Same digit throughout the entirety of the number : 1111, 777777777
The digits are in consecutive ascending order : 1234, 1234567890 (for 0 see below)
The digits are in consecuti... | [] |
Introduction
In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values, some also have notations for elements of enumerated types and compound values. Wikipedia
For example 1 usually represent an integer value, "Hello"... | [] |
Inspired by this Puzzling SE question: All distances different on a chess board.
Introduction
Lets define a sequence \$a(n), n\geqslant 1\$ as how many pawns can you put on a \$n \times n\$ chessboard in such a way that all the distances between two pawns are different.
Pawns are placed always in the centre of the squ... | [] |
A basis of a vector space \$V\$ is a set of vectors \$B\$ such that every vector \$\vec v \in V\$ can be uniquely written as a linear combination of the vectors in \$B\$. In other words, let \$B = \{\vec b_1, \dots, \vec b_n\}\$ be a basis of some vector space \$V\$. For every possible \$\vec v \in V\$, we can say tha... | [
[
7265,
90,
5187,
2555,
92,
856,
24984,
379,
1124,
408,
90,
5187,
2555
],
[
90,
5187,
2555,
92,
856,
24984,
379,
1124,
408,
90,
5187,
2555,
92
],
[
2555,
92,
856,
24984,
379,
1124,... |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
Related to AoC2015 Day 10.
Here's why I'm posting and not Bubbler
The Elves are playing a variation of the game called look-and-say. In plain look-and-say, they take turns making sequences by reading aloud the previous sequence and using tha... | [] |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
Related to AoC2015 Day 20, Part 1.
Here's why I'm posting instead of Bubbler and why not emanresuA
To keep the Elves busy, Santa has them deliver some presents by hand, door-to-door. He sends them down a street with infinite houses numbered ... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
],
[
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20,
11,
323
],
[
11,
220,
17,
11,
220,
18,
11,
220,
19,
11... |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
The story continues from AoC2015 Day 24, Part 2.
Here's why I'm posting instead of Bubbler
To recap: Santa gives you the list of gift packages' weights. The packages must be split into multiple groups so that each group has the same weight, ... | [
[
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
]
] |
We all know how binary conversion works: the sequence of bits
$$ b_1, b_2, ..., b_{n-1}, b_n $$
encodes the number
$$ b_1 \times 2^{n-1} + b_2 \times 2^{n-2} + ... + b_{n-1} \times 2^1 + b_n \times 2^0 $$
This gives an unambiguous representation when we limit all bits \$ b_i \$ to be only 0 or 1.
...but what if we allo... | [] |
Following the theme of strange kitchen appliances, let's talk about my microwave.
Introduction
My microwave has a keypad that is laid out like this:
30 > 15
1 2 3
4 5 6
7 8 9
+/- 0 S/M
I can press the +/- and S/M keys to switch between adding and subtracting minutes or seconds.
The microwave starts in a... | [] |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
Related to AoC2017 Day 6.
A debugger program here is having an issue: it is trying to repair a memory reallocation routine, but it keeps getting stuck in an infinite loop.
In this area, there are n memory banks; each memory bank can hold any... | [] |
Your task is to input a sequence of integers and chunk sort it. You may assume the input list can always be chunked into groups of 1, 2, and 3.
Definition
Chunk sorting (a term I made up for the purpose of this challenge) is the action of first chunking a sequence into groups of 1, 2, and 3 in a cycle and then sorting ... | [
[
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 challenge is to, given a positive integer n, count up to each digit of it, giving the effect of converging on it.
Basically, count up to the first digit of n by its place value (\$⌊\log_{10}\left(x\right)⌋\$). Then do the same for each subsequent digit, but with the values of the previous digits added.
Example imp... | [] |
The story continues from AoC2017 Day 22, Part 2.
The damn virus that was infecting a grid computing cluster now has jumped to a hexagonal computing cluster! In this cluster, the computers are connected in the honeycomb-like shape, and each computer has three neighbors.
.. .. ..
. .. .. .
.. .. ..
. .. .. ... | [
[
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... |
Challenge
Given two binary vectors (containing two consistent values of your choice) of length \$n\$ and \$m\$, output a corresponding ascii-art hitomezashi stitching pattern.
You are to fill the following pattern, where \$n\$ is the number of A-columns and \$m\$ is the number of B-rows:
A A A A A
B+B+B+B+B+B
A A A A... | [] |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
The story continues from AoC2018 Day 7, Part 2.
Why I'm pxeger, not Bubbler
As soon as you and a few Elves successfully assemble the Sleigh kit, you spot another set of the same kit not so far away. But you noticed that the last Elf is slack... | [] |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
Related to AoC2018 Day 8.
The license file for an imaginary software system is defined as follows:
The entire file is a sequence of non-negative integers.
The entire file defines a tree of nodes.
Each node in the tree has the following fiel... | [] |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
The story continues from AoC2017 Day 11.
Crossing the bridge, you've barely reached the other side of the stream when you are overcome with a sense of deja-vu. "Haven't I done this already?" But before you can finish that thought, someone r... | [] |
Consider the array [5, 6, 8, 3, 9, 4, 2, 1, 7]. If we list how far each number has moved from it's (1-indexed*) index, we have (considering absolute distance):
Array: [5, 6, 8, 3, 9, 4, 2, 1, 7]
Index: [1, 2, 3, 4, 5, 6, 7, 8, 9]
Dists: 4 4 5 1 4 2 5 7 2
We can then group the elements of the array based on th... | [
[
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
]
] |
Consider a length-\$n\$ array of positive integers.
The complement of the element with index \$i\$ is the element with index \$n - i - 1\$.
The twin of an element \$a\$ is its complement after removing all elements not equal to \$a\$.
For example, in the array [1, 2, 3, 4, 2, 1, 3, 2], the complement of the first 2 i... | [] |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
Related to AoC2020 Day 13, Part 2.
Why Bubbler isn't posting this; Why Riker isn't posting this
A shuttle bus service runs between the sea port (where you are) to the airport (where you need to go). Each bus has an ID number that also indica... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Consider some arbitrary polynomial with integer coefficients,
$$a_n x^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0 = 0$$
We'll assume that \$a_n \ne 0\$ and \$a_0 \ne 0\$. The solutions to this polynomial are algebraic numbers. For example, take the polynomial $$x^4 - 10x^2 + 1 = 0$$
We have that \$x = \sqrt 2 + \sqrt 3\$ ... | [
[
488,
264,
15159,
77,
12,
16,
92,
87,
47822,
77,
12,
16,
92
],
[
77,
12,
16,
92,
87,
47822,
77,
12,
16,
92,
488,
1124,
4385
],
[
16,
92,
87,
47822,
77,
12,
16,
92,
488... |
Let's say I have a non-empty list (array):
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
I want to incrementally slice the list into incremented amount of elements per chunk.
For this array, my desired output is:
[[1], [2, 3], [4, 5, 6], [7, 8, 9, 10]]
What would be the best way to slice the array in multiple chunks.
This is c... | [
[
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
]
] |
This challenge is one of the two challenges which were planned for Advent of Code Golf 2021, but didn't fit into the 25-day schedule.
Related to AoC2020 Day 24, Part 2.
Given a binary configuration on a hexagonal grid, output the next generation of Hexagonal Game of Life using AoC rules:
A living cell survives if it ... | [] |
Let's say I've got a list (or array) of:
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
I want to get the third Cartesian power of the above list, where we take every possible triple of elements from l.
Then I want to filter and only keep the sublists where the sum of that sublist equal to the maximum value of the list.
Then I o... | [
[
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
]
] |
Inspired by this StackOverflow post
Given a list where each element appears a maximum of 2 times, we can define it's "sortedness" as the sum of the distances between equal elements. For example, consider
[1,1,2,3,3] (array)
0 1 2 3 4 (indices)
The sortedness of this array is \$2\$. The distance between the 1s is \$1... | [] |
Inspired by this Stack Overflow post.
Given an ascending-sorted array of possibly duplicated integers, your goal is to increment each number by a counter, starting at 0, that resets for each group.
Spec:
Any numbers may be negative (but if so, they'll be at the beginning, because the array is sorted),
The array will h... | [] |
Add++, the Language of the Month, has the "collect" builtin as BC. Your task is to implement this builtin.
Consider a non-empty array, where each element is either:
A positive digit between 1 and 9 inclusive, or
A non-empty list of positive digits between 1 and 9
For example, all the following such arrays meet this ... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Input a non-empty array of positive (greater than 0) integers. Output another non-empty array of positive integers which encode the input array. Output array does not use any numbers used in the input array.
Rules
Output array should not contain any numbers used in the input array.
Both input and output array may con... | [] |
This challenge is inspired by the High throughput Fizz Buzz challenge.
The goal
Generate a list of prime numbers up to 10,000,000,000,000,000. The output of primes should be in decimal digits followed by a newline character '\n' in ascending order starting from the lowest prime 2. You may not skip a prime number or out... | [] |
Given an integer n, find the next number that follows the following requirements:
The next greater number is a number where each digit, from left to right, is greater than or equal to the previous one. For example, 1455:
1<4
4<5
5<=5
The next greater number has to be bigger than n
Testcases
10 -> 11
19 -> 22
99 -> ... | [] |
Let's define a simple function \$f\$ which takes an integer and produces a list:
\$
f(n) = [g(1),g(2),\dots,g(n)] \\
g(n) = [f(0),f(1),\dots,f(n-1)]
\$
We can then calculate the first couple of values for \$f(n)\$:
0 ->
[]
1 ->
[[[]]]
2 ->
[[[]],[[],[[[]]]]]
3 ->
[[[]],[[],[[[]]]],[[],[[[]]],[[[]],[[],[[[]]]]]]]
4 ... | [] |
Inspired by this Mathematica.SE post
Given two positive integers \$n, k\$ with \$n > k \ge 1\$, output a binary \$n\times n\$ matrix such that every row and column contains exactly \$k\$ 1s, and the leading diagonal is all zero. This is the adjacency matrix of a regular graph.
You may output any valid matrix, and it do... | [] |
Let's build a sequence of positive integers. The rule will be that the next number will be the smallest number which:
It hasn't already appeared in the sequence
Its absolute difference from the number preceding it wouldn't be equal to any previous absolute difference between consecutive elements.
Task
Your task is t... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220
]
] |
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
]
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.