instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Introduction Suppose that you are handed a random permutation of n objects. The permutation is sealed in a box, so you have no idea which of the n! possible ones it is. If you managed to apply the permutation to n distinct objects, you could immediately deduce its identity. However, you are only allowed to apply the pe...
stackexchange_codegolf
Everyone knows, that you can leave out the multiplication symbol (\$\times\$, or *) in a*b 23*a (2+3)*a a^(b*c) (a+b)*(c+d) but not in 2*3 => you don't want it to be 23 a*23 => most mathematicians just don't do it a^2*b => now it's (a^2)*b, if you remove the *, it's a^(2b) a/2*b => now it's (a/2)*b, if you remove th...
stackexchange_codegolf
From Wikipedia: Chopsticks is a hand game for two players, in which players extend a number of fingers from each hand and transfer those scores by taking turns to tap one hand against another. In this challenge "splits" can only be 4->2+2 or 2->1+1. Challenge Your challenge is to make a bot (think the AI and framewor...
stackexchange_codegolf
Given a map from arrays of integers of same size to single integers, determine if there is a set of indices such that the output is equal to the maximum of the elements at those indices for every corresponding pair. You can take the input as a map if your language support, arrays of pairs, separated 2D array of input a...
stackexchange_codegolf
Credit: Marco Verch CC BY 2.0 A two-cube calendar, as shown in the picture, uses two cubes with digits painted on the faces to display the date. For dates in the range 1-9, a leading zero is used ("01", "02", ..., "09"). Now, if you do the math, you might come to the conclusion that these calendars should be impossibl...
stackexchange_codegolf
I need this down to as few characters as possible. I would use Test-NetConnection but I need PSv2 compatability. Any help would be appreciated. $socket = new-object Net.Sockets.TcpClient $socket.Connect("192.168.5.5",445) $socket.Connected As a note I have tried this but it doesn't work (new-object Net.Sockets.TcpCl...
stackexchange_codegolf
Alpha Decay is a kind of radiation decay where every time the atom "decays", it loses a helium nucleus (an alpha particle). This means that an atom loses 2 protons and 2 neutrons each time. Your task is to simulate this, including the problems that occur during alpha decay. Given two integers as input, \$m\$ and \$p\$,...
stackexchange_codegolf
Sandbox What is Hexagonification™? Hexagonification™ is a transformation that creates a hexagon with 3 copies of a rectangle block, each skewed to the right by 30 degrees and then rotated by 0, 120 and 240 degrees respectively, as shown in the following image. A triangle hole may appear in the middle, but that isn't a ...
stackexchange_codegolf
Concept Remembering numbers can be difficult. Remembering a word may be easier. In order to memorize big numbers, I created a way to pronounce them in a leetspeak-like way. Rules Each digit is first replaced by its corresponding letter: 0 => O 1 => I 2 => R 3 => E 4 => A 5 => S 6 => G 7 => T 8 => B 9 => P After the re...
stackexchange_codegolf
Simpler version of this Task You must create a program that outputs a triangle of a given size N. A triangle is made of 3 identical triangles A triangle of size N should be made of N lines A triangle's line starts from 1 star, and increases by 2 stars each line Test Cases: 1 -> * * * 3 -> * *** ***** ...
stackexchange_codegolf
Input A positive integer N representing the size of the problem and four positive integers v, x, y, z. Output This is what your code should compute. Consider a set of N distinct integers and consider all ways of choosing 3 subsets (which can overlap) from the set. There are \$2^{3N}\$ different possible ways of choos...
stackexchange_codegolf
Here is the problem, for which I can only think of an iterative solution and have not found a closed formula: You need to paint a house with R rooms. For each room there are four walls and one ceiling, which all have the same dimensions and need C coats of paint. You can't paint the next coat until the previous one ha...
stackexchange_codegolf
You are given an array A of length N and an array B of length N-1. You need to output array where items alternates: A[0], B[0], A[1], B[1], ..., B[N-2], A[N-1] Restrictions: N>0 Type of items is not specified, but code should work at least for unsigned integers. Sample input: A = [1,2,3,4] B = [7,8,9] Sample output:...
stackexchange_codegolf
Given two positive integers a and b, output two positive integers c and d such that: c divides a d divides b c and d are co-prime the least common multiple of c and d equals the least common multiple of a and b. If there are more than one possible answers, you can output only one or all of them. Test cases: a b c ...
stackexchange_codegolf
There already have been multiple challenges about carryless multiplication, this challenge will work with the same calculation rules. You task is given a quadratic polynomial ax²+bx+c, to find an integer r such that a*r*r+b*r+c is zero, with + meaning exclusive or and * being carryless multiplication (use xor to add up...
stackexchange_codegolf
The Matoran Alphabet is the alphabet used by many of the characters in the Bionicle universe. Your challenge is to create a program or function that takes a string as input and creates an image of the input written in the Matoran alphabet. The input will only consist of uppercase letters (A-Z), numbers (0-9), and spac...
stackexchange_codegolf
I was asked by OEIS contributor Andrew Howroyd to post a Code Golf Challenge to extend OEIS sequence A049021. Would be super great to get a couple more terms for [...] A049021. Kind of thing [...] team golf would excel at. As I found out the hard way with the help of user202729, the definition of A049021 is... slippe...
stackexchange_codegolf
Your task is to write the shortest possible Pong game without human interaction, so AI plays vs AI. I assume all of you know Pong, just to make sure, this is the target (just as running code):http://www.youtube.com/watch?v=xeEFMhdnR6c The following game rules apply: No ASCII "graphics". You must actually have code to ...
stackexchange_codegolf
Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it. [1,3,2,1,2,1,5,3,3,4,2], visualised as: 5 5 4 3 5334 32 2 53342 13212153342 needs nine brush strokes: 1 2 3 4 5555 66 7 88888 9999...
stackexchange_codegolf
Imagine you have two boxes B(x) and B(y), each containing an unknown bit - 0 or 1, and a machine F that can X-ray them and produce a third box for B(x^y) (xor). F can also compute B(x*y) (and). In fact, those are just special cases of the the single operation the machine can perform - inner product each, denoted with F...
stackexchange_codegolf
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 -> ...
stackexchange_codegolf
When I was posting answers for the Husk Language of The Month thread, I realized it took more time to enter them in the thread than it took to actually write the answers. So, why not automate it? Write a program/function which inputs a language name, and displays all answers in that language during the current month so...
stackexchange_codegolf
Don't you hate it when you're trying to roughly sort a list based on user data, but you have to poll the user for thousands of comparisons? Hate no more, because the answers to this challenge are (going to be) here! Method The sorted-ness of a list is defined by how many possible comparisons it has which are correct. L...
stackexchange_codegolf
Mr Seckington is a mobile grocer. He drives his van door-to-door selling his produce all around the nearby villages. Mr Seckington needs a method to weigh the produce he is selling so he knows how much to charge his customers. Because space is at such a premium on his van, he uses an interesting sequence of weights ...
stackexchange_codegolf
Your task is to regulate traffic on a crossroads. There are 4 roads coming from north, east, south and west. The input is a string representing the upcoming traffic on each road. For example, NNNWS indicates there is a total of 5 cars: three at the north, one at the west and one at the south. The order of characters ha...
stackexchange_codegolf
Let's see how good your language of choice is at selective randomness. Given 4 characters, A, B, C, and D, or a string of 4 characters ABCD as input, output one of the characters with the following probabilities: A should have a 1/8 (12.5%) chance to be chosen B should have a 3/8 (37.5%) chance to be chosen C should h...
stackexchange_codegolf
Your task is to take a 24 BPP sRGB image and output the same image upscaled 3x into red, green, and blue subpixels. The resulting image will be made entirely of pure black, red, green, and blue pixels. Each pixel from the source image, when zoomed, produces an arrangement of 9 sub-pixels that can be either on or off (i...
stackexchange_codegolf
Write a program that outputs its input unchanged. However: If all uppercase characters are removed from the program, it lowercases all uppercase letters. If all lowercase characters are removed from the program, it uppercases all lowercase letters. Transforming characters beyond the basic Latin [A-Za-z] range is opti...
stackexchange_codegolf
When one performs a search query using Google, one of the first things you see is an approximation of how many results were found. Today, you'll be simulating this in as few bytes as possible. Input A short string of length at most 10 with characters from a-z. Output The approx count that Google reports for the number ...
stackexchange_codegolf
Oh, No! the sentences are out of balance. Quick! balance them. A word is defined as follows: A sequence of letters [A-Za-z] separated by any non-letter character ([0-9] ~+- etc.) A word is BaLanCeD if its capitalization is the same forwards as it is backwards. Given a sentence with words, balance each word by capita...
stackexchange_codegolf
Input A bound m <= 4294967295. Output Consider values sampled uniformly at random from integers in the range 0 to m, inclusive. Your output should be the expected (average) number of trailing zeros in the binary representation of the sampled value. Your answer should be exact, for example given as a fraction. Example ...
stackexchange_codegolf
Output the Nth term of the Van Eck Sequence. Van Eck Sequence is defined as: Starts with 0. If the last term is the first occurrence of that term the next term is 0. If the last term has occurred previously the next term is how many steps back was the most recent occurrence. https://oeis.org/A181391 https://www.you...
stackexchange_codegolf
A friend of yours has given you directions to the best restaurant in town. It's a series of left and right turns. Unfortunately, they forgot to mention for how long you need to go straight ahead between those turns. Luckily you have a street map with all the restaurants on it. Maybe you can figure out which restaurant ...
stackexchange_codegolf
Some chess variants use interesting non-standard pieces. In order to concisely describe new pieces or to describe pieces without requiring everyone to memorize a bunch of non-standard names some new notation can be invented. In this challenge we are going to look at Parlett's movement notation and convert it to nice at...
stackexchange_codegolf
Given an positive integer as input determine if it is a magnanimous number. A magnanimous number is a number such that any insertion of a + sign between any two digits in base 10 results in an expression of a prime integer. For example 40427 is magnanimous because 4+0427 = 431 is prime 40+427 = 467 is prime 404+27 ...
stackexchange_codegolf
Implement a function \$f\$ (as a function or complete program), such that \$ \displaystyle\lim_{n\rightarrow \infty} f(n) \$ converges to a number which is not a computable number. Answers will be scored in bytes with fewer bytes being better. IO formats Your answer may be in any of the following formats A program or ...
stackexchange_codegolf
Input a datetime, format the datetime in YYYY-MM-DD HH:mm:ss format using 30-hour clock time. The 30-hour clock time works as: After 6 a.m., it is same as 24-hour clock time Before 6 a.m., it use date for previous day, and plus Hours by 24. For more examples, you may checkout the testcases. Rules To simplify the que...
stackexchange_codegolf
Objective Design a modulator/demodulator pair to accurately transmit data as quickly as possible over simulated plain old telephone service (POTS). Steps Generate some random (/dev/random or the like) data that will take 3-4 seconds to transmit Modulate the data with your modulator to produce an audio file Pass the au...
stackexchange_codegolf
Challenge Print the numbers: 1 22 333 4444 55555 666666 7777777 88888888 999999999 In that order. I/O Takes no input. The numbers can have any delimiters desired (or none). That includes lists, cell arrays, .jpeg, etc.... Example outputs: 122333444455555666666777777788888888999999999 [1,22,333,4444,55555,666666,77777...
stackexchange_codegolf
In the C programming language, arrays are defined like this: int foo[] = {4, 8, 15, 16, 23, 42}; //Foo implicitly has a size of 6 The size of the array is inferred from the initializing elements, which in this case is 6. You can also write a C array this way, explicitly sizing it then defining each element in ord...
stackexchange_codegolf
Introduction Today's challenge is all about teeth. Specifically, how long it takes to brush from one tooth to another. Your challenge is, given the locations of two teeth, output the shortest amount of time possible to brush from the first to the second. Challenge For this challenge we will be using a layout of an aver...
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
Given a positive integer \$N >= 4\$, output an RSA key pair (both the private and the public key) whose key length is \$N\$ bits. The RSA key generation algorithm is as follows: Choose an \$N\$-bit semiprime \$n\$. Let the prime factors of \$n\$ be \$p\$ and \$q\$. Compute \$\lambda(n) = LCM(p-1, q-1)\$. Choose an int...
stackexchange_codegolf
J. E. Maxfield proved following theorem (see DOI: 10.2307/2688966): If \$A\$ is any positive integer having \$m\$ digits, there exists a positive integer \$N\$ such that the first \$m\$ digits of \$N!\$ constitute the integer \$A\$. Challenge Your challenge is given some \$A \geqslant 1\$ find a corresponding \$N \ge...
stackexchange_codegolf
Program Write a program to display repeating terms of a given sentence. Explanation The program must output the repeating terms of two or more letters from the given input (input is a sentence separated by spaces without any punctuation except the full-stop indicating the end.) Repeated terms may not span across or in...
stackexchange_codegolf
We are probably all used to the English alphabetical order: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z When we compare words in English for the sake of alphabetization we first compare the first letter, whichever word has the later first letter comes later. If they are the same we check the second letter and...
stackexchange_codegolf
In this challenge you are asked to find in how many ways we can express a positive integer n as the sum of two positive integers k and the reverse of k. Here is an example using n = 1069 : 188 + 881 = 1069 287 + 782 = 1069 386 + 683 = 1069 485 + 584 = 1069 980 + 89 = 1069 So, the answer here would be 5. rules As you ca...
stackexchange_codegolf
Pancake sorting is the colloquial term for the mathematical problem of sorting a disordered stack of pancakes in order of size when a spatula can be inserted at any point in the stack and used to flip all pancakes above it. A pancake number P(n) is the minimum number of flips required for n pancakes. 1 In 1979, a you...
stackexchange_codegolf
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...
stackexchange_codegolf
Based on the interpretation user @ThePirateBay made from the first version of my own challenge Output diagonal positions of me squared now I challenge you to make ASCII art that draws diagonal lines based on a square character matrix based on a given number n. Input A number n. Output A square matrix of size n^2 which...
stackexchange_codegolf
Background Set is a card game. The deck consists of 81 unique cards that vary in four features: number of shapes (one, two, or three), shape (diamond, squiggle, oval), shading (solid, striped, or open), and color (red, green, or purple). For convenience, let's write a card as a 4-tuple of numbers from 1 to 3, e.g. 111...
stackexchange_codegolf
Write the shortest function to convert an integer into a numeric representation given a radix between 2 and 62. e.g.: to_string(351837066319, 31) => "codegolf"
stackexchange_codegolf
This is the robbers' post. The cops' is here. Your challenge is to take a cop's post and find an input that the regex matches but the program returns a falsey value. Once you have cracked a cop's post, comment in a link to your crack. (If you don't have enough rep to comment, please say so, and someone will do it for y...
stackexchange_codegolf
It can be in any language, plus the map must be in the output only not in the source code. This is my first question here, so please feel free to edit it. Also, there might be some rules about scoreboard which I'm not familiar how to put it here. Cheers!
stackexchange_codegolf
Fix my Basic Orthography While I am excellent at following the English capitalisation rules when writing, when I am typing I have a habit a capitalising almost everything (as you will see from the titles of my challenges). I need a program to fix that, but because I use so many capitals, and capitals are big letters, y...
stackexchange_codegolf
⢣⠃⢎⠆⣇⡇⡯⡂⠈⡏⢰⢵⢐⡭⢸⠪⡀⢸⢐⡭⠀⢹⠁⢎⠆⢸⣱⢸⡃⢎⠰⡱⢸⣱⢸⡃⠈⡏⢸⡃⡱⡁⢹⠁⢸⡀⡇⡗⢅⢸⡃⠈⡏⢸⢼⢸⢐⡭⠀ ⣇⢸⡃⢹⠁⢹⠁⣟⢸⢕⢐⡭⠀⡮⡆⡯⡂⣟⠀⡯⠰⡱⢸⣸⢸⢕⠀⣏⡆⢎⠆⢹⠁⣪⠅⢸⢼⢸⠰⣩⢸⢼⠀⡮⡆⡗⢼⢸⣱⠀⢎⠆⡯⠀⢇⠇⡮⡆⡯⡂⡇⡮⡆⣟⡆⣇⢸⡃⠸⡰⡸⢸⢸⣱⠈⡏⢸⢼⠀ ⢎⠆⡗⢼⢸⡃⢸⡃⡗⠔⡇⡯⠂⢹⠁⢣⠃⠸⡸⢸⡃⡯⡂⢹⠁⡇⢎⢰⢵⢸⡀⢸⡀⡇⡗⢼⢸⡃⢐⡭⢸⡃⡯⠂⡮⡆⡯⡂⡮⡆⢹⠁⣟⢐⡭⠀⢎⢸⢼⢰⢵⢸⢕⢰⢵⠰⡁⢹⠁⣟⢸⢕⢐⡭⠀ ⡮⡆⢐⡭⢸⠕⢰⢵⠰⡁⣟⠀⡇⣪⠅⢈⣝⢸⡃⡯⡂⢎⠆⠸⡰⡸⢸⢸⣱⠈⡏⢸⢼⠀ ⣪⠅⢎⠆⢸⠈⡏⠀⣇⠰⡱⠰⡱⢸⠪⡀⣪⠅⢸⡀⡇⡗⢅⢸⡃⠸⡰⡸⠰⡱⢸⢕⢸⣱⢐⡭⠀⡮⡆⡯⡂⣟⠀⣪⠅⣟⢸⠕⢰⢵⢸⢕⢰⢵⠈⡏⢸⡃⣏⡆⢸⣳⠘⡜⠀...
stackexchange_codegolf
Some of your employees have broken capslock keys and you're too cheap to replace them. Help them out by creating the shortest program possible to correct their work! Simply convert each character in a given string from uppercase to lowercase and vice-versa... but there's a twist! You're also very excited for Christmas!...
stackexchange_codegolf
Each natural number (including 0) can be written as a sum of distinct powers of integers (with a minimum exponent of 2). Your task is to output the smallest power required to represent \$n\$. For example: 2 = 1^2 + 1^3 // Output 3 9 = 1^2 + 2^3 = 3^2 // Output 2 15 = 2^2 + 2^3 + 1^4 + 1^5 + 1^6 // Output 6 20 = 2^2 + ...
stackexchange_codegolf
I tested the waters on this sort of question with python, but now I get to the real question I want to ask. restricted-source challenges are uniquely rewarding in Haskell because of Haskell's strict rule set. Type coercion which is the bread and butter for other languages in these sort of challenges is arguably non-ex...
stackexchange_codegolf
You work at a bakery, and every day you make pastries. You make 100 of each of several different types. However customers are less predictable. Some days they order all of one kind of pastry and you run out, some days they order hardly any and you have some left over. So your boss has made up a chart which tells you ho...
stackexchange_codegolf
The Challenge Given an integer input, return the first Fibonacci number that contains the input within itself along with the index of that Fibonacci number (indexes starting at 0 or 1 - up to you, but please mention which in your answer). For example, if given the input of 12, the program would return 26: 121393 as 12 ...
stackexchange_codegolf
Goal Sometimes dinner menus can have long winded names. It's much easier for the waiter to write an abbreviation that unambiguously identifies the dish. For example, given this list: beef burger chicken burger chicken nuggets The abbreviation c n matches chicken nuggets. The abbreviation bur matches beef burger and c...
stackexchange_codegolf
Introduction Fischer random chess, also known as Chess960 for the 960 valid starting boards, is a variant of chess where each player's pieces are randomly shuffled at the start. As a reminder, each player gets 8 pawns, two rooks, two knights, two bishops, one queen, and one king. For this challenge, you don't need to k...
stackexchange_codegolf
Story: The π was recently computed with accuracy to 100 trillions digits, but it is useless to us. We can't do accurate enough math, because rational numbers are too boring and so we don't know that much digits of them! Challenge: Your task will be to write program or function which takes string of digits including dec...
stackexchange_codegolf
Sandbox There are special sets S of primes such that \$\sum\limits_{p\in S}\frac1{p-1}=1\$. In this challenge, your goal is to find the largest possible set of primes that satisfies this condition. Input: None Output: A set of primes which satisfies the conditions above. This challenge is a code-challenge, where your s...
stackexchange_codegolf
Jelly is a tacit, golf-oriented programming language by our very own Dennis. It’s popping up in answers here more and more often, beating other golf-y languages like Pyth and CJam, both by using its own code page and its powerful chain system to succinctly express programs. Let’s collect some useful tips for golfing in...
stackexchange_codegolf
Introduction: Ever used Dropbox with some other people and you both modified the same file? Ever had a multi-user application with a relational database, and two people were modifying (or worse, one was deleting and the other modifying) the same object? Well, let's simulate that with this challenge (sort-of). For the s...
stackexchange_codegolf
The variable star designation is an identifier for a variable star (a star that fluctuates in brightness). It consists of either a 1-2 letter code or (when the letter code is no longer sufficient) a 'V' followed by a number. This code is followed by the genitive of the star constellation the star is found in (eg. "RR C...
stackexchange_codegolf
Introduction This challenge appeared in the 2020 Estonian Open Informatics Olympiad and was created Sandra Schumann. I thought it was interesting because it involves symmetry and is quite hard even to brute force by hand. The problem author said that it's ok for me to post it here: Challenge You may use a modified vers...
stackexchange_codegolf
The question score on Stack Exchange is the total number of upvotes minus the total number of downvotes a question receives. However, the reputation gained/lost for every upvote/downvote is different (eg. 10/-2 on Code Golf). Given the total reputation earned, the reputation gained by an upvote and the reputation lost ...
stackexchange_codegolf
In this challenge we considered a frog hopping around a lily pond. To recap the lily pond was represented as a finite list of positive integers. The frog can only jump forward or backwards by a distance equal to the number at its current location. So for example: [2, 3, 1, 4, 1] Here the frog is on a 1 so i...
stackexchange_codegolf
Given a number n, calculates BB(n) (the maximum number of 1s finally on the tape, among all halting 2-symbol n-state Turing machines with tape of zeros). To solve the problem, you are given an extra (black-box) function H as input, which takes a function in your language (f) and returns a truthy/falsy value indicates w...
stackexchange_codegolf
One of the cool features introduced in the C++11 standard is the ability to declare a template parameter as being variadic; i.e. that parameter represents a sequence of an arbitrary number of arguments (including zero!). For example, suppose the parameter pack args expands contains the sequence A0, A1, A2. To expand th...
stackexchange_codegolf
This comes from http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/ "Given that Pi can be estimated using the function \$4 \times (1 - 1/3 + 1/5 - 1/7 + \cdots)\$ with more terms giving greater accuracy, write a function that calculates Pi to an accuracy of 5 decimal places." Note, the e...
stackexchange_codegolf
Part of Advent of Code Golf 2021 event. See the linked meta post for details. Related to AoC2020 Day 11, Part 2. You enter the waiting area for a ferry, and you see a bunch of people sitting at a bunch of seats. The seats form a grid like this (. is a floor, L is an empty seat and # is an occupied seat): LL.#L #.L.L L...
stackexchange_codegolf
Tom the lumberjack is going to do his daily routine: chop trees. After all, it's his job to do so. His boss has ordered him to chop trees in a straight line marked with a special tape to identify them, so he knows which trees he is going to have to chop. However, Tom quickly realizes he has a problem. His axe will only...
stackexchange_codegolf
Your task is to write a program which implements a bijection \$\mathbb{N}^n\to\mathbb{N}\$ for \$n \ge 1\$. Your program should take \$n\$ natural numbers as input, in any acceptable method (including taking them as a single, \$n\$ element list/array) and output a unique natural number for all possible inputs. In layma...
stackexchange_codegolf
Sometimes it really is a struggle to convert Cartesian coordinates (x,y) to Polar coordinates (r,phi). While you can calculate r = sqrt(x^2+y^2) quite easily, you often need some distinction of cases when calculating the angle phi because arcsin,arccos and arctan and all other trigonometric functions have a co-domain t...
stackexchange_codegolf
Given a constructible point \$(x, y) \in \mathbb R^2\$, output the steps required to construct \$(x, y)\$ Constructing a point Consider the following "construction" of a point \$(\alpha, \beta)\$ in the Cartesian plane: Begin with the points \$(0, 0)\$ and \$(1, 0)\$. Then, more points can be added by performing a fini...
stackexchange_codegolf
Write a program that outputs its input unchanged. However: If all uppercase characters are removed from the program, it lowercases all uppercase letters. If all lowercase characters are removed from the program, it uppercases all lowercase letters. Transforming characters beyond the basic Latin [A-Za-z] range is opti...
stackexchange_codegolf
Write a program that takes an undirected graph and finds the minimum cut, i.e., the set of edges that, if removed, would disconnect the graph into two or more connected components. The program should have a time complexity of \$O(n^2m)\$, where n is the number of vertices and m is the number of edges in the graph. One ...
stackexchange_codegolf
Write a program that prints the shapes of one-sided polyominoes. Given input 4 (tetrominos), a sample output would be: * * * * * * ** ** ** * ** ** ** * * *** **** You are not restricted with respect to orientation, ordering or layout as long as polyominoes are not connected and no...
stackexchange_codegolf
In some parts of the world, phone numbers are fixed-length, apparently. That sounds boring, though. For this challenge, your task is to take the digits of a what is presumed to be a valid phone number, and format it based on some simplified rules around what a phone number looks like. Input format Your input will consi...
stackexchange_codegolf
In chess, the Fool's Mate is the fastest possible way to reach checkmate. It is reached with Black's second move. In chess notation, one possible sequence of moves that achieves Fool's Mate is 1.f3 e6 2.g4 Qh4#. This is not the only possible way to achieve this checkmate (in the same number of moves). There are three ...
stackexchange_codegolf
This is a mirror: |. I just found out that you can stick a mirror in the middle of a string if the string can be mirrored on itself! For example, the string abccba. If you cut it in half the two halves are mirror images of each other: abc <--> cba So, we can stick a mirror in the middle of the string, and our new st...
stackexchange_codegolf
This is a different type of compression challenge. In a normal kolmogorov-complexity challenge, you are required to recreate a list exactly. Here, you are allowed to round the values in any way you wish. What's the catch? Your score is penalized based on how wrong your output is. At the bottom of this question is a...
stackexchange_codegolf
Note: this challenge has been posted on the sandbox. Introduction This challenge is inspired by 2009 Putnam B1, a problem in an undergraduate mathematics competition. The problem is as follows: Show that every positive rational number can be written as a quotient of products of factorials of (not necessarily distinct...
stackexchange_codegolf
Introduction A hypercube/tesseract is the 4 dimensional equivalent of a normal cube. It's made by taking a cube net, extending it to the 3rd dimension, then – using the 4th dimension – folding it into a hypercube. It's basically a cube, where each side is a cube. To create a hypercube, you need 16 4d vectors (a vector ...
stackexchange_codegolf
Given two integers, compute the two numbers that come from the blending the bits of the binary numbers of equal length(same number of digits, a number with less digits has zeros added), one after the other, like such: 2 1 10 01 1 0 1001 0 1 0110 some examples: Input Binary Conversion Output ...
stackexchange_codegolf
TL;DR Record (left-right)/length for each pair of consecutive elements. If they're 0 or negative, don't record it. Once this is done, take these actions. Don't update quotients: Increment right and decrement left for (0, .3) Remove from the array at >=.3 Print both elements for >.5 Print the remaining array. Have s...
stackexchange_codegolf
A guess the word game The agreed dictionary. All words are 6 letters long with all letters distinct Rules: This is a game of two players and the task will be to implement Player 2. Player 1 chooses a word from the agreed dictionary Player 2 repeatedly guesses a word from the agreed dictionary. At each turn, Player 1 ...
stackexchange_codegolf
Your goal is simple: to fail everything. More precisely, you should write the shortest code that triggers a compilation/interpretation error, or a runtime error. What does not count Failing with symbols that are not covered by the language syntax and are meant to appear only in string literals, comments and other ways...
stackexchange_codegolf
Imagine you have a grid where some squares are walls, some are empty, and some are lights that shine for arbitrary distances in the four cardinal directions until they meet walls: ####.#### ##..L.... ####.##.# ####.##L. ##......L In the above grid, the lights cover all the tiles. But in some cases, they may not be: ##...
stackexchange_codegolf
(no, not those ones) The Challenge You'll be given two inputs. The first is a positive integer n > 0, which is used to output an n x n right triangle of the numbers 1, 2, 3, ... n. This triangle starts in a corner and increases horizontally and vertically by one and diagonally by two. See examples below for clarificati...
stackexchange_codegolf
Objective Given an unlabelled binary tree, decide whether it is contiguous in indices. Indices This challenge gives one-indexing on binary trees. The exact definition expresses all indices in binary numeral: The root is indexed 1. For every node, to get the index of its left child, replace the most significant 1 by 1...
stackexchange_codegolf
Given \$a\$ and \$b\$, both odd \$n+1\$-bit integers, compute \$a/b\$ to a precision of \$n+1\$ bits in the 2-adic integers. That is, compute \$c\$ such that \$a = bc\, (\mathop{\rm mod} 2^{n+1})\$. \$n\$ should be your language's native integer size, or if native integers are bigints, take it as a parameter. If your l...
stackexchange_codegolf
Steven Gerrard was born on 30th of May 1980. He is now 37 years old. Happy birthday, Steven! To celebrate his anniversary, your goal is to remind him the number of goals he has scored each year in premiere league for Liverpool. He doesn't want to remember the goals scored before or after playing for Liverpool. It is l...
stackexchange_codegolf
Challenge Given an array of integers, received from stdin, function arguments, program arguments, or some other method: Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods. Example session > minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} ) -14 18...
stackexchange_codegolf
This is a challenge inspired by Chebyshev Rotation. I suggest looking at answers there to get inspiration for this challenge. Given a point on the plane there is a unique square (a rectangle with equal sides) that is centered on the origin and intersects that point (interactive demo): Given a point p and a distance d,...
stackexchange_codegolf
New Posts and New Sandbox Posts are chatbots that occupy CGSE's main chatroom, The Nineteenth Byte. They've been doing their jobs for almost one full year now, so I thought I'd make a challenge to honor their contributions! The challenge is simple: Draw the profile picture of either New Posts (NP) or New Sandbox Posts ...
stackexchange_codegolf