instruction_seed stringlengths 292 48.7k | found_ngrams listlengths 0 21 |
|---|---|
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... | [] |
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 ... | [] |
Intro
A friend posed this question today in a slightly different way - "Can a single [Python] command determine the largest of some integers AND that they aren't equal?".
While we didn't find a way to do this within reasonable definitions of "a single command", I thought it might be a fun problem to golf.
Challenge
"R... | [] |
Input:
An integer n in the range 2 <= n <= 10
A list of positive integers
Output:
Convert the integers to their binary representation (without any leading zeroes), and join them all together.
Then determine all binary substrings that form a 'binary fence' using n amount of fence posts. The spaces (zeros) between each... | [] |
Introduction
Large meetings waste working time. Our aim is to split a large meeting into a number of smaller meetings, so the average number topics that a person discusses is minimized but every person has to be in every meeting they are interested in.
Input
Given is a function from a set of topics \$T\$ to a set of pe... | [] |
From this stackoverflow question
Given a 2D array of size \$ M \times N \$, output the values in a anti-clockwise fashion. The output must start from the outside to the inside and the initial point always is going to be \$(0,0)\$.
Example Given:
$$ \begin{bmatrix} \color{blue}1&\color{red}2&\color{red}3&\color{red}4 \\... | [
[
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
]
] |
Idea:
Consider a 2-bit bitmap of arbitrary side-lengths overlaid on a coordinate grid and imaged with random data (1's represent an element of the image, 0's represent the "blank" canvas background):
y x—0 2 4 6 8 10 14 18
|
0 0000000000111100000000
0000000011111110000000
2 0000111111111111000000
0000... | [] |
Consider an array A of length n. The array contains only positive integers. For example A = (1,1,2,2). Let us define f(A) as the set of sums of all the non-empty contiguous subarrays of A. In this case f(A) = {1,2,3,4,5,6}. The steps to produce f(A) are as follows:
The subarrays of A are (1), (1), (2), (2), (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
]
] |
This question has a similar set up to Find an array that fits a set of sums although is quite different in its goals.
Consider an array A of length n. The array contains only positive integers. For example A = (1,1,2,2). Let us define f(A) as the set of sums of all the non-empty contiguous subarrays of A. In this cas... | [] |
Input
Two lists with binary values (list_a, list_b) of equal length=>3.
Output
Two lists with binary values (smoothed_a, smoothed_b) with minimal Forward Difference while keeping the same sum before and after processing sum(list_a) + sum(list_b) == sum(smoothed_a) + sum(smoothed_b).
Forward Difference being the absolut... | [] |
Isn't it annoying when you're taking a picture, but the background detracts from the actual substance of the image? I'd say it is. I need to know how much I should crop so that I get rid of this problem! But - as usual - I am quite lazy, so I need someone to do this for me...
Task & Rules
Given a binary matrix represe... | [] |
Inspired by this StackOverflow question.
Input:
We'll take three inputs:
A delimiter-character D to split on
A character I between two of which we ignore the delimiter character (I know, that sounds vague, but I'll explain it below)
A string S
Output:
A list/array containing the substrings after the split.
Example:
I... | [] |
(thanks to @JonathanFrech for the title)
Challenge
Write a program or function that, given a collection of positive integers \$S\$ and a positive integer \$n\$, finds as many non-overlapping subcollections \$T_1, T_2, ..., T_k\$ of \$S\$ as possible, such that the sum of every \$T_m\$ is equal to \$n\$.
Example
Given \... | [
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220
]
] |
There is a "sorting algorithm" sometimes called Stalin sort in which in order to sort a list you simply remove elements from the list until it is sorted in increasing order. For example the list
[1, 2, 4, 5, 3, 6, 6]
When "sorted" using Stalin sort becomes
[1, 2, 4, 5, 6, 6]
The three was removed because it was out ... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Inspired by "You had me at hello"
Introduction
For those who don't know, hexadecimal is a base system like decimal. Contrary to decimal however, it uses 16 (hence the name) digits instead of 10.
Here are the first few numbers while counting up in hexadecimal to maybe give you a feel of things, although you should proba... | [
[
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... |
Given an array of integers a which contains n integers, and a single integer x; remove the fewest amount of elements from a to make the sum of a equal to x. If no combinations of a can form x, return a falsy value.
As pointed out in a comment this is the maximum set with a sum of x, excuse my lesser math brain. I forg... | [] |
Problem A3 from the 2008 Putnam competition says:
Start with a finite sequence \$a_1, a_2, \dots, a_n\$ of positive integers. If possible, choose two indices \$j < k\$ such that \$a_j\$ does not divide \$a_k\$, and replace \$a_j\$ and \$a_k\$ by \$\gcd(a_j, a_k)\$ and \$\text{lcm}(a_j, a_k)\$, respectively. Prove 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
],
[
64,
62,
16,
11,
264,
62,
17,
11,
1124,
678... |
Background
A number n can be described as B-rough if all of the prime factors of n strictly exceed B.
The Challenge
Given two positive integers B and k, output the first k B-rough numbers.
Examples
Let f(B, k) be a function which returns the set containing the first k B-rough numbers.
> f(1, 10)
1, 2, 3, 4, 5, 6, 7, 8,... | [
[
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 5-card magic trick involves a magician whose assistant gives them 4 shown cards and a hidden one, in this order, and the magician must guess the hidden one.
WARNING: Solution below! Leave now or get spoiled with it.
The solution
The trick here is that the five cards are given in a specific order!
\$c_1,...,c_5\$ a... | [] |
This is a follow up to Count arrays that make unique sets . The significant difference is the definition of uniqueness.
Consider an array A of length n. The array contains only positive integers. For example A = (1,1,2,2). Let us define f(A) as the set of sums of all the non-empty contiguous subarrays of A. In this c... | [] |
Given two integers, output the two integers, and then the range between them (excluding both).
The order of the range must be the same as the input.
Examples:
Input Output
0, 5 -> [0, 5, 1, 2, 3, 4]
-3, 8 -> [-3, 8, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
4, 4 -> [4, 4]
4, 5 -> [4, 5]
8, 2 ->... | [
[
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... |
Consider an array A of length n. The array contains only integers in the range 1 to s. For example take s = 6, n = 5 and A = (2, 5, 6, 3, 1). Let us define g(A) as the collection of sums of all the non-empty contiguous subarrays of A. In this case g(A) = [2,5,6,3,1,7,11,9,4,13,14,10,16,15,17]. The steps to produce g(A... | [] |
Matlab has a useful command for visualizing data: plot. It draws data points using "markers" in 2-D space, connecting them with lines; however, for this challenge, let's ignore the lines and use only markers. In fact, only one marker.
Input: one of Matlab's marker symbols: . o x + * s d v ^ < > p h
Output: correspondin... | [] |
Given a non-empty rectangular array of integers from 0 to 9, output the amount of cells that are 8 and do not have a neighbour that is 8. Neighbouring is here understood in the Moore sense, that is, including diagonals. So each cell has 8 neighbours, except for cells at the edges of the array.
For example, given the in... | [] |
Shorter version of Skyscrapers Challenge
Task
Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the heights such that exactly k buildings are visible.
Any building will hide all shorter or equal height buildings behind it.
Any format for input and output is va... | [] |
The Dirichlet convolution is a special kind of convolution that appears as a very useful tool in number theory. It operates on the set of arithmetic functions.
Challenge
Given two arithmetic functions \$f,g\$ (i.e. functions \$f,g: \mathbb N \to \mathbb R\$) compute the Dirichlet convolution \$(f * g): \mathbb N \to \m... | [
[
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
]
] |
As with most APL symbols, ⍉ has different meanings when called with one argument (transpose) versus two arguments (dyadic transpose / reorder dimensions). This challenge concerns the latter, which acts similarly to numpy.moveaxis in Python or permute in MATLAB, but is more powerful.
order ⍉ A when order has distinct en... | [] |
Given integer n, calculate a set of n random unique integers in range 1..n^2 (inclusive) such that the sum of the set is equal to n^2
Random, in this case, means uniformly random between valid outputs. Each valid output for a given n must have a uniform chance of being generated.
For example, n=3 should have a 1/3 chan... | [
[
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
20,
11
]
] |
This is a restricted-source, kolmogorov-complexity, code-golf challenge to produce a fixed output with no input.
The output format, however, is flexible - it may be printed to standard out, printed to standard error, returned as a list of characters, returned as a list of bytes, or returned as a list of integers. If yo... | [
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220
]
] |
Here are the annual returns for a hypothetical S&P 500 stock index fund for each calendar year from 1928 to 2017, expressed as a multiplier. So in 1928 you might say "the index went up by 37.88%" which I've represented here by 1.3788.
1.3788, 0.8809, 0.7152, 0.5293, 0.8485, 1.4659, 0.9406, 1.4137, 1.2792, 0.6141, 1.25... | [
[
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... |
For nandgame fans: Please try out DPD to decimal in logic gates too!
Background
Densely packed decimal (DPD) is a way to efficiently store decimal digits in binary. It stores three decimal digits (000 to 999) in 10 bits, which is much more efficient than naive BCD (which stores one digit in 4 bits).
Notations
The lo... | [] |
The task
Given the set
$$S = \left[{1,2,3,4,5,6,7,8}\right]$$
and an integer
$$0 \leq N < 2^{|S|}$$
find the Nth subset.
Input/Output
N is given as an unsigned integer on stdin. You must print the Nth subset in a format suitable for your language (this may include [1,2,3],{1,2,3},[1, 2, 3],1 2 3,1,2,3 etc. for as long... | [] |
Peg solitaire is a popular game usually played alone. The game consists of some number of pegs and a board which is divided into a grid - usually the board is not rectangular but for this challenge we will assume so.
Each valid move allows one to remove a single peg and the goal is to play in a way, such that there is ... | [] |
Inspired by recent popularity of nandgame on TNB, and my own previous challenge.
Background
Densely packed decimal (DPD) is a way to efficiently store decimal digits in binary. It stores three decimal digits (000 to 999) in 10 bits, which is much more efficient than naive BCD (which stores one digit in 4 bits).
Convers... | [] |
Summary
A teacher was told to prepare word problems for the students. She is given a list of equations and told to write them as the corresponding word problem. However, she is very lazy, so she doesn't put much creativity into it. Instead, she simply writes it literally. For example, when she reads 1+1, she writes one... | [] |
Goal
The goal of this challenge is to produce a function of n which computes the number of ways to partition the n X 1 grid into triangles where all of the vertices of the triangles are on grid points.
Example
For example, there are 14 ways to partition the 2 x 1 grid, so f(2) = 14 via the following partitions
where t... | [] |
Challenge
Mark is a student who receives his N marks in a concatenated way in a one single line.
The challenge is to separate his marks, knowing that each mark can only be 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10.
Input
N natural number and one line.
Output
A set of natural numbers.
Example
N, One line-----... | [] |
Given an input n, write a program or function that outputs/returns the sum of the digital sums of n for all the bases 1 to n.
$$n + \sum_{b=2}^n \sum_{i=0}^\infty \left\lfloor \frac{n}{b^i} \right\rfloor \bmod b$$
Example:
n = 5
Create the range [1...n]: [1,2,3,4,5]
For each element x, get an array of the base-x digi... | [] |
Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length.
(Basically implementing the Haskell function inits.)
Details
The input list contains numbers (or another type if more convenient).
The output must be a list of lists.
The submission can, but does not... | [] |
Problem:
Find the number of leading zeroes in a 64-bit signed integer
Rules:
The input cannot be treated as string; it can be anything where math and bitwise operations drive the algorithm
The output should be validated against the 64-bit signed integer representation of the number, regardless of language
Default code... | [] |
For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows:
Task description
Given square 2D image A with side 2^^N, (N>0), with common Z-order, or row-major representation of pixels in RAM. I need to run ... | [] |
Background
OEIS sequence A272573 describes a spiral on a hexagonal grid as follows:
Start a spiral of numbers on a hexagonal tiling, with the initial hexagon as a(1) = 1. a(n) is the smallest positive integer not equal to or previously adjacent to its neighbors.
The sequence begins
1, 2, 3, 4, 5, 6, 7, 4, 6, 8, 5, 9,... | [
[
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 Korean language has two sets of numerals, a native Korean numerals and Sino-Korean numerals.
The native Korean numerals are mostly used for numbers under 100, such as age and time.
The Sino-Korean numeral system, which is based on the Chinese numeral system as its name says, is used in most of the time.
It uses 4-d... | [] |
Given a list of floating point numbers, standardize it.
Details
A list \$x_1,x_2,\ldots,x_n\$ is standardized if the mean of all values is 0, and the standard deviation is 1. One way to compute this is by first computing the mean \$\mu\$ and the standard deviation \$\sigma\$ as
$$ \mu = \frac1n\sum_{i=1}^n x_i \qquad ... | [] |
Imagine we have some polyomino and would like to uniquely identify them, however the polyominos can be rotated, so blindly hashing them won't give us the same fingerprint for a piece and a rotation thereof (in general).
For example if we have the L-tetromino
x
x
xx
we would like it to have the same fingerprint as any ... | [] |
If 1 is not counted as a factor, then
40 has two neighboring factors (4 and 5)
1092 has two neighboring factors (13 and 14)
350 does not have two neighboring factors
(out of its factors 2, 5, 7, 10, 14, 25, 35, 50, 70, and 175,
no two are consecutive)
The proportion of positive integers that have this property
is the... | [] |
Tournament over!
The tournament is now over! The final simulation was run during the night, a total of \$3*10^8\$ games. The winner is Christian Sievers with his bot OptFor2X. Christian Sievers also managed to secure the second place with Rebel. Congratulations! Below you can see the official high score list for the to... | [] |
Input
A binary matrix \$M\$ representing the walls of a dungeon.
The position \$(x,y)\$ of the player within the dungeon.
The direction \$d\$ that the player is currently facing (0 = North, 1 = East, 2 = South, 3 = West)
Output
A pseudo-3D representation of the walls that are in the field of view of the player, as an... | [] |
This is a "counterpart" of another puzzle, Eight coins for the fair king on Puzzling.SE.
You can read the above puzzle for the background. The details about this puzzle are as follows.
A set of 8 kinds of coins of different values are created, the king wants you to find out the maximum N such that any number of price f... | [
[
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
]
] |
Let's define the a function on natural numbers \$n\$, written as base 10 digits \$d_k\; d_{k-1}\; \dotsc\; d_1\; d_0\$, as follows:
As long as there are equal adjacent digits \$d_i\;d_{i-1}\$, replace them by their sum \$d_i+d_{i-1}\$ from left to right. If there were any such digits, repeat the same procedure.
In othe... | [] |
Your task is to determine the length of the longest descent down a "mountain" represented as a grid of integer heights. A "descent" is any path from a starting cell to orthogonally adjacent cells with strictly decreasing heights (i.e. not diagonal and not to the same height). For instance, you can move from 5-4-3-1 but... | [] |
TL;DR for those not interested: Look at the test cases at the bottom. Have a program/function that outputs the 2D list displayed for the given input.
Introduction:
On November 15th, 2018 puzzle designer Raphaël Mouflin revealed his Triangularity puzzle. Here is a picture of that puzzle:
As you can see, the shape is a ... | [] |
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
Examples
[] → []/[]
[42] → [0]/[1]
[7,7,7] → [0,1,2]/[1,2,3]
[10,20,30] → [0,0,0]/[1,1,1]
[5,12,10,12,12,10] → [0,0,0,1,2,1]/[1,1,1,2,3,2]
[2,7,1,8,2... | [] |
Input:
An integer n
Two equal-sized square matrices (with their width/height being a multiple of n)
Output:
One of two distinct values of your own choice, one being for truthy results and one for falsey results (so yes, 1/0 instead of true/false are valid outputs for languages like Java, even though they're not consi... | [] |
Given a binary 3D array, for each layer, cyclically rotate up each of its columns as many steps as indicated by the binary encoding of the columns of the layer above it, and then cyclically rotate left each of its rows as many steps as indicated by the binary encoding of the rows of the layer below it.
There will alway... | [] |
This challenge is based on the following puzzle: You are given an n by n grid with n cells marked. Your job is to the partition the grid into n parts where each part consists of exactly n cells, each containing exactly one marked cell.
Example
Here is a puzzle on the left and its (unique) solution on the right:
Chall... | [] |
Introduction
Inspired by the very recent video The Trapped Knight - Numberphile, I came up with a challenge.
The trapped knight sequence is a finite integer sequence of length 2016, starting from 1, and has the following construction rules:
Write a number spiral in the following manner:
17 16 15 14 13 ...
18 5 4 3... | [
[
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
]
] |
A flow network is a directed graph G = (V, E) with a source vertex s ϵ V and a sink vertex t ϵ V, and where every edge (u, v) ϵ E on the graph (connecting nodes u ϵ V and v ϵ V) has 2 quantities associated with it:
c(u, v) >= 0, the capacity of the edge
a(u, v) >= 0, the cost of sending one unit through the edge
We d... | [] |
Your task, if you wish to accept it, is to write a program that outputs its own source code in the binary UTF-8 representation.
Rules
The source must be at least 1 byte long.
Your program must not take input (or have an unused, empty input).
The output may be in any convient format.
Optional trailing newline is allow... | [] |
You've probably heard of Fibonacci numbers. Ya know, that integer sequence that starts with 1, 1, and then each new number is the sum of the last two?
1 1 2 3 5 8 13...
And so on. Challenges about Fibonacci numbers are pretty popular 'round here. But who says that the Fibonacci numbers have to start with 1, 1? Why cou... | [] |
Single moves
The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root of N from its current square (Euclidean distance measured centre to centre).
For example:
A 1-mover can move to any squar... | [] |
Here's the challenge. Write some code to output all the integers in a range. Sounds easy, but here's the tricky part. It will start with the lowest number, then the highest. Then the lowest number which isn't yet in the array. Then the highest which isn't yet in it.
Example:
Lets take 1 to 5 as our start
The numbers ... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
I recently decided to download some dictation software, in order to help with my writing. However, it doesn't work very well when I'm coding, since I have to change from saying words to symbols and back again. It's even worse when I'm coding in an esoteric language which is all symbols.
In order to make my use of the d... | [] |
Sorting makes no sense for a 2-dimensional array... or does it?
Your task is to take an input grid and apply a bubble-sort-like algorithm to it until all values in the grid are non-decreasing from left to right and top to bottom along every row and column.
The algorithm works as follows:
Each pass goes row by row, top... | [] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.