instruction_seed stringlengths 292 48.7k | found_ngrams listlengths 0 21 |
|---|---|
Your task is to create a program or function that generates a zipper with a length of 10 lines. Each line of the zipper is represented by two dashes --:
--
--
--
--
--
--
--
--
--
--
The program/function will take a percentage (divisible by 10) as input, and the output will be the zipper "unzipped" (dashes separated) ... | [] |
Task
Define a mod-fold as a function of the form f(x) = x % a1 % a2 % … % ak, where the ai are positive integers and k ≥ 0. (Here, % is the left-associative modulo operator.)
Given a list of n integers y0, …, yn−1, determine if there exists a mod-fold f so that each yi = f(i).
You may choose and fix any two outputs Y ... | [] |
I'm new here. I tried seeing if this challenge was introduced before. Found a close call one counting the number of cycles, but didn;t find one for listing them. So I'm writing this one. Sorry if I'm repeating...
Anyway, I'm looking for the shortest function to return all close cycles in a shuffled list of indices. For... | [
[
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... |
A difference pyramid is a pyramid where each new diagonal is the absolute value of the differences between the elements of the last diagonal. For example, if we start with the array
2 5 4 9 3 4
Now, we arrange these in a diagonal column:
2
5
4
9
3
4
Now, we fill in the nex... | [
[
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
]
] |
Summary
Given a list of integers, return the index each integer would end up at when sorted.
For example, if the list was [0,8,-1,5,8], you should return [1,3,0,2,4]. Note that the two 8s maintain their order relative to each other (the sort is stable).
Put another way: For each element in the list, return the number... | [] |
Introduction
Let's observe this array: [3, 2, 4, 1, 1, 5, 1, 2].
Each element displays the length of the substring which must be summed up. Let's take a look at the first element of the above array:
[3, 2, 4, 1, 1, 5, 1, 2]
^
The element at the first index is 3, so we now take a substring of length three with the sam... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Task
Given (by any means) a sorted floating point dataset, return (by any means and within 1‰ of the correct value) the interquartile mean.
One possible algorithm
Discard the lowest and highest quarters of the data points.
Calculate the average (sum divided by count) of the remaining data points.
Note: If the dataset... | [] |
The goal of this challenge is to collect selected items in a list and move them to a certain location in the list.
As a visual example, take the input values (represented by black boxed integers) and a corresponding list of truthy values where true denotes the item is selected (represented by blue boxes, where T is tru... | [] |
Given an input of an integer \$n ≥ 2\$, output a list of its divisors sorted by the
exponents in their prime factorizations, in ascending order, ordering first by
the largest prime, then by the second largest, and so on.
As an example, take the integer \$72\$, which is \$2^3\cdot3^2\$. It has
the divisors
1 3^0 · 2... | [] |
An algebraic curve is a certain "1D subset" of the "2D-plane" that can be described as set of zeros {(x,y) in R^2 : f(x,y)=0 }of a polynomial f. Here we consider the 2D-plane as the real plane R^2 such that we can easily imagine what such a curve could look like, basically a thing you can draw with a pencil.
Examples:
... | [] |
Definition
Fibonacci sequence F(n), on the positive integers, are defined as such:
1. F(1) = 1
2. F(2) = 1
3. F(n) = F(n-1) + F(n-2), where n is an integer and n > 2
The Fibonacci-orial of a positive integer is the product of [F(1), F(2), ..., F(n)].
Task
Given positive integer n, find the Fibonacci-orial of n.
Specs
... | [] |
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7." --George Carlin
In this challenge, you will print all Integers, inclusive, within the given input range. Print numbers ascending or descending according... | [] |
Given six unique non-negative integers, print the two 3-digit integers comprised of those numbers that sum to the smallest amount.
Additionally,
If there is more than one set of numbers that meets the smallest-sum requirement, print the two that have the greatest difference. For example, 269 + 157 = 267 + 159 = 426; ... | [] |
The Collatz conjecture is a very well-known conjecture. Take a positive integer; if it's even, divide by 2, else, multiply by 3 and add 1. Repeat until you reach 1 or something else happens. The conjecture is that this process always reaches 1.
You can also reverse the process. Start at 1, multiply by 2, and to branch ... | [] |
Previously, we computed the Bit-Reversal Permutation where we found how the order of indices would be permuted. In that case, we received an input n which was the order of the permutation of the indices where the length was 2n. However, this time, we are given a string of length m = 2k for some k. Now we want to apply ... | [] |
Given an input number n from 1 to 26 (or 0 to 25), output the alphabet reading left-to-right up to and including that corresponding letter, with a=1, b=2, c=3, .... The twist is the letters must also be repeated vertically corresponding to their position in the alphabet. Odd numbers (when 1-indexed) should be balanced ... | [] |
Challenge description
Multiplification (totally not a made-up word) is a process in which you take two positive integers: a and b, and produce another integer which is equal to a repeated ("glued together") b times. For example, multiplifying 3 by 7 gives 3333333. Similarly, 103 multiplified by 5 is 103103103103103.
In... | [] |
Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. However, this is a multiple-holes (common theme is manipulation of data of any type and structure, especially special handling of empty data) code-golf version of the Phase I problems – open to any language. Enjoy!
Objec... | [] |
Executive summary: test whether an input sequence of integers is "admissible", meaning that it doesn't cover all residue classes for any modulus.
What is an "admissible" sequence?
Given an integer m ≥ 2, the residue classes modulo m are just the m possible arithmetic progressions of common difference m. For example, wh... | [] |
A ballot number, which we'll label B, is the number of ways of arranging the numbers from 1 through B(B+1)/2 into a triangle, such that each row and column is in any increasing order. The first four ballot numbers are:
a(0) = 1
a(1) = 1
a(2) = 1
a(3) = 2
a(3) is 2, which means that there are 2 ways of arranging the nu... | [] |
In arithmetic, an n-smooth number, where n is a given prime number, is mathematically defined as a positive integer that has no prime factors greater than n. For example, 42 is 7-smooth because all its prime factors are less than or equal to 7, but 44 is not 7-smooth because it also has 11 as a prime factor.
Define a p... | [] |
OEIS: A167171
A dense number is a number that has exactly as many prime divisors as non-prime divisors (including 1 and itself as divisors). Equivalently, it is either a prime or a product of two distinct primes. The first 100 dense numbers are:
2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 31, 33, 34,... | [] |
"Fit Numbers"
Sam has a "brilliant" idea for compression! Can you help?
Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17... | [] |
Some people say curiosity killed the cat. Other say it was the box and poison. The RSPCA say Erwin Schrödinger needs to lose the right to own pets.
With animal rights activists outside his house. The cat murderer scientist Schrödinger has finally come up with his greatest invention. A special, radioactive mix of unobta... | [] |
Frank has been working IT his whole life. Each day he responds to tickets, organizes equipment, and reports to his boss. One day, near the closing time on friday, Frank is doing his final inventory and sorting come cables in the supply closet. Suddenly, the door closes and locks from the outside! Such audacity! Frank s... | [] |
Extended Train Swapping Problem
Part 1: Normal Train Swapping Problem
In the 1996 CCC (Canadian Computing Competition), the first Stage 2 problem was a Train Swapping Problem. You can visit the link here. Essentially, you have a bunch of numbered trains, and you want to find out how many train swaps you need to get the... | [] |
Since this SE community is about golfing, I thought a golf-related challenge would be appropriate.
Explanation
Normally, the objective of golf is to finish a hole (and consequently, the entire round) with the least amount of strokes. This is a simple version of golf: Play until you hole the ball and sum up your score. ... | [] |
Introduction
Dice 10,000 is a dice game which can be played with 6 dice and something to write. Players roll the dice multiple times a turn and gain a score at the end of it. The player who reaches 10,000 point first wins the game. Calculating the score of one roll is your job in this challenge.
Look here for the full ... | [
[
220,
16,
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220
],
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
],
[
16,
11,
220,
16,
11,
220,
17,
11,
220,
18... |
Working with old files from DOS, I found an ancient text animation format, that specify how much time each frame must be shown in the screen. It's very simple:
F1W5F2W3
This example above indicates that Frame 1 must be shown for 5 units of time, and frame 2 for 3 units more. Now I want to convert it to:
1, 1, 1, 1, ... | [] |
In cryptography, PKCS#7 padding is a padding scheme which adds a number of bytes N ≥ 1, where the value of each added byte is equal to N.
For example, Hello, World!, which has 13 bytes, is the following in hex:
48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21
If we choose to PKCS#7 pad to length 16, then the result is:
48 65 6C... | [] |
It is time to embark on a perilous quest to defeat the British Intelligence. The aim of this challenge is to write the shortest code that will solve a Nonogram.
What is a Nonogram?
The rules are simple.
You have a grid of squares, which must be either filled in black or left blank. Beside each row of the grid are... | [] |
The sequence of segmented numbers or prime numbers of measurement (OEIS A002048) is the sequence of numbers such that each member is the smallest positive (greater than zero) number that can't be made of a sum of earlier consecutive numbers, with a(0) = 1.
Example
To calculate a(7) we first calculate a(0->6) = [1, 2, 4... | [] |
Introduction
The game of xiangqi, also known as Chinese chess, is a chess-like game
popular in China, Vietnam, Taiwan, and other East Asian countries. The colours
of the two sides in xiangqi are red and black. There are seven pieces in
xiangqi: the general (G), advisor (A), elephant (E), horse (H), chariot
(R), cannon ... | [] |
Decipher Neurotic Frogs
Now that Puzzling.SE has finally cracked my amphibian-obsessed cipher, let's write a program or function to decrypt it!
(If you want to look at the puzzle before having it spoiled for you, click the above link now.)
How the cipher works
In Neurotic Frogs Ought To Relax In Mud Baths ("Neurotic F... | [] |
Continued fractions are expressions that describe fractions iteratively. They can be represented graphically:
$$
a_0 +\cfrac 1
{a_1 + \cfrac 1
{a_2 + \cfrac 1
{\ddots + \cfrac 1
{a_n}
}
}
}
$$
Or they can be represented as a list of values: \$[a_0 ; a_1, a_2, \dots, a_n]\$
The challenge:
take a base nu... | [
[
64,
62,
16,
11,
264,
62,
17,
11,
1124,
67816,
11,
264,
1089
]
] |
Write a program or function which will provably print all integers exactly once given infinite time and memory.
Possible outputs could be:
0, 1, -1, 2, -2, 3, -3, 4, -4, …
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8, -9, 10, 11, …
This is not a valid output, as this would never enumerate negative num... | [
[
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 a number x and a number n, round number x to n significant figures and output the result.
Significant figures
The significant figures of a number are digits that carry meaning contributing to its measurement resolution. This includes all numbers except leading zeroes.
Bear in mind that leading zeroes af... | [] |
This challenge is the first in a two-challenge series about Repetition. The second will be up soon.
In a language called Repetition (something I just made up), there consists an infinite string of 12345678901234567890..., with 1234567890 repeating forever.
The following syntax is available to output numbers:
+-*/: Thi... | [] |
Background
In 1870 Émile Baudot invented Baudot Code, a fixed-length character
encoding for telegraphy. He designed the code to be entered from a
manual keyboard with just five keys; two operated with the left hand and
three with the right:
The right index, middle and ring fingers operate the I, II, and
III keys, res... | [] |
The challenge is to list all ordered partitions (composition (combinatorics)) of a given positive integer n. These are the lists of numbers from 1 to n whose sum is n. For example, given input n = 4, the result should be:
4
1, 3
3, 1
2, 2
2, 1, 1
1, 2, 1
1, 1, 2
1, 1, 1, 1
The result can be in any order... | [] |
Input:
A list/array of integers for which each item is in the range of 2-36.
Output:
The sum of the integers (as base 10), where each next integer is in the base of the previous value (starting with a regular base 10).
Example:
Let's say we have an input like this: [4, 12, 34, 20, 14, 6, 25, 13, 33]
Then we have a sum ... | [
[
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... |
This is sequel to this challenge by Adnan. If you like this challenge, chances are you'll like the other one too. Check it out!
A multiple choice test with 8 questions each with 4 choices might have the answers: BCADBADA. Converted to four different arrays, with true and false if the current letter is the answer, it w... | [] |
Task
Given the pre-order and post-order traversals of a full binary tree, return its in-order traversal.
The traversals will be represented as two lists, both containing n distinct positive integers, each uniquely identifying a node. Your program may take these lists, and output the resulting in-order traversal, using ... | [] |
Credit
My thanks to Rand Al'Thor's letter-based question for the inspiration for this code-golf challenge.
Background
The nature of this challenge is based off the algorithm mentioned by Rand in his "A Triangle Formed of Three Letters":
Start with a sequence of 10 letters each of which is X, Y, or Z.
Under each row, ... | [] |
A guitar fretboard diagram looks like this:
0 1 2 3 4 5 6 7 8 9 10 11 12 <- Fret number (0 means it's open)
|-E--F--F#-G--G#-A--A#-B--C--C#-D--D#-E
|-B--C--C#-D--D#-E--F--F#-G--G#-A--A#-B
|-G--G#-A--A#-B--C--C#-D--D#-E--F--F#-G
|-D--D#-E--F--F#-G--G#-A--A#-B--C--C#-D
|-A--A#-B--C--C#-D--D#-E--F--F#-G--G#-... | [] |
Things to know:
First, lucky numbers.
Lucky numbers are generated like so:
Take all the natural numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20...
Then, remove each second number.
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39...
Now, 3 is safe.
Remove every 3... | [
[
11,
220,
16,
17,
11,
220,
16,
19,
11,
220,
16,
21,
11
],
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
],
[
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
... |
XKCD #99, with the title "Binary Heart" shows a simple image of ones and zeros, with some digits colored red.
The red heart is visible to the naked eye, but the message hidden in the binary sequence is not. If you remove all the spaces and newlines and interpret the binary sequence as 8 bit ASCII-code, you'll end up ... | [] |
Crash Course on DST
Dempster–Shafer theory (DST) provides a method to combine various sources of evidence to form a belief. Given a list of possible statement (one of which is the true answer), each possible combination of statements is assigned a "mass" indicating the degree of supporting evidence. The total mass of... | [] |
Given a list of indices and zero or more lists of integers, output the lists of integers, sorted in ascending order, with the key priority from the first input.
Example
Let the keys input be [1, 0, 2], and the lists input be [[5, 3, 4], [6, 2, 1], [5, 2, 1]]. Those lists need to be sorted by their second element, then ... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Write a program or function that outputs this exact text, case-insensitive:
A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.
(Based on the alphabet song that many American kids learn to help memorize the alphabet, though edited for more compressibility.)
The output must look exactly the sa... | [
[
32,
11,
425,
11,
356,
11,
422,
11,
468,
11,
434,
11,
479
]
] |
Challenge
I've recently gotten into 8-bit computers and are fascinated with the workings of them and others alike; thus the objective of this code golf, is to replicate a portion of the Woz Monitor, designed by Steve Wozniak for the Apple I.
You are to store an array of 22 hexadecimal values with a width of two bytes... | [] |
Introduction
A Gray Code is an alternative to binary representation in which a number is incremented by toggling only one bit, rather than a variable amount of bits. Here are some gray codes along with their decimal and binary equivalents:
decimal | binary | gray
-------------------------
0 | 0 | 0
----... | [] |
Introduction
The Atari ST was a rather popular personal computer from the mid 80's to early 90's era, powered by a Motorola 68000 microprocessor. On this machine, the default behavior of the operating system for uncaught CPU exceptions was to display a row of bombs on the screen, as shown in the following picture:
Sou... | [] |
Given a Sudoku puzzle, find all possible marks that can be filled into each empty cell.
Test case
Input:
[
[
// Top left:
[
0, 0, 0,
3, 4, 0,
0, 0, 2
],
// Top middle:
[
7, 4, 0,
0, 0, 0,
0, 0, 3
... | [] |
Given a number determine if it is a folding number.
A folding number is a number such that if you take it binary representation and "fold" it in half, That is take the result of XNOR multiplication of the first half of the number and the second half with it digits in reverse, you will get zero.
If the number has a odd... | [] |
Challenge
Ever seen those movie trailer titles (namely Martian, Interstellar, etc) where they have huge gaps in between letters slowly spreading out?
The challenge is to recreate this effect given a string, gap multiplier and direction, by inserting appropriate amount of spaces in between the letters.
Example
Input: '... | [] |
We have already defined a folding number here.
But now we are going to define a Super Folding Number. A Super Folding number is a number that if folded enough times it will eventually reach one less than a power of two. The method of folding is slightly different than in the folding number question.
The folding algor... | [] |
The Wythoff matrix is an infinite matrix consisting of the Grundy numbers of each square on a chessboard in Wythoff's game.
Each entry in this matrix is equal to the smallest nonnegative number that does not appear anywhere above, to the left, or diagonally northwest of the position of the entry.
The top-left 20-by-20 ... | [] |
String Similarity
String similarity is basically a ratio of how similar one string is to another. This can be calculated in many ways, and there are various algorithms out there for implementing a ratio calculation for string similarity, some being more accurate than others. It's actually very useful to use these metho... | [] |
Introduction
A decimal is terminating if it has a finite number of decimal digits. For example, 0.4 (2/5) is terminating because it has one decimal digit.
A decimal is purely periodic if it has an infinite number of decimal digits and has no decimal digits before its repetent (the part of the decimal that repeats.) For... | [] |
Write a program or function that takes in positive integers a, b and c, and prints or returns a/b to c decimal places, using the operations +-*/% [add, subtract, multiply, divide, modulate] on the positive integers: you can use all that your language allows, but not on floating point numbers. The range of a,b,c would b... | [] |
Backstory
Disclaimer: May contain made up information about kangaroos.
Kangaroos traverse several stages of development. As they grow older and stronger, they can jump higher and longer, and they can jump more times before they get hungry.
In stage 1, the kangaroo is very little and cannot jump at all. Despite this, is... | [] |
Connect Four is a game where two players take turns to drop disks into columns of a vertically mounted grid, and attempt to connect four disks orthogonally or diagonally. When a column is chosen, the disk falls to the lowest empty position in that column, so any game may be completely specified by the size of the grid ... | [] |
Given a number N, draw a left aligned NxN board of numbers, leaving 1 blank (as a space) (I will show diagrams with N=5)
2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Your job is to construct the Sieve of Eratosthenes, step by step. First, start with 2. It's prime, so leave it there, and re... | [] |
Consider the natural sequence up-to 6 (disregard 1):
2,3,4,5,6
We start scanning from the left (in this case from 2), search for a number divisible by 2 (here 4) and then remove both the numbers from the list (here 2 & 4), such that the list reduces to:
3,5,6
We continue the same process, here leftmost is 3, so we... | [] |
The Goldbach conjecture states that every even number greater than two can be expressed as the sum of two primes. For example,
4 = 2 + 2
6 = 3 + 3
8 = 5 + 3
However, once we get to 10 something interesting happens. Not only can 10 be written as
5 + 5
but it can also be written as
7 + 3
Since 10 can be expressed as t... | [] |
The challenge is to write the fastest code possible for computing the permanent of a matrix.
The permanent of an n-by-n matrix A = (ai,j) is defined as
Here S_n represents the set of all permutations of [1, n].
As an example (from the wiki):
In this question matrices are all square and will only have the values -1 a... | [] |
This challenge was inspired by this Wendy's commercial from 1984.
Illustration by T S Rogers
Your task is to find a hexadecimal 0xBEEF on a binary bun.
The 'beef' consists of the following pattern:
1 0 1 1 (0xB)
1 1 1 0 (0xE)
1 1 1 0 (0xE)
1 1 1 1 (0xF)
And the 'bun' consists of a 12x12 binary matrix, such as:
1 ... | [] |
Introduction
Suppose you have a ruler with numbers from 0 to r-1.
You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler.
The ruler is so narrow that the ant cannot walk from one position to another without walking on all the numbers in between.
As the ant walks on a number for... | [] |
This is different from My Word can beat up your Word as it is less complex and only requires you to calculate it, and not compare them.
To find the digital root, take all of the digits of a number, add them, and repeat until you get a one-digit number. For example, if the number was 12345, you would add 1, 2, 3, 4, and... | [] |
Bailey–Borwein–Plouffe Iterations
We've seen a few pi challenges on PPCG, but none that specifically dictate the algorithm you should be using. I'd like to see implementations of the Bailey–Borwein–Plouffe algorithm in any language up to iteration n. The formula is as follows:
Your algorithm should output each iterati... | [] |
I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as \$10^{100}\$, i.e., 1 followed by a hundred 0's in decimal.
Example output:
111111111111111111111111111111111111111111111111111111111111111111111111...... | [] |
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.
Examples
"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" -->... | [] |
Background
Back in the late 90's / first 00's when Flash Web Design was so much cool that noone could live without having a full Flash website, or at least an animated widget, I was hired to develop a "horse races viewer" in Flash/Actionscript, in the shape of an 80's videogame style animation, so the site's visitors c... | [] |
The program should take input the number, the start of the range and the end of the range, and output how many integers the number appears between the start and end of the range, inclusive. Both programs and functions are allowed.
Example Inputs
For example:
//Input example 1
3,1,100
//Input example 2
3
1
100
//Input e... | [] |
This is my first code golf exercise for you:
Your input is two integers n and k. You can assume n >= 1 and k >= 1
You have to output all numbers from 1 to n (inclusively) and replace every element that is a multiple of k or that contains k with "Shaggy".
you can take the input in any convenient form and output it in a ... | [] |
A Primenary (binary-prime) string is one which, when written as a binary grid, every row and column has a prime total.
That's quite a vague explanation, so let's break it down with a worked example...
For this example we'll use the string bunny:
First, find the ASCII code point of each character and its binary repre... | [] |
Inspired by, and in memory of, my dear friend and colleague,
Dan Baronet, 1956 – 2016. R.I.P.
He found the shortest possible APL solution to this task:
Task
Given a Boolean list, count the number of trailing truth values.
Example cases
{} → 0
{0} → 0
{1} → 1
{0, 1, 1, 0, 0} → 0
{1, 1, 1, 0, 1} → 1
{1, 1, 0, 1, 1} → 2
... | [] |
Introduction
In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (units). These are one type of 2-dimensional figurate numbers.
The number 10, for example, can be arranged as a triangle:
*
**
***
****
But 10 cannot... | [] |
Hearts is a trick-taking card game for 4 players. Each trick is taken by the player who played the highest card of the leading suit. At the end of each hand, the players incur a penalty score depending on the penalty cards they have taken; the task is to determine the scores under Microsoft Hearts rules.
Input
Input is... | [
[
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 monotonic subsequence is a sequence of numbers \$a_1, a_2, ..., a_n\$ such that
$$a_1 \le a_2 \le ... \le a_n \\
\text{or} \\
a_1 \ge a_2 \ge ... \ge a_n$$
[1, 3, 3, 7, 9, 13, 13, 100] is a monotonic (non-decreasing) subsequence, as well as [9, 4, 4, 3, 0, -10, -12] (this one is non-increasing), but [1, 3, 6, 9, 8] i... | [
[
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
]
] |
Problem
The goal is as the title says to find the \$n\$th prime such that \$\text{the prime}-1\$ is divisible by \$n\$.
Explanation
Here is an example so you understand the question, this is not necessarily the way it ought to be solved. It merely as a way to explain the question
given \$3\$ as an input we would first ... | [] |
Let's take a look on a typical loop, which usually performs 8 iterations:
for (int x=0; x<8; ++x);
You have to make it infinite!
It's a popularity-contest for all languages that support such form of for loop. So solution with highest score (upvotes minus downvotes) wins.
If your language has the other form of for loo... | [] |
I love /usr/share/dict/words; it's so handy! I use it for all my programs, whenever I can! You're going to take advantage of this ever so useful file to use, by testing a word's individuality.
Input
A word; defined in this challenge as any string of characters
/usr/share/dict/words in some format; you may hard code i... | [] |
EDITS:
Added link to the plain-text (multiple strings) test data
Added BLANK,EDGE and TIE2 test cases (see Test Data section) (11/25)
Updated the JSON test cases (some lines were ill-formatted) (11/24)
Renju match gone bad ! (well, technically these guys are playing Go, but who cares) Wikisource
TL;DR
Take a 15x15 ... | [] |
Take a non-nested array as input. Turn it into a matrix by using the following method:
Let's say my array is [1, 2, 3, 4, 5]
First, I repeat that array 5 times: (the length)
[[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]]
Then, I read it along the diagonals:
[[1],
[2, 1],
[3... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Task
Given a Boolean matrix, find one (or optionally more) subset(s) of rows which have exactly one True in each column. You may use any algorithm, but must support very large matrices, like the last example.
One possible algorithm (Knuth's Algorithm X)
While there is no requirement to use this algorithm, it may be you... | [
[
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
An unlabelled tree may look like this:
o
/ | \
o o o
| / \
o o o
To linearize this tree, we first label each node o with it's number of child nodes:
3
/ | \
1 0 2
| / \
0 0 0
and then write the numbers in a list in a breath-first manner, meaning line by line and left to right:
[3... | [] |
You will write a simple program that prints exactly 1 2 3 4 5 6 7 8 9 10 to STDOUT, Console, or your language's closest output method. No other visible output should be seen. Any other code executed must be back-end only.
This is answer-chaining, so the catch is that you must include the previous answer's source code i... | [] |
Let's use the four basic operations, addition +, multiplication *, subtraction - and division / (float, not integer).
Stewie's sequence is defined as follows:
x = [x(1), x(2)] // Two initial numbers (one indexed)
x(3) = x(1) + x(2)
x(4) = x(2) * x(3)
x(5) = x(3) - x(4)
x(6) = x(4) / x(5)
x(7) = x(5) + x(6)
... and s... | [] |
Introduction
A xenodrome in base n is an integer where all of its digits in base n are different. Here are some OEIS sequences of xenodromes.
For example, in base 16, FACE, 42 and FEDCBA9876543210 are some xenodromes (Which are 64206, 66 and 18364758544493064720 in base 10), but 11 and DEFACED are not.
Challenge
Given ... | [
[
11,
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
20,
11
],
[
220,
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220
]
] |
An unspeakable number is a number which is divisible by seven or has seven as one of its digits. A children game is to count skipping unspeakable numbers
1 2 3 4 5 6 ( ) 8 9 10 11 12 13 ( ) 15 16 ( ) 18 ...
Cantor's version of the game is the sequence defined by recursively filling in the sequence "1 2 3 4 5 6 ( ) 8..... | [] |
Given three sidelengths of a triangle, evaluate its aspect ratio AR given the following formula:
where
The closer to equilaterality a triangle is, the closer to 1 its aspect ratio is. The aspect ratio is bigger or equal to 1 for valid triangles.
Inputs
The input is three real positive numbers which can be encapsulate... | [] |
There’s a famous tricky algorithm for counting the number of set bits in a 32-bit unsigned integer:
int popcount(unsigned x) {
x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
x = (x & 0x00FF00FF) + ((x >> 8) & 0x... | [] |
Alphabetize Integers
For a given set of numbers, put them in alphabetical order when they are spelled out (i.e. 1: one, 2: two, 90: ninety, 19: nineteen). Your code should work for the range [-999999, 999999]. Output must have a delimiter between numbers. A space will work, as will a space and a comma as shown in the e... | [
[
16,
11,
220,
17,
11,
220,
18,
11,
220,
19,
11,
220,
20
]
] |
Introduction
Consider a sequence of integers and one of its subsequences, say A = [4 2 2 4 4 6 5] and B = [2 4 5].
We want to remove the elements of B from A in order, and there are several ways of doing that:
A = 4 2 2 4 4 6 5
B = 2 4 5
-> 4 2 4 6
A = 4 2 2 4 4 6 5
B = 2 4 5
-> 4 2 4 6
A = ... | [] |
Binary to decimal converter
As far as I can see, we don't have a simple binary to decimal conversion challenge.
Write a program or function that takes a positive binary integer and outputs its decimal value.
You are not allowed to use any builtin base conversion functions. Integer-to-decimal functions (e.g., a functio... | [] |
Introduction and Credit
Imagine you're Amazon. Imagine you have a large number of products for which a lot of people have written reviews scoring 1-5 stars. Now you need to give your customers a summary for each product based on the simple product-scoring association. Because you're Amazon, time is money and as such yo... | [] |
We are putting balls into a fixed number a bins. These bins begin empty.
Empty bin (a=4): 0 0 0 0
And one by one we add balls to the bins.
0 0 0 1 or
0 0 1 0 or
0 1 0 0 or
1 0 0 0
We need a quick way to loop over all the possible states the bins take, without duplicates and without missing any and we don't want t... | [] |
Generate me a QFP chip!
From the sandbox!
QFP is a type of form factor for an electrical component where pins come out the sides of a chip. Here are is a picture of a typical QFP component:
you can see that the general formula is to have 4 sides of equal numbers of pins.
Your challenge is to create a program that tak... | [] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.