instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
In this challenge, you'll take an answer as input, and print the answer before it. If the answer passed as input is the first answer, print your own submission's source. You'll be passed any answer in the chain up to and including your own answer, but none after it in the chain. For example, if the first submission is ...
stackexchange_codegolf
Given a ragged list, e.g. [[4, 7], [5, 3, [], [6, [2]]]] Your challenge is to sort only the numbers in it. For example, with the above, the result would be [[2, 3], [4, 5, [], [6, [7]]]] The shape of the output should remain the same, only the numeric contents should change. This is code-golf, shortest code wins! All...
stackexchange_codegolf
Given a nonnegative integer n, your solution must output a program in your chosen language whose output has n times as many bytes as the outputted program. Rules You must specify the language and encoding of the programs your solution outputs, and you may not choose different languages or encodings for different input...
stackexchange_codegolf
Consider a non-empty binary matrix M and a natural number n. For the purposes of this challenge, M is said to have blockiness n if it can be built using adjacent square blocks of size n, where each block has equal entries; and it cannot be formed using square blocks of any larger size. Intuitively, n can be thought of ...
stackexchange_codegolf
An integer \$x\in[0,2^{32}-1]\$ divided by an integer \$d\in{[1,2^{31}]}\$ will produce an integral quotient \$q\$ and a remainder \$r\$, so that \$x=d\times q+r\$. Any \$q\$, in fact, can be calculated by the following formula. $$y=\left\lfloor\frac{mx}{2^{32}}\right\rfloor\\q=\left\lfloor\frac{y+f\lfloor(x-y)/2\rfloo...
stackexchange_codegolf
We say two positive integers are anagrams of each other if the digits in one of them (in decimal representation) can be rearranged to form the other. Leading zeros don't count. For example, 110020222 is an anagram of 212102020, but not of 221100011; neither is 22002211 even though it can be written as 022002211. Intere...
stackexchange_codegolf
As the June 2021 Language of the Month is Red, what are some general tips for golfing in Red language? Please suggest tips that are at least somewhat specific to Red (e.g. "remove comments" isn't a valid tip here). Please one tip per answer!
stackexchange_codegolf
Background: I originally posted this question last night, and received backlash on its vagueness. I have since consulted many personnel concerning not only the wording of the problem, but also its complexity (which is not O(1)). This programming problem is an evil spin on an Amazon interview question. Question: Given a...
stackexchange_codegolf
There's a payment machine for laundry in my building which does a few frustrating things. The ones relevant to this challenge are: It doesn't make change. So if you pay over the amount then you are not getting that over-payment back. It doesn't accept coins smaller than 20c. Meaning the only coins it accepts are 20c...
stackexchange_codegolf
(randomly inspired by this question) Let's make a drawing from some pipes | and hyphens -. Choosing a subset, if chosen carefully, you can form a rectangular box or block shape (meaning that the corners are formed by |- or -|). For this challenge, we're concerned only with identifying the corners -- the vertical and ho...
stackexchange_codegolf
The number 113 is the first prime whose length 3 is prime, digital sum 5 = 1 + 1 + 3 is prime, and digital product 3 = 1 * 1 * 3 is prime. A prime that has these 3 properties will be called supremely prime. The primes 11117 and 1111151 are other examples. Goal Write a program that can find the largest supremely prime n...
stackexchange_codegolf
Alternate name: ChessMoveQ Given a list of up to 32 elements, each consisting of 4 elements, and a second list with 4 elements, determine whether the move detailed in the second input is a valid chess move. The first list indicates the position of all 32 pieces on the board. Each element will follow the structure <colo...
stackexchange_codegolf
Write a function which, given the first 12 digits of an ISBN-13 code, will calculate the entire ISBN via calculating and appending an appropriate check digit. Your function's input is a string containing the first 12 digits of the ISBN. Its output is a string containing all 13 digits. Formal specification Write a funct...
stackexchange_codegolf
The Steenrod algebra is an important algebra that comes up in algebraic topology. The Steenrod algebra is generated by operators called "Steenrod squares," one exists for each positive integer i. There is a basis for the Steenrod algebra consisting of "admissible monomials" in the squaring operations. It is our goal to...
stackexchange_codegolf
Background Here in the UK1, these are the income tax rules: You get a personal allowance (untaxed) of up to £12,570: If you earn less than £100,000, you get the full £12,570 as personal allowance For every £2 over £100,000, your personal allowance goes down by £1 After the personal allowance, the next £37,700 is ta...
stackexchange_codegolf
Given a list of words, output a square grid of characters, so that all the words can be read from the grid, by moving horizontally, vertically, or diagonally between characters, without reusing characters in the same word. The grid must be the smallest possible which allows all words to be read. Example B A D R E T E Y...
stackexchange_codegolf
You must produce a function which nests a string s inside an array, n times >>> N("stackoverflow",2) [['stackoverflow']] Parameters: s - An ascii string n - An integer >= 0 Rules Shortest code wins. The output will be a nested array, list or tuple (or similar type based off an array) Test Cases >>> N("stackoverflo...
stackexchange_codegolf
Given an integer 2n, find the number of possible ways in which 2n^2 black pawns and 2n^2 white pawns can be arranged on a 2n by 2n chess board such that no pawn attack another. A black pawn can attack only a white pawn, and vice versa. The usual chess rules of attacking follow, i.e, white pawns attack squares immediat...
stackexchange_codegolf
Sandbox Have y'all ever written an answer with unprintable ASCII characters in it and wished that there was an easy way to represent those characters in a printable way? Well, that's why the Control Pictures Unicode block was invented. However, manually substituting these characters into one's answer is time-consumin...
stackexchange_codegolf
A Sphenic Number is a number that is the product of exactly three distinct primes. The first few Sphenic numbers are 30, 42, 66, 70, 78, 102, 105, 110, 114. This is sequence A007304 in the OEIS. Your Task: Write a program or function to determine whether an inputted integer is a Sphenic number. Input: An integer be...
stackexchange_codegolf
There's a minigame in Super Mario 3D World known as the Lucky House. It consists of a slot machine with 4 blocks. Each block may be one of 5 different icons (Flower, Leaf, Bell, Cherry or Boomerang) and the goal of the player is to get as many identical icons as possible (see a video). The player is rewarded with coin...
stackexchange_codegolf
Given an array where each number represent a color. After iterating each item in the array (for each item in the iteration the pointer can also point to the second-item-to-the-right), and the two colors in the iteration is the same, do the following checking: If there is a different color between the pointed colors, th...
stackexchange_codegolf
In English, nouns can take on two different forms depending on whether they are singular (one) or plural (anything else). For example, we would say "1 dog" but "2 dogs", "0 dogs", "57 dogs" and so forth. In Russian, there are three categories. Instead of "1 dog, 2 dogs, 5 dogs", in Russian it would be "1 собака, 2 соба...
stackexchange_codegolf
Your task is to take an array of numbers and a real number and return the value at that point in the array. Arrays start at \$\pi\$ and are counted in \$\pi\$ intervals. Thing is, we're actually going to interpolate between elements given the "index". As an example: Index: 1π 2π 3π 4π 5π 6π Array: [ 1.1, 1...
stackexchange_codegolf
Introduction Every string has an "alphabet", composed of the characters that make it up. For example, the alphabet of \$abcaabbcc\$ is \${a, b,c}\$. There are two operations you can do with alphabets: getting the alphabet of a string, and seeing if another string has a given alphabet. Challenge Given two strings, you m...
stackexchange_codegolf
The brilliant engineers at <enter company you love to hate> have struck again. This time they've "revolutionised" the generation of random permutations. "Every great invention is simple" they say and their magical new algorithm is as follows: Start with a list 1,2,3,...,n of numbers to permute. For each element x in t...
stackexchange_codegolf
Given n numbers in an array (you can't assume they are integers), I would like to compute the product of all subsets of size n-1. You can do this by multiplying all the numbers together and then dividing by each one in turn, as long as none of the numbers is zero. However, how quickly can you do this with no division...
stackexchange_codegolf
Objective Given an integer \$n\$ interpreted as two's complement binary, output two integers, namely the integer consisting of \$n\$'s bits at places of \$2^0, 2^2, 2^4, \cdots\$, and the integer consisting of \$n\$'s bits at places of \$2^1, 2^3, 2^5, \cdots\$. Note that the input may be negative. Since \$n\$ is inter...
stackexchange_codegolf
Inspired by this and this which was inspired by the first question. I've set my farmers' fields on fire, but unfortunately they saw me do it! If I don't deal with this situation they could report me and then I'd get arrested! So, that shouldn't be too hard. All I have to do is kill them with fire! The field will be an ...
stackexchange_codegolf
A Bit of Background The exterior algebra is a central object in topology and physics (for the physics concept cf. fermion). The basic rule dictating the behavior of the exterior algebra is that \$yx = -xy\$ (and consequently \$x^2 = -x^2 = 0\$). Applying this rule twice we see that \$yzx = -yxz = xyz\$. The product of...
stackexchange_codegolf
Write a program that generates a sequence of numbers starting with zero and then 100 random integers between -9 and 9. That sequence will be displayed like a roller coaster. Any increasing number in the sequence will go up and any decreasing number will go down Sample sequence: 0 1 8 5 -1 -5 7 1 3 3 4 6 9 -2 ... Sampl...
stackexchange_codegolf
The Rules Each submission must be a full program. The program must take input as two comma-separated dates in the form YYYY-MM-DD, and print the number of days that has passed since the second date to STDOUT as if today was the first date (if the second date would be in the future, output a negative number) plus an o...
stackexchange_codegolf
The gravitational binding energy of a planet is the amount of energy required to separate every tiny piece of it so that no piece will orbit or collide with another piece. For a uniform sphere, Wikipedia gives this formula: $$E = \frac{3GM^2}{5R}$$ Where G is the gravitational constant (6.672e-11 m3•kg-1•s-2), M is mas...
stackexchange_codegolf
I am quite proficient in C++ and Java and want to learn competitive programming to participate in contests like Google codejam and other online contests held on sites like CodeChef and Codeforces. I would like to get information about any free resources including websites and courses to learn the "sport". Book suggesti...
stackexchange_codegolf
Write a program that, when run in different languages, outputs a different byte permutation of the code in each language. The exact source code is counted as one permutation. Here "different language" can be different version(Py 2 and Py 3) or different standard flags. It's different output that forces different versio...
stackexchange_codegolf
Preamble A common pain-point when working with rational numbers and decimals is how infrequently one can represent their rational number as a clean, non-repeating decimal. Let's solve this by writing a program to decimalize (not to be confused with decimate) them for us! The Challenge Given a fraction, check if it can ...
stackexchange_codegolf
This challenge like some of my previous challenges will have you counting free polyforms, which are generalizations of Tetris pieces. This code-golf challenge will have you count polyomino-like polyforms on hypercubes. In particular, this challenge is to write a program that takes in three parameters: n, which represe...
stackexchange_codegolf
As the title says, given a valid chess move in algebraic notation, produce the string describing the move. Example: fxg8=Q+ -> Pawn takes g8 promotes to Queen check Bb7# -> Bishop to b7 mate Here is a list of all the keywords and their respective notation R -> Rook x -> takes N -> Knight ...
stackexchange_codegolf
Backstory If you visit the Steward Badge Page, you will see no one has received one of these badges from PPCG yet. However, there are two users: DJMcMayhem & Martin Ender, that are only a few reviews away from this badge! Challenge Your challenge is to write a program or function that when run outputs DJMcMayhem's revi...
stackexchange_codegolf
A binary eye is an odd set of digits, with all of its digits except the center one set to 1 or 0, and the center one set to the opposite of the others. Thus, there are two binary eyes for a given odd number of digits: x eyes 1 1,0 3 101,010 5 11011,00100 7 1110111,0001000 9 111101111,000010000 Make ...
stackexchange_codegolf
Loading Circle Animation Challenge Write a full program that takes no input (or has an unused input) that displays exactly the following ASCII animation for as long as possible or only 8 frames. Frame 1: # # # # ## Frame 2: ## # # ## Frame 3: ## # # # # Frame 4: ## # # # # (Note that the line at the end...
stackexchange_codegolf
Introduction This challenge is inspired by the Meta Stack Exchange question The longest consecutive days streak; it turns out that the URL https://codegolf.stackexchange.com/users/daily-site-access/[user id], where the last number is your user ID (found in the URL of your profile) contains information about which days ...
stackexchange_codegolf
It's back to school season! So for a part-time job, you're helping out at the school's library. The problem is, the head librarian has never even heard the words "Dewey Decimal," let alone implemented that system. Instead, the sorting system in use has grown "organically" as the library has expanded... In an effort to ...
stackexchange_codegolf
For this challenge, a linked list looks like this: [1, 2, 4, 0, 6, 1, 3, 1] You'll notice there's no data; each item in the list is just a reference to the index of the next one. Your task is to write a program or function which will follow a linked list like this forever, outputting each item as it is encountered. Fo...
stackexchange_codegolf
If we have a finite list of elements we can determine the probability of any one element being drawn at random as the number of times it occurs divided by the total number of elements in the list. For example if the list is [2,3,2,4] the probability of drawing 2 is \$\frac 1 2\$ since there are \$2\$ 2s and \$4\$ eleme...
stackexchange_codegolf
Introduction This challenge is similar to Project Euler problems. I came up with it because I was playing a deceivingly simple board game and couldn't come up with an efficient solution to answer a simple question about its mechanics. Quarto is a fun variant of 4 in a row. It is played on a 4 by 4 board with 16 unique ...
stackexchange_codegolf
In bash, this code posts String to post to http://www.example.com/target: curl -d "String to post" "http://www.example.com/target" NOTE: You should use http://www.example.com/target as the URL to POST to, without any change. I think all other languages that I have knowledge in need a lot more code than this. I'm not b...
stackexchange_codegolf
Print or return the following string: R******* *R****** **R***** ***R**** ****R*** *****R** ******R* *******R *....... .*...... ..*..... ...*.... ....*... .....*.. ......*. .......* *....... .*...... ..*..... ...*.... ....*... .....*.. ......*. .......* *....... .*...... ..*..... ...*.... ....*... .....*.. ......*. ......
stackexchange_codegolf
Objective Write the shortest program possible that adds semicolons to the end of all lines of code in a file unless: it already has a semicolon at the end the line is blank. Must be a complete program. Bonuses Write the program so it won't produce any compiler errors when running the program on a C Header File.
stackexchange_codegolf
I'm trying to shorten a bash solution to a Code Golf challenge, which requires an output of true or false. I've managed to condense the key piece of the code down to a substring check, to determine if the provided argument, $1, is a substring of a particular hard-coded fixed string, of the form: [[ FIXEDSTRING = *$1* ]...
stackexchange_codegolf
Introduction Let's draw some regular hexagons formed by hexagonal tiles, marking the vertices of the tiles with dots. Then we will count the number of dots. size 1: 6 dots . . . . . . size 2: 24 dots . . . . . . . . . . . . . . . . . . . . . . . . size 3: 54 dots . . . . . . ...
stackexchange_codegolf
In my answer, I have this code: s.match(/[AEIOU]/) This seems too verbose to check if a string is one of A, E, I, O, or U. I tried: "AEIOU".includes(s) But that's 1 byte longer. Can I do this in a shorter way?
stackexchange_codegolf
Jolf is a procedural golfing language made by @CᴏɴᴏʀO'Bʀɪᴇɴ. What tips do you have for golfing in Jolf? Please post one tip per answer. These tips should be at least somewhat specific to Jolf, e.g. remove comments is an answer, but not a very good one.
stackexchange_codegolf
This is much more advanced than How to randomize letters in a word and Cambridge Transposition because of the rule about which letters may be swapped with which. A simple regex will not suffice here. It is well known that a text can still be read while the innards of its words have been scrambled, as long as their fir...
stackexchange_codegolf
Create a function or program that takes two inputs: A list of integers that shall be sorted (less than 20 elements) A positive integer, N, saying how many comparisons you should take The function shall stop, and output the resulting list of integers after N comparisons. If the list is fully sorted before N comparison...
stackexchange_codegolf
Background Often, when storing a number in binary with some maximum, we simply round the maximum to the next power of two then allocate the number of bits nececairy to store the whole range. Lets call the result of this method \$S(x, m)\$ where x is the number and m is the maximum. While not bad, the naive has a few bi...
stackexchange_codegolf
Problem A fact you may have noticed about factorials is that as \$n\$ gets larger \$n!\$ will have an increasing number of \$0\$s at the end of it's base \$10\$ representation. In fact this is true for any base. In this challenge you will be given a base \$b > 1\$ and an integer \$n > 0\$ and you will determine the sm...
stackexchange_codegolf
Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For example, let $$A = \left[ \begin{matrix} -3 & 2 \\ 0 & -1 \end{matrix} \right]$$ Therefore, $$\begin{align} A^2 & = \left...
stackexchange_codegolf
Consider a binary operator \$*\$ that operates on a set \$S\$. For simplicity's sake, we'll assume that \$*\$ is closed, meaning that its inputs and outputs are always members of \$S\$. This means that \$(*, S)\$ is a magma Let's define some basic terms describing the properties of \$*\$. We can say that \$*\$ can have...
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
You are given 6 numbers: 5 digits [0-9] and a target number. Your goal is to intersperse operators between the digits to get as close as you can to the target. You have to use each digit exactly once, and can use the following operators as many times as you want: + - * / () ^ sqrt sin cos tan. For example, if I'm give...
stackexchange_codegolf
Goal In light of the World Series being around the corner, I need a program that can read the box scores and tell me what inning it is. This is complicated slightly because baseball uses an odd method to record the score. They don't write down the at-bat team's score for the inning until they've scored a run (and are s...
stackexchange_codegolf
Given the name of a cation and anion, output "S" (soluble) or "I" (insoluble). The table we will be using is from wikipedia: https://en.wikipedia.org/wiki/Solubility_chart. It is copied at the end of the question for future reference. Input: The cation, followed by the anion, separated by a space. The cation will be on...
stackexchange_codegolf
Write a program, which outputs I'm Blue, and then Da, Ba, Dee, Da, Ba, Die, forever, the words must be space-seperated in one line, and it must pause 0.4 to 0.6 seconds after printing each word. Also, the text should be outputted in the color blue 0x0000FF or in ANSI escape code blues. So the output must be something...
stackexchange_codegolf
Divide the first quadrant (including the positive x-axis, the positive y-axis, and the origin) into 1x1 grids, with each grid labelled by the coordinates of its bottom-left corner, as demonstrated below: Note that each grid contains its boundaries and its vertices. Using mathematical symbols, the grid labelled (m,n) w...
stackexchange_codegolf
Given Color codes in CMYK, convert it to RGB value. Input: string of 4 integers(ranging from 0-100) separated by space 86 86 0 43 28 14 0 6 0 41 73 4 Output: #141592 #ABCDEF #F49043 Shortest code wins! HINT: For converting CMYK to RGB you may use formula such as: Red = 255 x (1 - Cyan/100) x (1 - Black/100) ...
stackexchange_codegolf
You have to output the alphabet (upper case) with the shortest code possible. Exact output expected : ABCDEFGHIJKLMNOPQRSTUVWXYZ
stackexchange_codegolf
A Ken Thompson virus is a virus that infects your compiler and other programs. Since it infects all your tools, you can not detect it without using tools from before the virus was introduced. Your will create a prototype for inserting the Ken Thompson virus into code. The goal of this virus will be to allow you to (fak...
stackexchange_codegolf
emanresu A posted a challenge to reconstruct an ordered list of integers from its unordered set of unordered prefixes. Many users (beginning with xnor's answer) noticed that summing each unordered prefix led to a very short solution. Well, let's cruelly take that possibility away by using data that isn't integers! A fe...
stackexchange_codegolf
Background Puzzlang is a derivative of Brainfuck, where the symbol X executes a BF command based on three characters on top of it, and anything else does nothing. The following is the translation table for Puzzlang, where X is the literal X and . stands for anything else: > < + - . , [ ...
stackexchange_codegolf
Your task is to make a bidirectional compressor. It takes a list of bytes as input and returns a list of bytes as output. It has the property than whenever it is iterated twice it returns the original input. In other words, if f is your program as a function, then f(f(x))=x for all x. Now, since this is a "compressor",...
stackexchange_codegolf
This challenge is about building a chessboard in which the square size, instead of being constant across the board, follows a certain non-decreasing sequence, as described below. The board is defined iteratively. A board of size \$n \times n\$ is enlarged to size \$(n+k)\times(n+k)\$ by extending it down and to the rig...
stackexchange_codegolf
You are given 4 positive integers: volume of the first container (v1), volume of the second container (v2), volume of the liquid in the first container (l1), and volume of the liquid in the second container (l2). Your task is to move some of the liquid from container 1 to container 2, making the amount of empty space i...
stackexchange_codegolf
The Hourglass This hourglass has 60 "sands of time", and it completely fills each chamber. The clock is 19 characters wide and 13 characters in height. Each chamber has 5 rows of sand and there is a row in the centre that can hold 1 sand. The top row can hold 17 sands, the next one 15 and so on (see below). Sands fall ...
stackexchange_codegolf
In this challenge you will write a function that takes a list (ordered set) containing real numbers (the empty list is an exception, as it has nothing) and calculates $$f(x)=\begin{cases}1 & \text{if } |x|=0 \\ x_1+1 & \text{if } |x|=1 \\ \log_{|x|}\sum_{n=1}^{|x|}{|x|}^{x_n} & \text{otherwise} \end{cases}$$ where \$|x...
stackexchange_codegolf
In various Super Mario games green and red Koopa Troopa shells can slide frictionlessly on flat surfaces and destroy brick blocks that are in their way. When a shell hits a brick block the block breaks, turning it into empty space, and the Koopa shell reverses direction. As an example, watch the red shell here. Suppose...
stackexchange_codegolf
A huge storm is ravaging the world and as you and your family run away from it, you come across a gigantic shelter run by a girl. She tells you that "she sells sanctuary" and that different types of rooms are offered at different prices. A room may only house one person. The challenge Write a program which takes in two...
stackexchange_codegolf
⢣⠃⢎⠆⣇⡇⡯⡂⠈⡏⢰⢵⢐⡭⢸⠪⡀⢸⢐⡭⠀⢹⠁⢎⠆⢸⣱⢸⡃⢎⠰⡱⢸⣱⢸⡃⠈⡏⢸⡃⡱⡁⢹⠁⢸⡀⡇⡗⢅⢸⡃⠈⡏⢸⢼⢸⢐⡭⠀ ⣇⢸⡃⢹⠁⢹⠁⣟⢸⢕⢐⡭⠀⡮⡆⡯⡂⣟⠀⡯⠰⡱⢸⣸⢸⢕⠀⣏⡆⢎⠆⢹⠁⣪⠅⢸⢼⢸⠰⣩⢸⢼⠀⡮⡆⡗⢼⢸⣱⠀⢎⠆⡯⠀⢇⠇⡮⡆⡯⡂⡇⡮⡆⣟⡆⣇⢸⡃⠸⡰⡸⢸⢸⣱⠈⡏⢸⢼⠀ ⢎⠆⡗⢼⢸⡃⢸⡃⡗⠔⡇⡯⠂⢹⠁⢣⠃⠸⡸⢸⡃⡯⡂⢹⠁⡇⢎⢰⢵⢸⡀⢸⡀⡇⡗⢼⢸⡃⢐⡭⢸⡃⡯⠂⡮⡆⡯⡂⡮⡆⢹⠁⣟⢐⡭⠀⢎⢸⢼⢰⢵⢸⢕⢰⢵⠰⡁⢹⠁⣟⢸⢕⢐⡭⠀ ⡮⡆⢐⡭⢸⠕⢰⢵⠰⡁⣟⠀⡇⣪⠅⢈⣝⢸⡃⡯⡂⢎⠆⠸⡰⡸⢸⢸⣱⠈⡏⢸⢼⠀ ⣪⠅⢎⠆⢸⠈⡏⠀⣇⠰⡱⠰⡱⢸⠪⡀⣪⠅⢸⡀⡇⡗⢅⢸⡃⠸⡰⡸⠰⡱⢸⢕⢸⣱⢐⡭⠀⡮⡆⡯⡂⣟⠀⣪⠅⣟⢸⠕⢰⢵⢸⢕⢰⢵⠈⡏⢸⡃⣏⡆⢸⣳⠘⡜⠀...
stackexchange_codegolf
using Prefixed Length Code We are going to implement a compression of text (string, array/list of characters/bytes) by simple substitution of each character by a binary code, based on the frequency of that character in the text. The characters that occur more frequently will be replaced by shorter codes. The resulting ...
stackexchange_codegolf
Contest permanently opened - Updated August 10th 2017 Even though on June 5th 2017 I declared a winner (who will be kept as the best answer) I'll be rnning new bots and updating the results. June 5th Results Congratulations user1502040 Since there are no ties, I only show the % of matches won. Statistician2 - 95.7% Fit...
stackexchange_codegolf
Challenge: Some ascii-art is a pain to make, but makes code comments easier to read, especially when the code is dense. The challenge is to make a simple tool that converts comments to simple ascii-art with arrows. The comments to modify are delimited by empty comments. For example, supposing Haskell comment syntax, co...
stackexchange_codegolf
Given a non negative integer number \$n\$ output how many steps to reach zero using radicals, divisions or subtractions. The algorithm Get digits count ( \$d\$ ) of \$n\$. Try the following operations in order: $$\sqrt[d]{n}$$ $$n/d$$ $$n-d$$ Take the first integer result not equal to \$n\$. Floating point errors ...
stackexchange_codegolf
Today we're going to build a pyramid out of letters! Here's an example letter pyramid for the first 5 letters: Write the first 5 letters with a space between, first ascending and then descending. A B C D E D C B A Do the same thing for the first four letters on the line above, but with two extra leading spaces: A B...
stackexchange_codegolf
Challenge Write a program or function that takes in 4 non-negative integers, A, B, C, and D, that represent two fractions, A/B and C/D, where B and D are non-zero and A <= B and C <= D. Output an ASCII art depiction of the fractions made of |x- characters on two lines as follows: The lines will always be the same, min...
stackexchange_codegolf
The aim is to trim elements in from the ends of a list, depending on if they are in a second list of "falsey" results. For example, if the first list is [-1, 1, 2, 0, -1, 3, -1, 4, -1, -1] and the second is [-1], then we would remove all leading and trailing -1s from the first input, but not any -1s in the middle: [1, ...
stackexchange_codegolf
How many ways can one place (unlabelled) dominoes on a square chequerboard such that the number placed horizontally is equal to the number placed vertically? The dominoes must align with, and may not protrude, the chequerboard and may not overlap. This is OEIS sequence A330658, 1, 1, 1, 23, 1608, 371500, 328956227, 112...
stackexchange_codegolf
Related, but very different. In the examples below, \$A\$ and \$B\$ will be \$2\times2\$ matrices, and the matrices are one-indexed. A Kronecker product has the following properties: A⊗B = A(1,1)*B A(1,2)*B A(2,1)*B A(2,2)*B = A(1,1)*B(1,1) A(1,1)*B(1,2) A(1,2)*B(1,1) A(1,2)*B(1,2) A(...
stackexchange_codegolf
Write a quine that outputs the complement of the source code from the smallest containing power of two. Here's an example: IN : source OUT: \r\x11\x0b\x0e\x1d\x1b The largest code point in the string "source" is the letter u, which is 117. The smallest containing power of 2 would be 128, so all the code points are tak...
stackexchange_codegolf
Given an integer array and two numbers as input, remove a certain amount of the first and last elements, specified by the numbers. The input can be in any order you want. You should remove the first x elements, where x is the first numerical input, and also remove the last y elements, where y is the second numerical in...
stackexchange_codegolf
This is a Cops and Robbers challenge. This is the robber's thread. The cop's thread is here. The cops will pick any sequence from the OEIS, and write a program p that prints the first integer from that sequence. They will also find some string s. If you insert s somewhere into p, this program must print the second inte...
stackexchange_codegolf
We already now how to strip a string from its spaces. However, as proper gentlemen/ladies, we should rather undress it. Undressing a string is the same as stripping it, only more delicate. Instead of removing all leading and trailing spaces at once, we remove them one by one. We also alternate between leading and trai...
stackexchange_codegolf
Background (skip to definitions) Euler proved a beautiful theorem about the complex numbers: \$e^{ix} = \cos(x) + i \sin(x)\$. This makes de Moivre's theorem easy to prove: $$ (e^{ix})^n = e^{i(nx)} \\ (\cos(x) + i\sin(x))^n = \cos(nx) + i\sin(nx) $$ We can plot complex numbers using the two-dimensional Euclidean plane...
stackexchange_codegolf
Given an integer n as input, return a list containing n, repeated n times. For example, the program would take 5 and turn it into [5,5,5,5,5]. The elements need to be integers, not strings. No built-in functions that accomplish the task are allowed. This is code-golf, so standard rules apply.
stackexchange_codegolf
So you are given a POSITIVE base 10 (decimal) number. Your job is to reverse the binary digits and return that base 10 number. Examples: 1 => 1 (1 => 1) 2 => 1 (10 => 01) 3 => 3 (11 => 11) 4 => 1 (100 => 001) 5 => 5 (101 => 101) 6 => 3 (110 => 011) 7 => 7 (111 => 111) 8 => 1 (1000 => 0001) 9 => 9 (1001 => 1001) 10 => ...
stackexchange_codegolf
Problem You're a staircase engineer on a house and realize you only have n rectangles to create a staircase. So you are tasked with finding the number of ways to use n rectangles to tile a stairstep shape for the architects. Your task is to write a program that takes a non-negative integer n as input and calculates the...
stackexchange_codegolf
On a toroidal square grid (you can wrap around) where each cell indicates one direction (^ > v <) if we pick a cell and start to walk following these directions, we will eventually get stuck in a loop. We may end up in a different loop, depending on our starting cell. Not all the cells we encounter constitute our term...
stackexchange_codegolf
Output the numbers 1-16 (or any other set of 16 distinct items). Then, repeatedly, output a random value chosen uniformly from the last 16 items outputted. After the same item is printed 16 times in a row, halt. If a number appears multiple times in the last 16 values, it should have proportionally more chance to be ch...
stackexchange_codegolf
For today's task, we have two programs, P and Q, both in the same language. Each of them receives a single-character input. If P receives character K, P says how many times K appeared in Q. (You can use any output format for P or Q; they need not be the same, the only requirement is that your format can represent any n...
stackexchange_codegolf
Today's Google doodle is about Celebrating 50 years of Kids Coding: The goal is program the path of a little bunny so that it can eat all the carrots. There are 4 types of blocks (see pictures below): From left to right: O("...", k) = orange piece: these are for loops which executes k times the program "...". G = g...
stackexchange_codegolf
You have played \$N\$ matches in some game where each match can only result in one of the two outcomes: win or loss. Currently, you have \$W\$ wins. You want to have a win percentage of \$P\$ or more, playing as few matches as possible. Output the minimum win streak that you need. Assume the current win streak is at \$...
stackexchange_codegolf