instruction
stringlengths
34
53.1k
Background I am currently in an AP Comp Sci A: Java class, and I want to start some of my friends on code golfing. I have a challenge from the course, and I would like to see how many bytes the community can do this challenge in. Challenge details: Given two input strings, the main string and the pivot string, do the ...
Given an integer \$x_1\$ and some black box function \$f: ℤ → ℤ\$ find a fixed point of \$f\$ in the sequence defined by \$x_{k+1} := f(x_k)\$. Details A value \$x\$ is said to be a fixed point of \$f\$ if \$x = f(x)\$. For instance if \$f(x) = \text{round}(\frac{x}{\pi})\$ and we have a starting point \$x_1 = 10\$ t...
Let's define a self-contained number as a positive integer, whose digits appear in runs of length equal to themselves only. In other words, any decimal digit d (excluding 0) occurs only in runs of length exactly d. Task You can choose any of the three methods listed below: Given an integer n, output the nth (either 0 ...
The main purpose of the RGB (Red Green Blue) color model is for the sensing, representation and display of images in electronic systems, such as televisions and computers HSL (Hue Saturation Lightness) is an alternative color model, designed in the 1970s by computer graphics researchers to more closely align with the ...
There has not been a challenge regarding slope fields, as a far as I can tell. So, I might as well make one. The challenge Given: A black box function f which takes two arguments, x and y (both real numbers) , and returns the value of the slope at point (x,y) (also a real number) A list of real numbers, X, representi...
Adapted from this FiveThirtyEight riddle. Background Examine the following infinite sequence: 3 3 3 2 3 3 3 2 3 3 3 2 3 3 2 3 3 3 2 ... Let's say the sequence is 1-indexed. The ith number in the sequence determines how many 3s there are before the ith 2 and following any previous 2s. So since the sequence starts with ...
Write an indefinitely-running program that reports how many instances of itself are currently running. Each instance of the program should also report the order in which it was opened out of all other currently-running instances. Example The user launches the program for the first time - we'll call this Instance 1. Ins...
A follow-up to this challenge Given a set of mixed dice, output the frequency distribution of rolling all of them and summing the rolled numbers on each die. For example, consider 1d12 + 1d8 (rolling 1 12-sided die and 1 8-sided die). The maximum and minimum rolls are 20 and 2, respectively, which is similar to rolling...
Background I was working on a StackOverflow helper program (that sends me notifications) when I noticed something rather interesting in StackOverflow's Network tab: StackOverflow uses WebSockets (not too surprising, but good to know)! For this challenge, we will be conquering StackOverflow's web socket server. This p...
Background: This question is a remix of the one that I made previously on this forum. The only difference with this one is: the range is significantly larger, AND dynamic. Details below! Also, I'm typing this question incredibly quickly, so if there are any grammatical errors, I do apologize and ask if anyone would edi...
Task Given two positive integers (dividend and divisor), calculate the quotient and the remainder. Normally it would be calculated as e = o*q+r where q*o<=e and 0<=r<o. For this challenge it still e = o*q+r but q*o>=e and -o<r<=0. For example e=20 and o=3, normally it would be 20/3 -> 20=3*6+2, since 18<=20 and 0<=2<3....
<< Prev Thanks to the PPCG community, Santa now has balanced his storage carts. Now, he needs to move them into the transport docks so that they can be sent to the loading bays. Unfortunately, the tracks to move the carts around are a mess, and he needs to figure out how to get them all around without them crashing tog...
GPA Calculator (GPA = Grade Point Average) You are a stressed out college student during finals week. Instead of studying for your exams coming up, you decide it is best to determine what GPA you will have at the end of the semester. This way you have data to back up your decision of staying up all night to get that A ...
In APL, you can write tacit functions, called trains. How they work is irrelevant for this challenge. Here are the different ways they can be grouped, using ⍴ as the function: ⍴ -> ⍴ ⍴⍴ -> ⍴⍴ ⍴⍴⍴ -> ⍴⍴⍴ ⍴⍴⍴⍴ -> ⍴(⍴⍴⍴) ⍴⍴⍴⍴⍴ -> ⍴⍴(⍴⍴⍴) ⍴⍴⍴⍴⍴⍴ -> ⍴(⍴⍴(⍴⍴⍴)) ... The order remains the same. The procedure is...
Near the middle of the semester in chemistry, we get problems like: Convert 1.283850057 to Scientific Notation and Convert 3.583✕106 to Standard Notation This is just stupid busy work for people who already know how to do this. So… The Challenge Given an input in any reasonable, convenient format, in either standar...
In atomic physics and quantum chemistry, the electron configuration is the distribution of electrons of an atom in atomic orbitals. For example, the electron configuration of the neon atom is 1s2 2s2 2p6 (From Wikipedia) Challenge Your challenge is to take a number representing the atomic number of an element and out...
For any String that is composed of lower cased alphabetical characters, make a function that returns a list of all of it's variations, empty strings returns empty list Test Cases "" -> [] "a" -> ["a", "A"] "ab" -> ["ab", "Ab", "aB", "AB"] "abc" -> ["abc", "Abc", "aBc", "ABc", "abC", "AbC", "aBC", "ABC"] This is Code-g...
Given an Integer array: Start from the first number Jump forward n positions where n is the value of the current position Delete the current position, making what was the next position the current position. Goto step 2 until there is one number remaining Print that number Rules The array wraps-around (the next number...
Yahtzee is a game played with five six-sided dice and a score sheet with thirteen different boxes to fill a score in. Each box has its own scoring rules: 1s, 2s, 3s, 4s, 5s, 6s all score points equal to the sum of the respective dice (that is, a roll of [3, 2, 3, 1, 5] scored as 3s would be awarded 6 points: 3 for eac...
In case you missed Encode Factor Trees, here is the definition of a Factor Tree: The empty string is 1. Concatenation represents multiplication. A number n enclosed in parentheses (or any paired characters) represents the nth prime number, with 2 being the first prime number. Note that this is done recursively:...
Given 2 random circle sections, return how many times they intersect. Rules/clarifications are as below. You are provided 10 total values, The center (x,y) of the circle section Angles of the circle (i.e. (0,90) would be a quarter circle "facing" the top-right corner. The radius of the circle section The circle s...
For another challenge I am writing, I need to verify that test cases are solveable with bounded integers. Specifically, I need to verify the following, for a non-empty array of integers A and an integer bit width n: All integers a in A satisfy -2**(n-1) <= a < 2**(n-1) (representable with n-bit two's complement intege...
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...