instruction_seed stringlengths 292 48.7k | found_ngrams listlengths 0 21 |
|---|---|
Imagine there are \$n\$ people \$\{a_1, a_2, \ldots, a_n\}\$ who enter a room in order and sit down in \$n\$ seats, arranged in a row. Each of these people belong to some gang, indicated by an integer \$\{1, 2, \ldots, k\}\$. These gangs hate the members of the other gangs, so they want to sit as far away from those pe... | [
[
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 well-known Urinal Protocol states that each person that takes a urinal will take the one furthest from any other taken urinal. But this fails to account for short urinals; in many cases, a person would prioritize taking a taller urinal in addition to distance.
In the real world, you might struggle to find a restroo... | [] |
The Rudin-Shapiro sequence is a sequence of \$1\$s and \$-1\$s defined as follows: \$r_n = (-1)^{u_n}\$, where \$u_n\$ is the number of occurrences of (possibly overlapping) \$11\$ in the binary representation of \$n\$.
For example, \$r_{461} = -1\$, because \$461\$ in binary is \$111001101\$, which contains \$3\$ occu... | [] |
We need to produce a block cipher round function with a 1 bit round key size and a 7 bit message size with the highest level of cryptographic security according to our measure of security.
Introduction
We are going to need new symmetric encryption functions. We are at the point where we cannot improve the performance o... | [] |
One lane is closed, the vehicles have to thread their way in according to the zip-lock system: One car from one lane, the next car from the other lane, always taking turns.
Input: Two vehicle queues, represented e.g. as strings, in which short cars are represented by individual symbols, lorries by several identical sym... | [] |
It is a well-known fact that you can colour a two-dimensional map with four colours in such a way that two countries with a common border always have different colours. There have already been enough challenges on this topic.
However, the prerequisite for this is that there must be no enclaves, i.e. non-contiguous area... | [] |
Objective
Given two non-negative integers encoded in unbounded-length Gray code, add them and output the result, where the result is also encoded in Gray code.
Gray code
There are many equivalent formulations of Gray code, but here's an intuitive one.
The Gray code encodes each non-negative integer as an infinite bit-s... | [] |
Challenge
This challenge is based on the domino effect:
Initially, each domino is located on one straight line and is in a vertical state. It can be dropped either to the left along the same straight line, or to the right. Then this domino will knock down the next one, and that one, perhaps, the other.
The dominoes are... | [] |
Given a string of ASCII text as input, encode it in BPSK31 using Varicode. You may either output an audio file in any common format, or play the audio over the device speakers. You may output at any sample rate and with any carrier frequency between 500 Hz and 2500 Hz. The sample rate and carrier frequency must be cons... | [] |
You know what a monotonic sequence is: each element is bigger than its predecessor (monotonically rising) or as its successor (monotonically falling).
Bitonic means you have two arms of the sequence, one monotonically rising, the other falling.
For example, 1,3,5,7,6,4,2 is bitonic (rising until 7, then falling until t... | [] |
In this challenge, an infinitely proportional sequence is defined as a infinite sequence of positive integers such that:
All positive integers are contained infinitely many times within the sequence.
As more and more terms are added to the sequence, for all positive integers \$n\$, the ratio of the number of \$n\$s to... | [] |
OEIS sequence A003242 comprises the numbers of Carlitz compositions for any given positive integer. This is the number of integer partitions of the integer for which no two adjacent parts are equal.
For example, for 4:
Generate the possible integer partitions (and their permutations): [1,1,1,1], [1,1,2], [1,2,1], [2,1... | [] |
Given an n non-negative integers, how many numbers must be changed so that each number x appears x times? You cannot add or remove elements, only replace them with other numbers.
For example:
1 6 23 6 9 23 1 1 6
can be turned into:
1 6 2 6 6 2 6 6 6
with 5 changes, which is optimal.
Test cases
0 => 1
1 2 3 => 1
5 5 5... | [] |
Every Brazilian citizen has a national identification number associated with them, named CPF.
This number has 11 digits (formatted as XXX.XXX.XXX-XX) and it's validated by the following (real) algorithm1:
Take the 9 most significant digits of the number. Call it c.
Multiply the n-th least significant digit of c by n+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
]
] |
I define mousetail's sequence as follows:
If the nth element of the sequence is q, then n+1 must appear q times in the sequence
The sequence is weakly monotonically increasing (i.e. no lower number may follow a higher number)
f(1)=1
I'll show an example of how this works:
the first element is 1
after the 1, come 1 2... | [] |
Historic Tetris Achievement
Blue Scuti became the first ever human to beat the classic game of Tetris on NES.
Here's the Tetris Kill Screen
Challenge
Output the following Tetris Kill Screen board (10x20 blocks)
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEEEEEEE
EEEEGGEEE... | [] |
Earlier I asked about this problem on stackoverflow (link), but now I also want to see the golfiest solutions
Problem:
Given an array of arbitrary numbers, what is the longest subarray that is repeated (appears more than once)? In case there are multiple distinct repeated subarrays that all have the longest length, the... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Consider a function \$r\$ where
$$
r(i,k)= \begin{cases}
L_{i+1}-L_i, & \text{if}\ k =0\ \text{ (1st reduction)} \\
r(i,0)-r(\lfloor \log_2{k} \rfloor,k-2^{\lfloor \log_2{k} \rfloor}) & \text{if}\ k \geq 1\ \text{ (2nd reduction)}
\end{cases}
$$
where \$k<2^i\$ and \$L\$ is a finite sequence of integers.
For example,... | [
[
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
]
] |
Definitions
The common methods to generate consecutive composites are
$$\overbrace{(n+1)! + 2, \ (n+1)! + 3, \ \ldots, \ (n+1)! + (n+1)}^{\text{n composites}}$$
$$\overbrace{n!+2,n!+3,...,n!+n}^{\text{n-1 composites}}$$
$$\overbrace{n\#+2,n\#+3,…n\#+n}^{\text{n-1 composites (Primorials)}}$$
A less common method involv... | [] |
Exposition
In this challenge, I am talking about ARM assembly language. ARM is a 32-bit RISC processor; I'll use instruction set up to architecture v6.
To load a constant ("immediate") value into a register, use
the MOV instruction:
MOV r8, #42
To load negative values, use the MVN instruction, with a bit-complement of... | [] |
Even though the concept of phat-fingered-lights-out number should be pretty self-explanatory here is a definition:
Given a nonnegative integer in binary representation a phat-fingered double-bit-flip or phatflip for short replaces a pair of adjacent, equal bits with their complement.
For example given the number 0b1110... | [] |
Input: You are given two numbers n and m.
Create the snail: Given an n >= 3, fill an n * n grid with the numbers from 1 to n * n, starting at the top left, going clockwise to the middle like this (for n = 5):
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Calculate the sum of the neightbour... | [] |
Background
As noted in this question, for all positive integers \$n>2\$ there exists at least one Egyptian fraction representation (EFR) of \$n\$ distinct positive integers \$a_{1} < a_{2} < \dots < a_{n}\$ such that $$ \sum_{k=1}^{n} \frac{1}{a_{k}} = 1. \tag{1} \label{1} $$
When \$n=3\$, for instance, we have $$ \fra... | [] |
A list \$[a_1,a_2,a_3 \cdots a_n]\$ can be uniquely represented as an unordered list of its prefixes - \$ [[a_1],[a_1, a_2], [a_1,a_2,a_3] \cdots [a_1,a_2,a_3 \cdots a_n]] \$. This can be in any order - for example, \$[1, 2, 3]\$ could be represented by any of \$[[1],[1,2],[1,2,3]]\$, \$[[3,2,1],[2,1],[1]]\$, or \$[[2,... | [] |
Challenge
Given ASCII-encoded text input of any size, detect numbers between -1,000,000,000,000,000,000 and 1,000,000,000,000,000,000 exclusive and rewrite them with thousands separators. Use commas only and ignore leading zeroes. Leave the rest of the input unchanged.
Test cases
Input
Output
Description
123
123... | [] |
Given a collection of coloured laces, what would be the probability, \$P\$, that Alice won't create any loops if, until impossible, they tie two uniformly chosen, free lace ends of differing colours together?
For the avoidance of doubt:
Each lace will be of only one colour and will have precisely two ends.
Alice does ... | [] |
I recently found this game and have been enjoying it. Basically, there is a grid of colored tiles and you act by clicking on empty spaces. When you click an empty space, the first tile (if any) in each of the four axis-aligned directions is selected. If any color appears more than once, all tiles of that color are dest... | [] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.