instruction stringlengths 34 53.1k |
|---|
You work at a virtual, old-fashioned printing press. To help you arrange your monospace letters faster, you decide to make the shortest program possible to help you. Given a string of text and a page size, generate and output each page of the text.
Examples
For example, with a page width of 14, height 7, and some text,... |
Challenge
For a given positive integers range, find the first and last prime number entirely composed of prime number digits, exceptionally including 0 (for the digits, a range of 0-2 should output 2-2). The range is inclusive. If no number is found, the expected output is 0. If there is only one such number, the expec... |
Write a regular expression which matches a given string consisting of three non-negative, space-separated integers if and only if the last integer is the sum of the previous two. Answers may be for integers of any numeral system with radix between 2 and 10.
Test cases
These should fail:
0 1 2
10 20 1000
These should m... |
Standard ML (or golfier: SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. (from Wikipedia)
Though you almost certainly will never win a code golf challenge with SML, (ab-) using it for golfing can nevertheless be quite fun (<- keyword for function d... |
I call this sequence "the Jesus sequence", because it is the sum of mod.</pun>
For this sequence, you take all the positive integers m less than the input n, and take the sum of n modulo each m. In other words:
$$a_n = \sum_{m=1}^{n-1}{n\bmod m}$$
For example, take the term 14:
14 % 1 = 0
14 % 2 = 0
14 % 3 = 2
14 % 4 =... |
This challenge posed an algorithm for encoding an integer n as another integer r. What follows is a succinct explanation of that algorithm, using n=60 as an example.
The original algorithm
First, we encode the number as a string of brackets.
If n = 1, return an empty string.
Otherwise, we take n's prime decomposition... |
This is based on how my company deals with the monitoring of the working times for every employee. Each one of us has a card that can be passed in front of a sensor, so that a clock registers the times at which the employees check in or out the office. Every time register is linked to a code:
Code 0: the employee arri... |
The characteristic polynomial of a square matrix \$A\$ is defined as the polynomial \$p_A(x) = \det(Ix-A)\$ where \$I\$ is the identity matrix and \$\det\$ the determinant. Note that this definition always gives us a monic polynomial such that the solution is unique.
Your task for this challenge is to compute the coeff... |
Given 4 points on the 2D planes A, B, C, D, calculate the area of the intersection region of the triangles OAB and OCD, where O is the center of the plane, having coordinate (0, 0).
Algorithms that runs in constant time complexity (in terms of arithmetic operations) are encouraged, but not forced.
Rules
Each point is ... |
Dice Cricket is a game I was introduced to as a child and have used as a way to pass time for years since. I couldn't find a Wikipedia page so I'll explain the rules below.
Dice Cricket Rules
Premise
Dice Cricket is a game similar to scoring a game of cricket as you watch it but rather than watching and recording the r... |
Given a binary number A as input with d > 1 digits, output a binary number B with d digits according to the following rules for finding the nth digit of B:
The first digit of B is zero if the first and second digits of A are equal; otherwise, it is one.
If 1 < n < d, then if the (n-1)th, nth and (n+1)th digits of A ar... |
Merge sort is a sorting algorithm which works by splitting a given list in half, recursively sorting both smaller lists, and merging them back together to one sorted list. The base case of the recursion is arriving at a singleton list, which cannot be split further but is per definition already sorted.
The execution of... |
The Pareto Distribution is a probability distribution that comes up a lot in nature. It has lots of special properties, such as an infinite mean. In this challenge, you will output a number sampled from this distribution.
The Pareto Distribution is defined to be greater than or equal to x with probability 1/x, for all ... |
Normally, I'd open with some flavor text here about being bored and/or lazy but looking through the stack-exchange-api questions that would be far from original. So instead I'm going to open with a meta and self-referential flavor text describing this lack of originality that then describes itself and how meta and self... |
Challenge
For any string that is composed of alphabetical characters of any case, make a function that returns a list of all of it's variations, order and case-wise empty strings returns empty list.
Test Cases
"" -> []
"a" -> ['a', 'A']
"ab" -> ['ab', 'Ab', 'aB', 'AB', 'ba', 'Ba', 'bA', 'BA']
"abc" -> ['abc', 'Abc', '... |
(2 Jan 2018) Because of the winning criteria I am going to accept the Jelly answer, but I am also giving upvotes to all other answers which all use astounding methods as well
Introduction
There are lots of challenges asking for a shortest program to calculate mathematical constants. I saw some with restrictions like ba... |
Unary numbers typically only represent nonnegative integers, but we can extend them to represent all integers as follows:
A positive integer N is represented as N 1's: 5 -> 11111
A negative integer -N is represented as a 0 followed by N 1's: -5 -> 011111
Zero is represented as 0
We can then represent a list of these ... |
Given a nonnegative integer, return whether it is a three digit number ending in one, in any consistent integer base. In other words, the number needs to be represented in base-N, N being an integer greater than zero.
Rules
This is code-golf, so shortest answer wins.
Since unary behaves weirdly, the behavior with inpu... |
Given a fraction in the format m/n (where m and n are coprime integers), output the corresponding Unicode fraction. Your program/function will not be expected to take in any input that does not correspond to a Unicode character. Arrays, e.g. [2, 3] as opposed to 2/3, are accepted. m / n as opposed to m/n is also fine. ... |
We all know that whenever a rational number is written in decimal, the result is either terminating or (eventually) periodic. For example, when 41/42 is written in decimal, the result is
0.9 761904 761904 761904 761904 761904 761904 761904 ...
with an initial sequence of digits 0.9 followed by the sequence 761904 repe... |
The partitions of an integer N are all the combinations of integers smaller than or equal to N and higher than 0 which sum up to N.
A relatively prime partition is an integer partition, but whose elements are (overall) coprime; or in other words, there is no integer greater than 1 which divides all of the parts.
Task
G... |
Challenge:
Your task is to use any language to output that language's name times the number of character's in its name.
Use the common name or acronym of the language.
If there are
multiple versions of a language, you need not include the version number.
The capitalization matters.
Examples:
PHP -> PHPPHPPHP
Java -> ... |
A pleasing number (according to this definition) is a number that can be passed through the following process (let's use 41802000 as an example):
Separate the trailing identical numbers (41802000 => [41802, 000])
Sort the first half of the digits and take the maximum ([41802, 000] => [8, 000])
Take the length of the f... |
Introduction
In this challenge you should split an integer into two pieces. Since nobody likes getting the smaller piece of cake, your goal is to be as fair as possible. For example if you wanted to split the integer 7129 into two pieces, there are 3 possible ways of doing so.
7,129, 71,29 and 712,9 are all possibiliti... |
Just for fun, I wanted to see how little lines I could solve this problem in, using python. I managed to condense my code into 9 lines.
size = int(input("Size: "))
a = [x for x in range(size-2, -1, -1)] if size % 2 == 0 else [x for x
in range(size-2, 0, -1)]
b, counter = a[::-1], 0
print("\n"+"\\"+"#"*size+"/") #top
f... |
Description
Output the rhyme scheme for a very long Terza Rima.
Input
None.
Output
ABA
BCB
CDC
DED
EFE
FGF
GHG
HIH
IJI
JKJ
KLK
LML
MNM
NON
OPO
PQP
QRQ
RSR
STS
TUT
UVU
VWV
WXW
XYX
YZY
Rules
You can pick between separating stanzas with whitespace or newlines, so either:
ABA BCB...
OR
ABA
BCB
...
A single trailing whit... |
Task
Write a program/function that, given three integers n,a,b prints a regular expression which matches all of the base-n integers from a to b (and no integers outside of that range).
Your algorithm should, in theory, work for arbitrarily large integers. In practice, you may assume that the input can be stored in your... |
If you have a small child in your house, you may have come across foam bath letters. These can be moistened and stuck to flat surfaces such as tiles and the side of the bath to make words and messages.
The range of words and messages is somewhat limited if you only have one set though, since you only get 36 characters:... |
Thanks to your help in the Mark My Mail challenge, PPCG-Post has successfully stamped all of its parcels with the generated barcodes!
Now, it's time to decode them.
In this challenge your program will, given a barcode generated from the Mark My Mail challenge, decode it and return the encoded integer.
But watch out! Th... |
On December 4, 2017, the Google Doodle was a graphical programming game featuring a bunny. The later levels were nicely non-trivial and they seemed like a great candidate for an atomic-golf challenge.
Details
Game
There are four available moves: hop forward, turn left, turn right, and loop. Each of these moves is one ... |
If a string T of length K appears K or more times in a string S, then it is potentially communistic. For example, 10 in 10/10 is potentially communistic, for it appears 2 times and is of length 2. Note that these substrings cannot overlap.
A communistic transformation is one that takes this string T and moves each cha... |
Many digital clocks display the time using simplified digits comprised of only seven different lights that are either on or off:
When mirrored horizontally, the digits 018 don't change because they are symmetrical. Also, the digits 2 and 5 get swapped, 2 becoming 5 and vice versa. All the other digits become invalid w... |
Your task is to determine whether two numbers are easy to multiply. This means that their base-10 long multiplication doesn't have any carrying (regrouping) between place values, looking at both the multiplication steps and the addition step. This happens when each pair of digits being multiplied gives 9 or less and th... |
Given an integer n, return the number of ways that n can be written as a list of prime numbers. For example, 2323 can be written as (2,3,23), (23,23) or (2,3,2,3) or (23,2,3), so you would output 4. If it can not be written in this way, you should output 0.
A prime number such as 019 or 00000037 is a valid prime for th... |
Inspiration. Posted with permission.
Print one of the possible XKCD calendar "facts":
You can get the raw text and structure from my APL reference implementation or from Explain XKCD's transcript (including the title text just under the illustration).
Rules
At every decision node, there must be an equal (pseudo-)rando... |
A superabundant number is an integer n that sets a new upper bound for its ratio with the divisor sum function σ. In other words, n is superabundant if and only if, for all positive integers x that are less than n:
$$\frac{\sigma(n)}n>\frac{\sigma(x)}x$$
For a few of the values:
n σ(n) σ(n)/n superabundant
1 1 ... |
Note to mods, if the title doesn't do justice, change it to whatever, I thought it was funny.
You're tasked with hanging up the lights for this Christmas season, and your family has decided that for it to be a merry Christmas, you need to hang at least 2 Christmas lights on your house. So, your challenge is, given a n... |
Background
Minifiers are used, commonly, when serving JavaScript to your Web Browser. It is commonly used to reduce the number of bytes that have to be sent. Saving bandwidth is useful for obvious reasons. Some people use obfuscaters (that intentionally make code harder to read), I am not talking about those.
We wil... |
Do you remember my mat properly grouped by colors?
Yesterday I was looking at it and realized that some letters fit inside others. Example: a letter P fits in the place where the letter R goes. So here's a simple challenge: given two letters, return a truthy value if any one of the letters fits inside the other (direc... |
Your challenge is to take an array of strings and output the longest string in the array. So for
["tiny", "small", "bigger", "biggest"]
the output would be biggest.
If two elements of the array have the same length, you should choose the one that appears first in the array. That means if the array looks like this:
["o... |
To check whether a list of non-negative integers is balanced, one can imagine putting respective weights on a board and then try to balance the board on a pivot such that the summarized relative weights left and right of the pivot are the same. The relative weight is given by multiplying the weight with its distance to... |
Mafia (also known as Werewolf) is a party game that plays roughly like this:
The game begins on day 0. After every day n comes a night n. After every night n comes a day n+1. i.e. D0, N0, D1, N1, D2, N2...
At the dawn of day 0, a host secretly chooses players to fill certain roles:
Some number of players become th... |
Covalent bonding uses so-called "hybrid" orbitals to form tetrahedral, octahedral, etc. formations out of the s, p, and sometimes d orbitals. Their naming conventions are pretty much the concatenation of the component orbitals; for example, the hybridization of the s orbital and one p orbital would be the two sp orbita... |
Definition
An arrowhead matrix is a matrix that has all entries equal to 0, except the ones on the main diagonal, top row and leftmost column. In other words, the matrix should look like this:
* * * * * *
* * 0 0 0 0
* 0 * 0 0 0
* 0 0 * 0 0
* 0 0 0 * 0
* 0 0 0 0 *
Where each * is any non-zero entry.
Task
Given a squa... |
The question: Given an a number n ≥ 2, how many distinct pairs of points on an n-dimensional n x n x n x n x n x n ... x n lattice, where the coordinates range from 0 to n - 1, are a distance at least n apart? The pairs {(2,1,3,1), (3,2,1,3)} and {(3,2,1,3), (2,1,3,1)} are not considered distinct from each other, as th... |
We often see music videos on Youtube. Many Youtube channels that host music videos are "powered by VEVO". Those can be easily identified by both embedding VEVO at their video thumbnails and appending VEVO to their channel name.
Now write some code to test whether a string given by user is a VEVO user account or not.
Re... |
Explanation
In this task you'll be given a set of N points (x1,y1),…,(xN,yN) with distinct xi values and your task is to interpolate a polynomial through these points. If you know what Lagrange interpolation is you can skip this section.
The goal of a polynomial interpolation is to construct the (unique) polynomial p(x... |
Given a drawing of the letter shoot system, where an existing piece of pipe is marked with a *, and an empty spot is marked with a ., your task is to compile a lexicographically sorted list of index tuples [entry row, entry column, exit row, exit column], where each index is 0-based. Entry and exit points are always on... |
The 52 week challenge is a way to save money. For example, Week 1, you save $1.00. Week 2 you save $2.00, and it continues through the year, adding one more dollar to each week’s savings goal. By Week 52, you’ll set aside $52.00, which will bring the year’s total savings to $1,378! Of course, you can decide how much mo... |
A venerated pass time of pedants is to point out that pictures of "Rubik's Cubes" (on t-shirts, posters etc.) are not actually solvable.
The first thing that should be checked is that the cube is made up of the right pieces. To be solvable a cube needs six colors each with nine squares. The cube also needs each edge ... |
Your task is to program a mathematical function \$s\$, that takes a nonempty finite set \$A\$ of points in the 2D plane, and outputs an uncircularity score \$s(A)\$ that satisfies following properties:
Positive Definiteness: If there is a circle or a straight line that contains all points of \$A\$, then \$s(A) = 0\$. ... |
A mountain is defined to be a set of line segments whose first point has coordinates (0,a) where a > 0, and whose last point has coordinates (b,0), where b > 0. All intermediate points have a y-coordinate (ordinate) strictly greater than 0. You are given the points on the mountain sorted in ascending order of x-coordin... |
(This might be quite classic but this is my first post here, so I'm not ready for the fancy stuff yet)
The Goodstein sequence is defined for an input number as follows:
Pick a starting number n, let b=2 and repeat:
write n in heriditary base b notation
substitute all the (b)s to (b+1)s in n and substract 1
output the ... |
Challenge
Given a whole number divisible by 9 and one missing digit, find the missing digit.
The missing digit may be represented by any character other than the digits 0-9 as long as it is consistent.
If the missing digit could be 0 or 9, output something to signify so.
Assume the user is intelligent enough to put onl... |
Introduction
This challenge requires you to set the trailing zeros of an integers binary representation to 010101…, this is best explained with an example:
Given the integer 400, the first step is to convert it to binary:
110010000
As we can see the fifth bit is the least significant 1 bit, so starting from there we r... |
inspired by this chat conversation
A satisfying number is a number whose decimal representation is of the form abx, with the following properties:
x is the longest trailing repeating suffix, or the last digit if there is no repetition at the end (123333 -> 3333, 545656 -> 5656, 123 -> 3)
b is the single digit prior to... |
I posted this challenge a while ago, which concerns how many elves Santa needs to deliver presents.
Due to population increase, Santa is a little more pressed for time this year. Although in the past we operated very asynchronously, we are beginning to experiment with being more and more synchronized. So, Santa needs t... |
Challenge
Given two digits 0-9 as input, output a domino (from the double-nine domino set) with these number of pips (dots) on the two faces. The ten possible faces look like this (separated by pipes):
| | o| o|o o|o o|o o o|o o o|o o o|o o o
| o | | o | | o | | o |o o|o o ... |
Introduction
This is a follow-up of this challenge where you're taking the role of that person's evil twin. Being evil you don't want to maximize your share, but rather be as unfair as possible and you're not going to make it too obvious, that's why you came up with the following scheme:
You're going to tell the others... |
In this challenge we learned a way to encode every positive integer using factor trees.
Here is how it works:
The empty string has value of 1.
(S) where S is any expression with a value of S evaluates to the Sth prime.
AB where A and B are arbirary expressions with values of A and B respectively has value A*B.
For ex... |
This has no practical purpose but it could be fun to golf.
Challenge
Given a number n,
Count the amount of each digit in n and add 1 to each count
Take the prime factorization of n
Count the amount of each digit in the prime factorization of n, without including duplicate primes
Create a new list by multiplying togeth... |
Input: An integer N which represents the polygon's vertices and a list of their x and y coordinates.
Expected output: The smallest difference possible between the area of the(not necessarily convex) polygon and the triangle containing it. The triangle also has to share at least 2 vertices with the polygon. If there is ... |
Christmas is coming up, and this year you have been charged with organizing your family's christmas get-together. You have a list of foods you want be there, but before you assign foods to people, you need to know who's coming. So...
Challenge
Given an input of relative's names separated by commas or whatever (note tha... |
You have been given N piles of coins. You have decided to divide each of those B1, B2, ..., BN piles among separate groups of people. The amount of people receiving coins has to be a prime number and the amount of money given to each person must be different in each pile.
Input: N, B1, B2, ..., BN (The amount of coins ... |
Given an input of a note, output an ASCII drawing of the corresponding major
key on the treble clef.
Here are all the major keys (that don't include double-sharps or double-flats)
and their corresponding key signatures:
Circle of fifths deluxe 4 by Wikipedia user Just plain Bill, copyright CC BY-SA 3.0
If the input is... |
Introduction
You have a friend that keeps asking you for loans and you are getting tired of it. Today, he came for a loan again. Instead of turning down his offer, you get a great idea: troll your friend by giving him as many coins/bills as possible.
Challenge
You will take as input: the amount of money your friend wa... |
Background
A typist comes home wfter some riugh drinkinh and realizes thag an importsnt letter still needs to be wtitten. To make sure he vets the text correct, he writes the text character bh vjaracter t0 be sure of 6he resuly. However, he dtill manages t0 miss some ofbthe keys.
Yout task is to write cose that simulat... |
Challenge
We all know about normal Christmas trees - but how about an upside-down Christmas tree! This is a fairly easy, Christmas themed challenge. The objective of this challenge is to make me an ASCII upside-down Christmas tree. Here are the rules for this challenge:
Accept an odd, positive integer. You can assume ... |
In this challenge you will be asked to implement any function (or full program) that fulfills two properties. Those properties are:
Your function must be an injective (reversible) function from the polynomials with non-negative integer coeffecients to the non-negative integers. This means no two unequal inputs can m... |
Challenge
Your task is to write a program which, once a second (including immediately when your program is started), prints the elapsed time from the time your program was started.
Rules
Time must be printed in hh:mm:ss format. (leading zeros for single-digit values)
The time stamps must be separated by CR, LF, or CRL... |
In this challenge I will ask you to find a QR decomposition of a square matrix. The QR decomposition of matrix A is two Matrices Q and R such that A = QR. In particular we are looking for Q to be an orthogonal matrix (that is QTQ=QQT=I where I is the multiplicative identity and T is the transpose) and R to be a upper... |
Starting with a positive integer N, find the smallest integer N' which can be computed by repeatedly dividing N by one of its digits (in base-10). Each selected digit must be a divisor of N greater than 1.
Example #1
The expected output for N = 230 is N' = 23:
Example #2
The expected output for N = 129528 is N' = 257:... |
In chat, we are often fast-typers and don't really look at the order of letters before posting a message. Since we are lazy, we need a program that automatically swaps the last two letters in our words, but since we don't want to respond too late, the code must be short.
Your task, if you wish to accept it, is to write... |
Your program must print out this exact sequence:
1
2
4
10
24
54
116
242
496
1006
2028
4074
8168
16358
32740
65506
131040
262110
NOPE!
As usual, shortest program wins. Standard code golf rules apply.
|
A set of dominoes consists of tiles with two numbers on them such that every combination of integers from 0 to N are represented. Examples below refer to N=6 out of convenience, but N=9 and N=12 are also common. The orientation of the tiles does not matter (they are usually printed with dots rather than digits), so [1-... |
Given a key, and an array of strings, shuffle the array so that it is sorted when each element is XOR'd with the key.
XOR'ing two strings
To XOR a string by a key, XOR each of the character values of the string by its pair in the key, assuming that the key repeats forever. For example, abcde^123 looks like:
a ... |
Write a program or function that takes N, and S and outputs the number of palindromes of length S you can build using an alphabet of size N such that any prefix of size between 2 and S-1 is not a palindrome.
For example if N were 2 and S were 5
The valid palindromes would be
01110
10001
And thus the answer would be 2
... |
Background
The nuclear industry has term, SCRAM, used to describe a quick shutdown of the reactor. There's a fun myth that it stands for "Safety Control Rod Ax Man," the role which served to shut down the Chicago Pile if it got too hot by literally cutting a rope with an ax (although this was debunked).
The US Nuclear... |
Your task is to print the text Good morning, Green orb!, with every character repeated in place as many times as the most frequent byte in your source (the mode). A trailing newline is permitted and need not be repeated.
For example if your source was
print p
Since p appears twice and every other byte appears once yo... |
(There exists some challenges that require to use the best strategy, but here we don't. Even if you are able to win, you are allowed to make a tie)
Challenge
Write a program which plays the game tic-tac-toe. It must not lose (therefore, it should end the game either with a tie or by winning).
Allowed I/O methods
Input... |
Left and right Riemann sums are approximations to definite integrals. Of course, in mathematics we need to be very accurate, so we aim to calculate them with a number of subdivisions that approaches infinity, but that's not needed for the purposes of this challenge. You should instead try to write the shortest program,... |
Imagine enumerating the elements of rhombi which grow [1],[1,3,1],[1,3,5,3,1],… (only odd numbers such that they align nicely). This would look like as follows, note that you always begin enumerating with 1:
01
1 02 03 04
1 2 3 4 05 06 07 08 09 …
5 10 11 12
... |
A doubly linked list is a data structure in which each node has a value as well as "links" to both the previous and next nodes in the list. For example, consider the following nodes with values 12, 99, and 37:
Here, the nodes with values 12 and 99 point to their respective next nodes, with values 99 and 37. The node w... |
What is the shortest way we can express the function
f(a,b)(c,d)=(a+c,b+d)
in point-free notation?
pointfree.io gives us
uncurry (flip flip snd . (ap .) . flip flip fst . ((.) .) . (. (+)) . flip . (((.) . (,)) .) . (+))
which with a little bit of work can be shortened to
uncurry$(`flip`snd).((<*>).).(`flip`fst).((.... |
The idea of this is mainly from BIO 2017 q1. I got the idea for posting this challenge from my Binary Sequences challenge, since lots of people seemed to like it.
Also, this is the first challenge I've posted without posting on the sandbox. I'll delete it if no one likes it.
Rules
Take in a sequence of digits in ternar... |
Rules
Given a list of integer coordinates, l, with a length of at least 4, and an integer n such that n is smaller than the length of l (but at least 3), return the largest area of an n-sided polygon satisfies:
is simple (not self-intersecting).
has all the coordinates of its n vertices in the list l.
has no three con... |
Today while playing with my kids I noticed that an apparently simple toy in the park hid a challenge.
The wheel has a triangle that points to a number, but also has three circles that point to the numbers every 90 degrees from the first one. So:
Challenge (really simple)
Given an integer between 1 and 12 (the one poi... |
It is the year MDLXVII in a world in which the Roman Empire never fell, and the collapse into the dark ages never occurred. Due to the extended period of Pax Romana, the empire's economic stability enabled technology to progress at a rapid rate.
The Romans have begun to dabble with circuitry, and have invented an inge... |
Challenge
Given a non-negative integer, output whether it is possible for two dates (of the Gregorian calendar) differing by exactly that many years to share a day of the week. A year is assumed to be a leap year either if it is divisible by 4 but not by 100, or if it is divisible by 400.
Output may be:
falsey/truthy ... |
So you want to create a haiku, but you're not sure if it follows the syllable rules for a haiku.
I couldn't be bothered to write a proper blurb like I usually do, so you'll have to make do with this. Let's get stuck right in.
Finding a haiku out in the wild
For the purposes of this challenge, we will be checking if the... |
Robbers post
A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle shuffle a string:
Split the string into equal sections.
Reverse the strings, and starting from the start of each string.
Pu... |
Cops post
A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle shuffle a string:
Split the string into equal sections.
Reverse the string, and starting from the start of each string.
Put ru... |
It is well known that odd primes will appear in Pascal's triangle exactly twice. However, not all numbers that appear exactly twice in Pascal's triangle are prime. We'll call these numbers Pascal primes.
Pascal primes are composite numbers that appear exactly twice in Pascal's triangle. The first few Pascal primes are... |
I really like times that follow certain patterns. In particular, I like times where all the digits are the same, or all of the digits increase arithmetically by one from left to right. Further, I viscerally hate when people put letters in my times, so all of that AM/PM nonsense is dead to me. Thus, my favorite times ar... |
A riffle shuffle is a type of shuffle where the deck is split into two partitions and the partitions are then spliced back together to create a new shuffled deck.
The cards are spliced together in such a way that cards maintain their relative order within the partition they are a member of. For example, if card A is b... |
Inspired by Taken from a question at Stack Overflow.
The challenge
Given an integer n>1, output all arrays that can be obtained by swapping exactly two entries in the array [1, 2, ..., n].
The arrays can be produced in any order.
You can consistently use [0, 1, ..., n-1] (0-based) instead of [1, 2, ..., n] (1-based).
A... |
Challenge
Given a grid like this,
1 2 3 4 5 6 7 8
1 . . . . . . . .
2 . # . . . # . .
3 . . . . . . . .
4 . . . . . . . .
5 . . . . . . . .
6 . . # . . . . .
7 . . . . . . . .
8 . . . . . . . .
write a piece of code that can determine the size of the largest square that does not include a '#'. (The answer to this in... |
Balanced ternary logic
Ternary is normally another name for base 3, that is to say, each digit is 0, 1, or 2, and each place is worth 3 times as much as the next place.
Balanced ternary is a modification of ternary which uses digits of -1, 0 and 1. This has the advantage of not needing a sign. Each place is still worth... |
Challenge
Given any positive integer supported by your language:
Take the input and divide it into two halves. For all divisions in this program, if the input is odd, round one half up and one half down (ex: 7 -> 3,4, not 7 -> 3.5,3.5).
Divide either number in half, then take the larger of these two new halves and add... |
Yesterday I asked this question about riffle shuffles. It seems that yesterdays question was a bit too hard so this question is a related but much easier task.
Today you are asked to determine if a permutation is in fact a riffle shuffle. Our definition of riffle shuffle is adapted from our last question:
The first ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.