instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Lenguage is a brainfuck dialect that is notorious for breaking source restriction challenges. That is because Lenguage cares only about the length of it's source and not the contents. First, the length of the program is calculated. Then, said length is converted to binary and left-padded by zeroes to a multiple of 3. ...
stackexchange_codegolf
In a programming language of your choice, write 95 programs, each of which outputs a different one of the 95 printable ASCII characters without that character occurring anywhere in the program. For example, if your language was Python, your program that outputs the character P might be print(chr(80)) because P has ASC...
stackexchange_codegolf
An analog clock has 2 hands*: Hour and minute. These hands circle the clock's face as time goes by. Each full rotation of the minute hand results in 1/12th of a rotation of the hour hand. 2 full rotations of the hour hand signifies a full day. As these hands are fixed to the same central point, and rotate around that p...
stackexchange_codegolf
Yes, the good old GIF. Loved for its versatility, hated for its patents and partly obsoleted due to its limitations (and patents), GIF consists, at the core, of a color palette and a palette-indexed image compressed using the LZW algorithm. Your task is to write a program that reads an image in ASCII PPM format ("P3" m...
stackexchange_codegolf
Introduction Your job is to write a function or program that detects if a number a is less than a number b. But... You are not allowed to use built-in alternatives for equals, less than, greater than, less than or equal to, greater than or equal to, or not equal to operators. (Writing your own implementation is allowed...
stackexchange_codegolf
Consider the infinite string of all nonnegative decimal integers concatenated together in order (akin to Champernowne's constant): 0123456789101112131415161718192021222324252627282930...979899100101102103... Write a program or function that takes in a nonnegative integer that indexes (0-based) into this infinite strin...
stackexchange_codegolf
Your task, at the moment that you choose to accept it, is to write a program that, when given a string and a PCRE-regex, calculates the minimum Levenshtein distance to another string that matches the regex (fully). All strings, as well as the regexes, should be in the Latin-1 character set. This is code-golf, so the sh...
stackexchange_codegolf
The purpose of this challenge is to solve the original first Project Euler problem, but as the title suggests in constant time (with respect to the size of the interval). Find the sum of all the multiples from a list of numbers in some defined range, in such a way that the running time of your program runs in constant...
stackexchange_codegolf
The task Today's special offer: consonants and punctuation for FREE! Your program or function will be given as input the first 6 paragraphs of Lewis Carroll's famous novel Alice's Adventures in Wonderland, with all vowels [aeiouAEIOU] removed and all other characters left intact. It must output the original text, byte-...
stackexchange_codegolf
Introduction I have some ASCII cars that have velocity and direction. Their velocity is represented by their number. If a car is <> then it has stopped. For example: <> 1> 2> 3> After one second, I get <> 1> 2> 3> After two, I get <> 1> 2> 3> If two cars are too close, they crash. 1> <1 1> <2 Afte...
stackexchange_codegolf
Given two strings \$ A \$ and \$ B \$ and a positive integer \$ n \$, determine whether \$ B \$ is composed entirely of (possibly overlapping) strict substrings of \$ A \$ of a length of at least \$ n \$. Test cases n A B Output ----------------------------------------- 2 abcdefg ...
stackexchange_codegolf
A simple pedometer can be modeled by a pendulum with two switches on opposite sides—one at x=0 and one at x=l. When the pendulum contacts the far switch, the ambulator can be assumed to have taken half a step. When it contacts the near switch, the step is completed. Given a list of integers representing positions of th...
stackexchange_codegolf
Some sleep commands implement a delay of an integer number of seconds. However, 2³² seconds is only about 100 years. Bug! What if you need a larger delay? Make a program or a function which waits for 1000 years, with an error of less than ±10%. Because it's too time-consuming to test, please explain how/why your soluti...
stackexchange_codegolf
Write a program or function that takes in two integers that represent the X and Y coordinates of a point on a Cartesian plane. The input may come in any reasonable format as long as the X value comes before the Y. For example, 1 -2, (1,-2), [1, -2], or 1\n-2 would all be fine for X = 1, Y = -2. Print or return a single...
stackexchange_codegolf
This challenge is as follows. (Uhoh no! Now everyone is going to use reciprocal division. Now all the answers are going to look the same and lose originality, ugh!) Given two integers multiply them, ... but you can't use the multiplication symbols "*" and "x". As you probably know multiplication is just an extension...
stackexchange_codegolf
Introduction Hex is a strategy board game played on a hexagonal grid, theoretically of any size and several possible shapes, but traditionally as an 11×11 rhombus. Other popular dimensions are 13×13 and 19×19 as a result of the game's relationship to the older game of Go. According to the book A Beautiful Mind, John Na...
stackexchange_codegolf
There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and not considering every element, and skipping an element depending on whether the previous element was selected or not. I u...
stackexchange_codegolf
Given a list of stack heights, calculate the number of ways those heights could have been arrived at by stacking blocks one at a time. Shortest code wins. Test cases: [2, 2] 6 [3,3,3] 1680 [1,5,9,1] 480480 [] 1 [10] 1 [2,2,2,10] 720720 Reference Python implementation: def stacking_count(stacks): if sum(stacks) ==...
stackexchange_codegolf
Brain-flak turns one year old tomorrow! In honor of it's birthday, we're having a PPCG style birthday party, where several users post brain-flak related questions! Help us celebrate! :) Brain-flak is an esoteric language I wrote where all of the commands are brackets and all of the brackets must be fully matched. To...
stackexchange_codegolf
One thing that is constantly frustrating when golfing ARM Thumb-2 code is generating constants. Since Thumb only has 16-bit and 32-bit instructions, it is impossible to encode every immediate 32-bit value into a single instruction. Additionally, since it is a variable length instruction set, some methods of generating ...
stackexchange_codegolf
What does "jelly" mean in the title?. Cop's thread Robbers, you are to choose an uncracked Cop answer, and attempt to find a Jelly program which is: shorter than the Cop's answer solves the linked challenge, according to the rules of the challenge So long as these two bullet points are met, your answer cracks the Cop...
stackexchange_codegolf
Definition: A number m is called a primitive root of a prime p the condition that the smallest integer k for which p dividies mk-1 is p-1 Your task Given a tuple (a,b) of positive integers, return the fraction: (number of primes p equal to or less than a which has b as a primitive root) divided by (number of primes ...
stackexchange_codegolf
In some languages, strings are started and ended with a quote mark ('). And quote itself is escaped by writing it twice sequentially. For example, empty string is written as '', and I'm is written as 'I''m'. This question is about find out all non-overlapping strings from left to right in such format from the given inp...
stackexchange_codegolf
The London Underground A.K.A. The Tube is the oldest underground railway in the world, it currently consists of eleven lines* servicing 267 named stations (strictly 269** stations since "Edgware Road" and "Hammersmith" each occupy two locations) The challenge Output the names of the lines servicing a station given by n...
stackexchange_codegolf
Challenge: Given an NxN matrix where \$N\geq2\$ and one of eight distinct 'folding options', output a 2D array/list with the subtracted values. The eight folding options are: left-to-right; right-to-left; top-to-bottom; bottom-to-top; topleft-to-bottomright; topright-to-bottomleft; bottomleft-to-topright; bottomright-t...
stackexchange_codegolf
In the Thai calendar the year 2017 corresponds to 2560. The Thai calendar is always 543 years ahead of the Gregorian calendar. Observant coders will note that 2560 is equal to \$2^9 \times 5\$, in other words it has 10 prime factors. This will not happen again for another 896 years! We call a year tenacious if it has e...
stackexchange_codegolf
Challenge In this challenge, you will be writing the first program, p1, of an infinite sequence of programs, in which running pn outputs/generates program pn+1. When concatenating the first n >= 2 programs, the sequence should output n. Example Let's say the first 4 programs are: p1 p2 p3 p4 If I were to run p1, it sh...
stackexchange_codegolf
There's a lot of questions about Conway's Game of Life, but nothing about customization (Related: 2-Player Life). Given an input, determine the result on a 100x100 grid after some iterations. The input is given as a string. For example: Using the character #, follow the following rules: If there are 2 or 3 neighboring ...
stackexchange_codegolf
OEIS A090461 details the ‘numbers k for which there exists a permutation of the numbers 1 to k such that the sum of adjacent numbers is a square’. This has also been the subject of Matt Parker’s Numberphile and Alex Bellos’ Monday puzzle. This code-golf challenge is related to the square sum problem above and asks you ...
stackexchange_codegolf
With the US election going on right now, I noticed that there is one (completely meaningless, but still) thing which Trump can still achieve and which is out of reach for Biden: Having the won states being connected. Task: Given a list of strings of two-letter abbreviations (see below) for US states, determine whether ...
stackexchange_codegolf
PARI/GP is a free computer algebra system. It is designed for (algebraic) number theory, not golfing, but that's part of the attraction. Unsurprisingly, it fares best at mathematical tasks; its support for string manipulation is primitive. (Having said that, advice for golfing non-mathematical tasks is also welcome.) A...
stackexchange_codegolf
A loop is a pretty simple algebraic structure. It is a tuple (G,+) where G is a set and + is a binary operator G × G → G. That is + takes two elements from G and returns a new element. The operator is also required to fulfill two properties Cancellation: For every a and b in G there exists unique x and y in G such ...
stackexchange_codegolf
Your task is, given a positive integer n, to generate an expression that equals the number n. The catch is: you're only allowed the number 1 in the output. The operators at your disposal are: +, -, * and / / is floating-point division (so 5/2 = 2.5). sqrt (as s) ceil and floor (as c and f respectively) ! (factorial...
stackexchange_codegolf
Description I guess everyone knows the fairy tale of Rapunzel and the prince. For those who do not: read it here. However, Rapunzel had just had her hair cut, so it might not be long enough to let her prince climb up! She may get very sad.. Challenge Your task is to write a function that evaluates what Rapunzel will be...
stackexchange_codegolf
Given a 2-dimensional jagged array and a fill value, pad the array in both dimensions with the fill value to ensure that it is square and not jagged (i.e., all rows are the same length, and that length is the same as the number of rows). The fill values should always be added to the "edges", which may be the start or t...
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
Inspired by a tweet by Nathan W. Pyle There is, now, a standard method of converting your boring, normal human name into a mysterious, ethereal Ghost Name™️. Ably described by Mr Pyle... Use your first name: a - add “t” after it e - add “boo” after it h - becomes “s” n - add “oo” after it r - add “eee” after it...
stackexchange_codegolf
Write a quine which attempts to invert the case of as many ascii characters in the source code as possible. For example in javascript: (x=function(y){return ('(x='+y+')(x)').toUpperCase();})(x) Standard quine rules apply. The score is given by number of bytes in the source code - number of case inversions. For examp...
stackexchange_codegolf
Story In an unnamed company, some people use Java and some use C++. This was always a nuisance, and they kept on arguing which single language they should all be using. To settle the dispute, the management decided that they'll buy a translator program that will be able to rewrite their C++ programs to Java and vice ve...
stackexchange_codegolf
Task Read in a possibly infinite text stream or file, outputting its contents until the word hello has been output, abiding to the following rules. Once hello has been output, your code should quit immediately. It should not wait for a newline for example. Your code should output as it goes. That is it shouldn't read ...
stackexchange_codegolf
You place a standard die at the origin of a 2D grid that stretches infinitely in every direction. You place the die such that the 1 is facing upwards, the 2 is facing in the negative y direction, and the 3 is facing in the positive x direction, as shown in the figure below: You then proceed to execute a series of move...
stackexchange_codegolf
An Abecedarian Word is a word whose letters are in alphabetical order. Your goal is to write a program that outputs all abecedarian words from a given lexicon. Rules: Standard Loopholes are forbidden. If a word contains punctuation, diacritical marks, or any characters other than ASCII alphabet characters (A-Za-z), r...
stackexchange_codegolf
The idea for this code golf puzzle is from link: The Bridge and Torch Problem The inspiration for this code golf puzzle is the Bridge and Torch problem, in which d people at the start of a bridge must all cross it in the least amount of time. The catch is that at most two people can cross at once, otherwise the ...
stackexchange_codegolf
The Gray Code is a sequence of binary numbers of bitwidth n where successive numbers differ only in one bit (see example output). Reference Example input: 3 Example output: 000 001 011 010 110 111 101 100 Notes: This question seems to have a dupe but it's not, for that question is not a code-golf, and it demands dif...
stackexchange_codegolf
There's already a comprehensive list of tips for python here, so what I'm asking for are tips that specifically apply to using the numpy, scipy or pylab libraries. These can be either ways to shorten code already using numpy, or ways to shorten common python operations by using these libraries. One tip per answer, plea...
stackexchange_codegolf
You should write a program or function which receives a string representing a chessboard with only pawns as input and outputs or returns whether any capture is possible on the board. Input is in a FEN-like notation describing positions of white and black pawns with no other pieces present. You should decide if there is...
stackexchange_codegolf
Challenge Given two lists of strings where each string is of length 50 and each list is also of length 50 generate the shortest regex you can that fully matches all the strings in the first list and does not match any of the strings in the second list. Scoring Your score will be the average length of the regexes your p...
stackexchange_codegolf
I have so many secrets and nowhere to keep them! The goal is simple: write a program that lets you save a string and have it be protected by a password. The program will take an alias, password and (optional) secret as parameters. If this is the first time the program is called with a given alias, then it will store/re...
stackexchange_codegolf
Definition Given some number, x calculate the smallest number i such that 2i≥x. This is not a duplicate of this question. It is slightly different in that an input of 16 should yield an output of 4 whereas 16 returns 5 in the linked question. Input Input will be an unsigned 32-bit integer. Output Output will be an unsi...
stackexchange_codegolf
I'm a narcissist. (Not Really) I'm also very lazy... (Not Really) So I want to know the score of this question, and how many people have viewed it. But I'm too lazy to check myself... Challenge Your challenge is to output the score of this question, and how many views there are. No input may be taken, and output may...
stackexchange_codegolf
The task Given a multiline string with ascii art operators and numbers, parse the expression! Possible symbols Numbers: (3x4) / /| | --- ___ _| | --- ___ _| | --- | | |_| | | ___ |_ | --- ___ |_ | | --- ___ / / | ___ |_| | | --- ___ |_| | --- ___ | | | | --- Operators: (3x3) | -+- | ---...
stackexchange_codegolf