instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Introduction If \$\newcommand{\fib}{\operatorname{fib}}\fib(x)\$ calculates the \$x\$th Fibonacci number, write a program that calculates \$\fib(\fib(m))\$ for any integer value of \$m \ge 0\$. (Of course, there will be practical limits based on the language, so lesser limits are acceptable. Also, it's okay to stop at ...
stackexchange_codegolf
The gambler's fallacy is a cognitive bias where we mistakenly expect things that have occurred often to be less likely to occur in the future and things that have not occurred in a while to be more likely to happen soon. Your task is to implement a specific version of this. Challenge Explanation Write a function that r...
stackexchange_codegolf
This is a sequence question of the usual type, as applied to OEIS sequence A038666. That is, do either of the following: Accept no or any input, and output A038666 until the heat death of the universe. Accept a positive integer as input, and output the \$n\$th term of A038666 or its first \$n\$ terms. (If using \$0\$-...
stackexchange_codegolf
In this challenge you and your friends are debating on which case is better, uppercase or lowercase? To find out, you write a program to do this for you. Because esolangs scare your friends, and verbose code scares you, your code will need to be as short as possible. Examples PrOgRaMiNgPuZzLeS & CoDe GoLf 0.52 upperca...
stackexchange_codegolf
Take an arbitrarily sized string as input. This string represents a baseball plate appearance, in which each character represents a pitch as follows: Strike: S Ball: B Foul ball: F Hit by pitch: H Ball in play: X (For those wondering, this is a very very simplified version of Retrosheet's notation) Your program must...
stackexchange_codegolf
Given an input string, write a program that outputs the total number of lines and curves it has. The Challenge Take input from STDIN, or any other input method. Output to STDOUT, or any other output method, the total number of lines and curves contained in the string, in that order, based on the below table in the cod...
stackexchange_codegolf
Introduction: A Dutch BSN (BurgerServiceNummer) is valid when it complies to the following rules: It only contains digits. The length should be either 8 or 9 in length. When the digits are indexed as A through I, the result of the following sum: 9xA + 8xB + 7xC + 6xD + 5xE + 4xF + 3xG + 2xH + -1xI (NOTE the -1 instead...
stackexchange_codegolf
This challenge was originally posted on codidact. You are a low-level censor working for the Ministry of Media Accuracy. Part of your job is to make sure that certain words don't appear in publications. Every morning you get a fresh stack of next week's newspapers and its your job to comb through them and fix any of ...
stackexchange_codegolf
Surprisingly, I don't think we have a code-golf question for determining if a number is semiprime. A semiprime is a natural number that is the product of two (not necessarily distinct) prime numbers. Simple enough, but a remarkably important concept. Given a positive integer, determine if it is a semiprime. Your ou...
stackexchange_codegolf
The Collatz Conjecture The famous Collatz Conjecture (which we will assume to be true for the challenge) defines a sequence for each natural number, and hypothesizes that every such sequence will ultimately reach 1. For a given starting number N, the following rules are repeatedly applied until the result is 1: While N...
stackexchange_codegolf
Write a program that produces an output such that: At least three distinct characters appear. The number of occurrences of each character is a multiple of 3. For example, A TEA AT TEE is a valid output since each of the 4 distinct characters, A, E, T and (space), occurs 3 times. Of course, a challenge about the numbe...
stackexchange_codegolf
A number is a de Polignac number if and only if it is odd and cannot be represented in the form p + 2n where n is a non-negative integer and p is a prime integer. Task Write some code that takes a positive integer and determines if it is a de Polignac number. You may output two distinct values one for true and one for...
stackexchange_codegolf
Pascal's Rhombus (which is actually a triangle) is obtained by adding in the pattern: * *** x instead of * * x This means that each cell is the sum of the three cells on the row directly above it and one cell on the row 2 above it. Just like Pascal's triangle the zeroth row has a single 1 on it that generates...
stackexchange_codegolf
Your challenge is to write a Python program to print all the primes (separated by whitespace) less than a given integer N with an asterisk (*) next to each twin prime in ONE statement. A twin prime is a prime number that is either two more or two less than another prime. All output should be to stdout and input should ...
stackexchange_codegolf
In Conway's Game of Life, there is an infinite square grid of cells, each of which is alive or dead. The pattern changes each "generation". A dead cell with exactly 3 live neighbors (orthogonal or diagonal) becomes a live cell. A live cell only lives to the next generation if it has 2 or 3 live neighbors. These simple ...
stackexchange_codegolf
Imagine the following 24-hour clock that can be controlled by arrow keys: ╔══╗ ┌──┐ ║00║:│00│ ╚══╝ └──┘ HH mm Pressing the up arrow twice (↑↑) will increase the currently focused hour input: ╔══╗ ┌──┐ ║02║:│00│ ╚══╝ └──┘ HH mm Pressing the right arrow (→) will focus the other input. ┌──┐ ╔══╗ │02│:║00║ └──┘ ╚══...
stackexchange_codegolf
Introduction Factorials are one of the most frequently used examples to show how a programming language works. A factorial, denoted \$n!\$, is \$1⋅2⋅3⋅…⋅(n-2)⋅(n-1)⋅n\$. There is also the superfactorial (there are other definitions of this, but I chose this one because it looks more like the factorial), denoted \$n$\$,...
stackexchange_codegolf
Task Given two positive integers \$m,n\$, imagine a chessboard of size \$m \times n\$. A chess queen is on the upper-left corner. In how many ways can it reach the lower-right corner, by moving only right, down, or diagonally right-down (possibly moving many steps at once, because it's a queen)? The resulting 2D sequen...
stackexchange_codegolf
The challenge given to me is comparatively easy, and specific to MySQL only. I'm given a table expressions which have mathematical calculations done by a kid. Basically, I've to select all the right calculations! The table have the following properties, a : an integer, the left operand. b : an integer, the right opera...
stackexchange_codegolf
Intro/Background I was looking at a Flybuys card at Coles recently and noticed that if I took something like this: Source, randomly found on the Internet And swapped some words around, I'd get this: After I finished laughing (don't judge my sense of humour please), I said to myself: "I need a program that can gener...
stackexchange_codegolf
This challenge is pretty simple: Your task is to draw a schematic of a (simplified) memory array. You will be given two (positive) integers n,m and the task is to draw the n:2^n decoder connected to the memory array with d data lines. The addressing will be in the order of gray codes, to check if the sequence is correc...
stackexchange_codegolf
The three-dimensional Levi-Civita symbol is a function f taking triples of numbers (i,j,k) each in {1,2,3}, to {-1,0,1}, defined as: f(i,j,k) = 0 when i,j,k are not distinct, i.e. i=j or j=k or k=i f(i,j,k) = 1 when (i,j,k) is a cyclic shift of (1,2,3), that is one of (1,2,3), (2,3,1), (3,1,2). f(i,j,k) = -1 when (i,j...
stackexchange_codegolf
Challenge Create a new file and write the string Hello World to it. Restrictions Your challenge must write to a file on disk, in the file system. The file may not be a log file generated during normal operation of the interpreter. The file must contain only the string Hello World. It is allowed to contain a trailing n...
stackexchange_codegolf
This is a code-challenge with a custom scoring system, where the lowest score wins. Introduction Many smartphones allow to enter text by swiping your finger across the 2D virtual keyboard. This technology is usually combined with a prediction algorithm that outputs a list of guessed words, sorted from most likely to le...
stackexchange_codegolf
The least common multiple (LCM) of a set of numbers A is the smallest integer b such that b/a is an integer for all integers a in A. This definition can be extended to rational numbers! Task Find the smallest positive rational b such that b/a is an integer for all rationals a in the input. Rules Standard loopholes are...
stackexchange_codegolf
In most programming languages, the string Hello, World! can be represented as "Hello, World!". But if you want to represent "Hello, World!" you need to escape the double quotes with backslashes for "\"Hello, World!\"", and to represent that you also need to escape the backslashes resulting in "\"\\\"Hello, World!\\\"\"...
stackexchange_codegolf
This answer-chaining challenge is officially over, resulting in the win of Wheat Wizard, with a total of 7 answers. Any other answer is welcome, but it won't influence the accepted answer for this challenge, nor the winner. Task: Print all the positive divisors of a number x taken as input. Input: A single number x w...
stackexchange_codegolf
The challenge given to me is comparatively easy, and specific to MySQL only. I'm given a table expressions which have mathematical calculations done by a kid. Basically, I've to select all the right calculations! The table have the following properties, a : an integer, the left operand. b : an integer, the right opera...
stackexchange_codegolf
Don't tell anyone, but I've nicked my uncle's time travel machine! My uncle is obsessed with prime numbers, though, and that shows in the machine — he has programmed it so that it can only go to dates that sum up to a prime number. So it can't go to 1947-08-15 because 1947+8+15 = 1970, which is not a prime number. It ...
stackexchange_codegolf
Introduction Consider a sequence of integers \$f\$ defined as follows: \$f(2) = 2\$ If \$n\$ is an odd prime, then \$f(n) = \frac{f(n-1) + f(n+1)}2\$ If \$n = p\cdot q\$ is composite, then \$f(n) = f(p)\cdot f(q)\$ It's not very hard to see that \$f(n) = n\$ for every \$n \ge 2\$, and thus computing \$f\$ wouldn't be...
stackexchange_codegolf
Problem Create a program or function that can calculate the result of a matrix raised to the nth power. Your code will take an arbitrary square matrix A and a non-negative integer n, and return a matrix with the value An. Restrictions Built-in functions that compute the matrix power and matrix product are not allowed. ...
stackexchange_codegolf
Intro In Objective-C (a superset of C and an object-oriented language), I can create an object called a UIWebView. There is a method for this object called loadHTMLString: in which I can load actual HTML into the UIWebView object itself. I can also inject Javascript into it using the method stringByEvaluatingJavaScript...
stackexchange_codegolf
Eyeballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation. So I want to take a number, say 3 (00000011) and output the bits in user-defined format, for example with space separated pairs: 0...
stackexchange_codegolf
The new xkcd feed bot room gave me an idea for a simple challenge. Your code will have to monitor the xkcd website and output all the new comics to the user. Specs When first run it should just sit around waiting. Then, when randall posts a new comic, within a minute, it should display the new comic in any of our usua...
stackexchange_codegolf
In this challenge posed by xnor, we were asked to implement XOR multiplication. In this challenge the goal is to find the first n XOR primes. XOR primes are very similar to regular primes as you can see by the following definitions: Definition of Prime Number: A positive number greater than 1 which cannot be formed thr...
stackexchange_codegolf
I assume everyone here is familiar with the Caesar Cipher that shifts letters to a certain index. https://en.wikipedia.org/wiki/Caesar_cipher for those who still needs introduction. But, we can all agree that plain Caesar is unfun and way too easy. So here's a version that also shifts characters around. This version fi...
stackexchange_codegolf
Problem Let's define a generalized Cantor set by iteratively deleting some rational length segments from the middle of all intervals that haven't yet been deleted, starting from a single continuous interval. Given the relative lengths of segments to delete or not, and the number of iterations to do, the problem is to w...
stackexchange_codegolf
Background A snake is a path over the cells of a square grid, such that it doesn't touch itself on a side of a unit square. Touching at a corner is allowed. An example snake: ##.#. .#.## ##..# #.### ###.. Some example non-snakes: ###.# #.#.# ##### .#... .#### ### .#. ## ## Challenge Given an empty grid with the two...
stackexchange_codegolf
Inspired by this post over on Puzzling. Spoilers for that puzzle are below. Given three positive integers as input, (x, y, z), construct the inclusive range [x, y], concatenate that range together, then remove z not-necessarily-consecutive digits to produce the largest and smallest positive integers possible. Leading z...
stackexchange_codegolf
Introduction This problem is a challenge that has to do with DOM manipulation at scale and overcoming some issues that may be inherent in dealing with the DOM. This challenge is interesting because limitations push us to think through things differently and lean on the strengths of languages different than what we usu...
stackexchange_codegolf
Print or return the following text: Hello world! The quick brown fox jumps over a lazy dog. However, your submission will not be scored in bytes. Instead, primarily it will be scored by the width in pixels of the program when written in Arial in a 12pt font. In particular, the score is: $$ (\text{visual width in px}) ...
stackexchange_codegolf
Given a list of integers find the "trajectory" that results from indefinitely moving the instructed steps to the right (left if negative), wrapping if necessary, starting at the first element. A "trajectory", here, is defined as a list containing the elements that are visited only one time, in the order they are visite...
stackexchange_codegolf
Challenge Create a function or program that, when given an integer size, behaves the following way: If size is equal to 1, output ┌┐ └┘ If size is greater than 1, apply the following substitutions : Source Target ┌ ┌┐└┌ ┐ ┌┐┐┘ └ ┌└└┘ ┘ ┘┐└┘ Note: this is basically a Unicode box-drawing version of the...
stackexchange_codegolf
Take the decimal number \$0.70710678\$. As a fraction, it'd be \$\frac{70710678}{100000000}\$, which simplifies to \$\frac{35355339}{50000000}\$. If you were to make the denominator \$1\$, the closest fraction is \$\frac{1}{1}\$. With \$2\$, it'd be \$\frac{1}{2}\$, and with \$3\$ it's \$\frac{2}{3}\$. Because \$0.\bar...
stackexchange_codegolf
Futoshiki is a logic puzzle where an \$n×n\$ Latin square must be completed based on given numbers and inequalities between adjacent cells. Each row and column must contain exactly one of each number from \$1\$ to \$n\$ while satisfying the inequalities. In a solved Futoshiki puzzle any row (or column) forms a linear ...
stackexchange_codegolf
Consider you have a hash function \$\mathcal{H}\$ which takes strings of length \$2n\$ and returns strings of length \$n\$ and has the nice property that it is collision resistant, i.e. it is hard to find two different strings \$s \neq s'\$ with the same hash \$\mathcal{H}(s) = \mathcal{H}(s')\$. You would now like to ...
stackexchange_codegolf
I was seen multiple shortest "Hello World!" program, but this is the longest program. The Rules Each submission must be a full program. This must be non-interpreted language (for example, JavaScript, Python, HTML, etc.) Target OS must be Windows, Mac, Linux or MS-DOS. The challenge Writing a longest Hello World prog...
stackexchange_codegolf
I'm designing a new space station for generic super-villain purposes (something something megalaser), but I'm having trouble designing the solar panels. My genius team of scientists can calculate exactly how many square meters of paneling we need to power the station, but the problem is our solar panels only come in sq...
stackexchange_codegolf
Your function must accept one string and return the opposite The opposite string is a string where all characters go in reverse order, all letters are replaced with the opposite mirror letter from the English alphabet and are changed in case, and all digits are replaced with opposite mirror digits opposite mirror for l...
stackexchange_codegolf
Minecraft 1.12 will be released tomorrow, so let's celebrate! Write code that takes in a non-negative integer N which represents the number of items of something in Minecraft. Output it in a way more helpful to players, giving the number of chests, stacks, and items N is equivalent to. Use the format XcYsZi where X i...
stackexchange_codegolf
First, some terminology (source): A hip roof is (quoting Wikipedia) "a type of roof where all sides slope downwards to the walls, usually with a fairly gentle slope" A slope is a planar surface that is a part of the roof A ridge is an edge where two opposite roof slopes meet A hip is a convex edge where two slopes bel...
stackexchange_codegolf
Challenge Write a program that applies an injective function which takes an ordered pair of strings as input and one string as output. In other words, each input must map to a unique output. Specifics The input may be any two strings of arbitrary length, but will consist only of printable ASCII characters (codes \$[32...
stackexchange_codegolf
Golf Challenge Given the below ASCII "Green". | | | |> | | | | | O | | | | | | | | | | | | | Let | Denote a wall Let | Denote half the flag pole Let > Denote the flag on the pole Let O Denote the hole Let o Denote the ball The dimens...
stackexchange_codegolf
The Challenge: For an input of one letter X (upper or lower case from A to Z) and one digit N (0-9) print the corresponding letter X made of N * X. The letter has to be from this list: AAA BBBB CCCC DDDD EEEEE FFFFF GGG H H A A B B C D D E F ...
stackexchange_codegolf
A cyclic number is a number of "n" digits that when multiplied by 1, 2, 3,...n, results in the same digits but in a different order. For example, the number 142,857 is a cyclic number since 142,857 x 2 = 285,714, 142,857 x 3 = 428,571, 142,857 x 4 = 571,428, and so on. Given an integer input, determine if it is a cycli...
stackexchange_codegolf
Given a POSIX Extended Regular Expression as input, output its complement (also a POSIX ERE). If the given regular expression matches a string, its complement should not match it, and the regex: (regex given)|(complement) should match any string. In other words, negate the regex. The regex for format input and for outp...
stackexchange_codegolf
Task Given a string as input, generate a "blurred" version of that string. Input Your input will be a single-line string of ASCII characters, containing a minimum of 2 alphanumeric characters Output A string that is the "blurred" version of the input string. A blurred string is one where every alphanumeric character fr...
stackexchange_codegolf
This is my first attempt at a Code Golf question. If it needs obvious edits, please feel free to make them. Below is a description of the basic Dropsort algorithm. Dropsort is run on a list of numbers by examining the numbers in sequence, beginning with the second number in the list. If the number being examined is l...
stackexchange_codegolf
Your task is to take an input, for example: a,b,4,5 And produce an output, which per this example is aaaabbbbb a,b,4,5 means: the lowercase character "a" is repeated 4 times, and is then followed by the lowercase character "b" repeated 5 times, making the total number of characters 4+5=9 Another example: the input a,B,...
stackexchange_codegolf
Write a program that prints an associative array (key-value) to a table. Requirements Standard loopholes are forbidden Please include a link to an online interpreter and the byte count in the answer Use box drawing characters to draw the table. You can write both a full program or a function. Key or value can't cont...
stackexchange_codegolf
Write a program to calculate the first 500 digits of the mathematical constant e, meeting the rules below: It cannot include "e", "math.e" or similar e constants, nor may it call a library function to calculate e. It must execute in a reasonable time (under 1 minute) on a modern computer. The digits are to include the...
stackexchange_codegolf
Your task Given a string, output the range of ASCII values. Example Let's say we have the string Hello. We get the ASCII values: H = 72 e = 101 l = 108 l = 108 o = 111 Now, we get the range (max - min): 111 - 72 = 39 Our answer is 39. Test cases Input Output Hello, World! 82 aaaaa 0 Code Golf ...
stackexchange_codegolf
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \end{cases} $$ Since it can be proved that it always terminates and evaluates to the simple function below, $$ t(x, y, z) = \begin{...
stackexchange_codegolf
Introduction Suppose you have a list of lists of integers (or any objects really, but let's stick to integers for simplicity). The lists may be of different lengths, and some of them may be empty. Let's write the lists in a tabular format: [[ 1, 2, 3, 4, 5], [ 6, 7], [ 8, 9, 10, 11], [], [12, 13, 14...
stackexchange_codegolf
Inspired by this question from our rivals friends over at Code Review. Definitions A super array is an array where each new element in the array is larger than the sum of all the previous elements. {2, 3, 6, 13} is a super array because 3 > 2 6 > 3 + 2 (5) 13 > 6 + 3 + 2 (11) {2, 3, 5, 11} is not a super array, becaus...
stackexchange_codegolf
Your challenge is to write a Python program to print all the primes (separated by whitespace) less than a given integer N with an asterisk (*) next to each twin prime in ONE statement. A twin prime is a prime number that is either two more or two less than another prime. All output should be to stdout and input should ...
stackexchange_codegolf
You have to write a program or a function in any language that outputs this pattern: ~|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||~ |~|||||||||||||||||||||||||||||||||||||||||||||||||||||||||~| ||~|||||||||||||||||||||||||||||||||||||||||||||||||||||||~|| |||~|||||||||||||||||||||||||||||||||||||||||||||...
stackexchange_codegolf
Usually each cell in brainfuck has 256 states, which is not enough to tell whether input is EOF or a character (usually \xFF). To fix it we can add one more state to it, and EOF (256) isn't mistake from a byte. Since outputting EOF is also not defined, . on 256 works as reading, and therefore , is removed from the mod...
stackexchange_codegolf
To quote http://brainfuck.org/utm.b: A tag-system transforms strings over an alphabet A = {a[1], a[2], ... a[n], a[n+1]} as follows: a positive integer m is chosen, and so is a function P that maps each a[i] for 1<=i<=n to a string P(a[i]) over the alphabet A. Now: if the string being transformed has fewer than m ele...
stackexchange_codegolf
In this challenge, your job is to find the straightest path from point A to point B in a two-dimensional maze. This is very similar to finding the shortest path, which has been done to death, but instead of minimizing the length of the path, you minimize the number of turns (or angles or corners, whatever you want to c...
stackexchange_codegolf
You get a string which contains an integer between 1000 and 99999999 as input. The input string might contain leading zeroes but cannot be longer than 8 characters. Your goal is to output all dates between 6th of December 1919 and 5th of December 2019 which fit the input in these formats: day - month - year (dmy) mont...
stackexchange_codegolf
The gambler's fallacy is a cognitive bias where we mistakenly expect things that have occurred often to be less likely to occur in the future and things that have not occurred in a while to be more likely to happen soon. Your task is to implement a specific version of this. Challenge Explanation Write a function that r...
stackexchange_codegolf
Write a program, given an input n, will generate all possible n-tuples using natural numbers. n=1 (1),(2),(3),(4),(5),(6)... n=2 (1,1),(1,2),(2,1),(2,2),(1,3),(3,1),(2,3),(3,2),(3,3)... n=6 (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1)... The output may be in any order that does not break any other rules. The program...
stackexchange_codegolf
Gaussian integers are complex numbers \$x+yi\$ such that \$x\$ and \$y\$ are both integers, and \$i^2 = -1\$. The norm of a Gaussian integer \$N(x+yi)\$ is defined as \$x^2 + y^2 = |x+yi|^2\$. It is possible to define a Euclidean division for Gaussian integers, which means that it is possible to define a Euclidean algo...
stackexchange_codegolf
Your task is to build a program that identifies the shape of the input. The shapes to be identified can be any of the following: Square To be identified as a square, the source must have lines of all equal length, and the same number of lines as characters per line (newline characters excluded). An optional trailing ne...
stackexchange_codegolf
You're organizing a treasure hunt for your friends. To conduct things more easily, you want to draw a map of all locations where you hid the precious objects. Input Any form of input denoting a list of points consisting of (nonnegative) x- and y-coordinate, 0 0 being the upper left corner is permitted (Note: You may al...
stackexchange_codegolf
Challenge Imagine a hexagonal grid as shown below. Let's call such a grid has size \$n\$ if it has \$n\$ dots on one side. The following is one of size 3: - - - - - - - - - - - - - - - - - - - Then, pick as many dots as possible on the grid so that no two dots are adjacent. For size 3, the maximum is 7 dots: -...
stackexchange_codegolf
This puzzle is based on this Math.SE post. A more complex version of this problem can be found over here. Assume I have some number of black shirts and some number of white shirts, both at least 1. Both colors of shirt have a non-zero durability. All shirts of a given color start with the same durability. Every day, I ...
stackexchange_codegolf
Given a positive integer, determine if it can be represented as a concatenation of two square numbers. Concatenated numbers may not begin with 0 (except for 0). Any leading zeros in input should be ignored. Examples 11 -> true // because 1 and 1 are squares 90 -> true // because 9 and 0 are squares 1001 -> true // ...
stackexchange_codegolf
When I was younger, I had a big map of the US tacked up on my wall across from my bed. When I was bored, I would stare at that map and think about stuff. Stuff like the four-color-theorem, or which state bordered the most other states. To save younger me some brainpower in counting, you are going to invent a time machi...
stackexchange_codegolf
You task for today: draw a dragon curve! In case you don't know what a Dragon Curve is, here is an introductory ViHart video (Really cool, please watch!) Your task: draw a dragon curve, iterated at least 9 times. You don't have to show iterations 1 through 9, you just have to show the final curve produced after complet...
stackexchange_codegolf
Challenge Create a function or program that, when given an integer size, does the following: If size is equal to 1, output H H HHH H H If size is greater than 1, output X X XXX X X where X is the output of the program/function for size - 1 (If you prefer, you may have the base case correspond to 0, so long as you spe...
stackexchange_codegolf
Related Explanation Given a string such as DCBA, convert it to ASCII ordinals, such as 68 67 66 65. Then, take the differences between each value, eg 67 - 68 = -1, 66 - 67 = -1... giving -1 -1 -1 Now as long as there is more than 1 left over value, repeat getting the differences. For a 3 letter string, your pathway sho...
stackexchange_codegolf
A super prime is a prime whose index in the list of primes is also a prime: 3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, 211, 241, 277, 283, 331, 353, 367, 401, 431, 461, 509, 547, 563, 587, 599, 617, 709, 739, 773, 797, 859, 877, 919, 967, 991, ... For this challenge, an "order 2" super prime is defined...
stackexchange_codegolf
Task Given a list of nodes representing a binary tree of positive integers serialized depth-first, return a list of nodes representing the same tree serialized breadth-first. To represent an absent child, you may use null, 0, 'X', Nothing, [], or any other value that is distinct from your representation of a node's val...
stackexchange_codegolf
Steve Ballmer is the ex-CEO of Microsoft, and in a recent article, claimed that he "still does not know what he did wrong with mobile". As CodeProject's newsletter pointed out, "That article's title could be ended at so many spots and still be accurate". Given no input, output the following: Steve Ballmer still does no...
stackexchange_codegolf
I love ><>, ><> is life! 2D langages are amazing! In this challenge, you will have to say if a "fishy" road has an end, while code-golfing. Definition A fishy road is constructed with tiles, including the following ones: v (go down) > (go right) ^ (go up) < (go left) / (mirror) \ (mirror) Any other character (except -...
stackexchange_codegolf
I like to save time quite literally, by wearing three watches on my wrist... Problem is they each give a different time. One watch is x minutes behind the actual time. One watch is x minutes ahead of the actual time. The last watch shows the actual time. Problem is, I can't tell which watch has the correct time... Fro...
stackexchange_codegolf
Introduction Nine-Ball is a popular pool game played casually and as a competitive sport. There is one of each numbered ball, with the numbers 1 to 9. The game starts with all 9 of the balls in a diamond shaped rack, like so: 1 2 3 4 9 6 5 7 8 The 1 ball is always at the front of the diamond, and the 9 ball is a...
stackexchange_codegolf
Challenge Given daily arrival and departure times of every train that reaches a railway station, find the minimum number of platforms required for the railway station so that no train waits. In other words, find the maximal number of trains simultaneously present in the station. Input a pair of lists of times: arrival...
stackexchange_codegolf
Given a positive number n, rotate its base-10 digits m positions rightward. That is, output the result of m steps of moving the last digit to the start. The rotation count m will be a non-negative integer. You should remove leading zeroes in the final result, but not in any of the intermediate steps. For example, for t...
stackexchange_codegolf
My Precalc teacher has one of his favorite problems that he made up (or more likely stole inspired by xkcd) that involves a row of n urinals. "Checkmate" is a situation in which every urinal is already occupied OR has an occupied urinal next to them. For instance, if a person is an X, then X-X--X is considered checkmat...
stackexchange_codegolf
Consider the following definitions taken from The number of runs in a string by W. Rytter. Note that word, string and substring are all roughly synonyms. A run in a string is a nonextendable (with the same minimal period) periodic segment in a string. A period p of a word w is any positive integer p such that w[i...
stackexchange_codegolf
(Inspired by last week's Riddler on FiveThirtyEight.com. Sandbox post.) Given a year between 2001 and 2099, calculate and return the number of days during that calendar year where mm * dd = yy (where yy is the 2-digit year). 2018, for example, has 5: January 18th (1 * 18 = 18) February 9th (2 * 9 = 18) March 6th (3 *...
stackexchange_codegolf
Create a quine that cannot be golfed. Your score is your byte count, where higher is better. If someone finds a shorter version, their score is your original byte count, and you lose points Scoring example: original submission, 34 bytes // score is 34 function(this){self.printquine();} golfed, 31 bytes ...
stackexchange_codegolf
Code Python 3, 245 bytes E=print def F(): B,C,A=1,1,1;yield 0 while True:yield B;B,C,A=B+C+A+1,C+A+1,A+1 C=int(input()) D=0 for A in range(C): E(end='*'*(C-(C-A)+1));B=A while 0<B:E(end=' '+chr(42+B)*B);B-=1 E();D+=1 for A in F(): if D==0:E(end=str(A));break D-=1 Try it online! What it does? Takes a number from...
stackexchange_codegolf
This should be easy: given an arbitrary string, your program will give it a name. Requirements Your program will accept an input of a UTF8 string, and output a string representing the input's "name", how you define this name is arbitrary, but it must comply with some conditions. I/O Ranges The input will at most be 382...
stackexchange_codegolf
Given some raw HTML, sanitize it by formatting the spaces, as defined below. Output rules: Like many challenges, this one is inspired by XKCD. First, "untag" all tags with nothing but spaces in them. (<i>te<b> </b>xt</i> becomes <i>te xt</i>). If a tag has nothing in it (like <b></b>, simply delete it and move o...
stackexchange_codegolf
Problem John bought 5 apples. You are given the weights of every group of four apples, and must then find the weights of the apples themselves. For example, if all apples without the first one weigh 798 g, without the second - 794 g, without the third - 813 g, without the fourth - 806 g, and without the fifth - 789 g, ...
stackexchange_codegolf
I'm a developer, and I don't feel like doing my work. I know from XKCD that the best excuse for slacking off is that your code's compiling. Because of this, I think I need some code that will compile forever! And because I'm lazy and don't want to have to type much, this has to be done with the shortest code possible. ...
stackexchange_codegolf