instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
I started a CodeWars kata in Python, just two days ago, related to code golf. Task: Given two congruent circles a and b of radius r, return the area of their intersection rounded down to the nearest integer, in less than 128 chars. Has to be a one-liner. Version: Python 3.6 External libraries: You may import NumPy as ...
stackexchange_codegolf
A "simple circular" word is a word whose chords do not intersect. The chords of a word may be seen by laying out the alphabet in a circle, and then connecting the word's consecutive letters. Examples of Simple Circular Words ROLE LAKE BALMY Failing Example A word fails to be simple circular if any of its chords in...
stackexchange_codegolf
Given a character, output (to the screen) the entire qwerty keyboard layout (with spaces and newlines) that follows the character. The examples make it clear. Input 1 f Output 1 g h j k l z x c v b n m Input 2 q Output 2 w e r t y u i o p a s d f g h j k l z x c v b n m Input 3 m Output 3 (Program terminates witho...
stackexchange_codegolf
33 is a simple esolang I created. You may have seen me use it in a few questions. You're not going to be writing a full interpreter. The interpreter you will be writing is for a simplified version of 33. This simplified 33 has two numeric registers: the accumulator and the counter. The accumulator holds all the post-ar...
stackexchange_codegolf
Given two nonnegative integers n,k such that 0 <= k <= n, return the binomial coefficient c(n,k) := (n!) / (k! * (n-k)!) Test cases Most languages will probably have a built in function. c(n,0) = c(n,n) = 1 for all n c(n,1) = c(n,n-1) = n for all n c(5,3) = 10 c(13,5) = 1287 Related challenges Catalan Numbers Compu...
stackexchange_codegolf
Background: MtDNA is a part of the human DNA that is passed from a mother to a child and it rarely mutates. Since this is true for all humans it is possible to create a huge tree that visualize how all humans are related to each other through their maternal ancestry all the way back to the hypothetical EVE. Every mutat...
stackexchange_codegolf
Introduction (may be ignored) Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the fourth challenge in this series (links to the first, second and third challenge). In this ...
stackexchange_codegolf
Inspired by We had a unit test once which only failed on Sundays, write a program or function that does nothing but throw an error when it is Sunday, and exit gracefully on any other day. Rules: No using input or showing output through the usual IO methods, except to print to STDERR or your language's equivalent. You ...
stackexchange_codegolf
All variables in this question are integer valued. Input 4 integers w, x, y, z. They can be positive or negative and will be less than 1048576 in absolute value. Output The general solution to the equation. \$ aw+bx+cy+dz = 0 \$. The variables \$a, b, c, d\$ must all be integer values. Output format Your output should ...
stackexchange_codegolf
Sequence Definition Construct a sequence of positive integers a(n) as follows: a(0) = 4 Each term a(n), other than the first, is the smallest number that satisfies the following: a) a(n) is a composite number, b) a(n) > a(n-1), and c) a(n) + a(k) + 1 is a composite number for each 0 <= k < n. So we start with a(0) =...
stackexchange_codegolf
Background MENACE (Machine Educable Noughts And Crosses Engine) is a rudimentary shallow machine learning algorithm for the game Noughts and Crosses, created by British computer scientist Donald Michie in the 1960s. It was originally implemented with 304 matchboxes, each labelled with a board position and containing co...
stackexchange_codegolf
CGCC hasn't always had MathJax. Back in the dark ages, it would have been necessary to write \$x^2\$ as x² (the horror!). In this challenge, you will be given some math which may include superscripts, and you should convert it to MathJax. Input: Input will consist of one or more letters a to z, some with superscripts. ...
stackexchange_codegolf
Introduction The EKG sequence begins with 1 and 2, then the rule is that the next term is the smallest positive integer not already in the sequence and whose common factor with the last term is greater than 1 (they are not coprimes). The first terms are: 1, 2, 4, 6, 3, 9, 12, 8, 10, 5, 15, ... It's called EKG because...
stackexchange_codegolf
Imagine that a list of integers describes the heights of some two-dimensional terrain as seen from the side. Stamina: [ 4 4 4 4 4 4 3 3 3 3 2 2 2 - ] O /|\ / \ +---+ +---+ | | | | +---+ ...
stackexchange_codegolf
Your task is to slowly calculate exponentiation, with the following steps: Given two inputs (in this example, 4 and 8), you must calculate the exponentiation by calculate the equation bit by bit. You would do 4^8, have a greater base value (4) and a smaller exponent (8). You can do this using more exponentiation and di...
stackexchange_codegolf
Your challenge is to query the SE API and find out whose rep on PPCG is tied, and output it. If these were all the users on PPCG: Martin Ender: 10000 rep Dennis: 10000 rep xnor: 5000 rep sp3000: 3000 rep You should output Martin Ender, Dennis. If these were the only users: Jon Skeet: 1000000 rep Martin Ender: 10000 re...
stackexchange_codegolf
Can you recover a sequence of letters from a sequence of dots and dashes? In Morse code, x is represented by -..-, but without the help of spaces, -..---.-... could represent xmas, or dole, or teettteteee, etc. I took the lyrics from "Rudolph, the Red-Nosed Reindeer" to make the following sequence of letters: youknowda...
stackexchange_codegolf
In this challenge, your task is to input a rectangle ASCII pattern (You may assume only printable characters need to be handled, and you may assume a trailing newline or not), C4_4 symmetrify, and output it. Here, C4_4 symmetric means symmetric under 90-degree rotation around a corner of the corner character. The corre...
stackexchange_codegolf
ed is the standard text editor on Unix systems. Your goal is to write an ed clone. Task Write a program that reads an input stream and for every received end of line character, print ? followed by a end of line character. The communication has to interactive. Means the program needs to output as soon as possible and h...
stackexchange_codegolf
For today's challenge you have to take an input, and if your source code is reversed, then the input should be printed doubled. Let's say your source code is ABC and its input is xyz. If I write CBA instead and run it, the output must be any of be xyzxyz or xyz xyz or xyz xyz For any numerical input you should not mu...
stackexchange_codegolf
Given a 7-segment display with some segments switched on and some off, find a sequence of digits (0-9), such that after toggling the corresponding segments for each digit, all segments are switched off. Example _ _ [3] => | [1] => [OFF] _ | Numbers and their corresponding segments: _ ...
stackexchange_codegolf
Given a string containing some parentheses and some other ASCII printable characters, like this: (abc((123))(k)) your task is to remove any sets of parentheses that are redundant. A set of parentheses is redundant if: It encloses another set of matching parentheses, like ab((123)), or It encloses the entire string, li...
stackexchange_codegolf
Shikaku is a 2D puzzle. The basic rundown of it is that a rectangular grid has some numbers in it, and you want to partition the grid into rectangular components such that each component contains exactly one number which is the number of grid squares in that component. This challenge involves a 1D simplification of thi...
stackexchange_codegolf
The Kolmogorov complexity of a string S is the length of the shortest program P, written in some programming language L, whose output is exactly S. (Yes, the real definition is more formal but this will suffice for the challenge.) Your task in this challenge is to write the shortest possible "Kolmogorov complexity solv...
stackexchange_codegolf
Disclaimer It is bad practice to draw out your molecules in 2 dimensions because that is not how they are. I chose to do this in 2D because it is easier to explain. Note that the bond angles are wrong too: the angle in CH4 is 109.5°, not 90° as I said and the bond angle in NH4 is 107°. BHCl2 does have a bond angle of ...
stackexchange_codegolf
This question got me nostalgic: Build a word generator! In the '80s I wrote a simple word generator in under 42kB (code and working memory) that would take a collection of strings and use them to create new words and phrases. Your task is to recreate this program in as few bytes as possible, with a few minor updates. Y...
stackexchange_codegolf
I'm trying to plug this really old phone into my computer but the phone seems to use a very obscure plug. Luckily I have some adapters. Unfortunately, I can't figure out which of them to use to connect my phone to my computer. Can you find the smallest number of adapters that can link my phone and computer? Input A pai...
stackexchange_codegolf
The goal is simple: Output a nonzero real solution x to the equation sin(x) = -mx, given input m, in the fewest number of bytes. Specifications: Your answer must be correct to 3 significant figures. You may output any real solution other than the trivial solution x=0. You can assume m is such that at least one soluti...
stackexchange_codegolf
Your task is to determine whether two numbers are easy to multiply. This means that their base-10 long multiplication doesn't have any carrying (regrouping) between place values, looking at both the multiplication steps and the addition step. This happens when each pair of digits being multiplied gives 9 or less and th...
stackexchange_codegolf
Challenge: Input: Two integer parameters a and b (where a<b and the difference is at least 2) Output: Output or return this text, where a and b are filled in: (a,b) = ]a,b[ = {a<x<b} = {a<x&&x<b} = a+1..b-1 [a,b) = [a,b[ = {a<=x<b} = {a<=x&&x<b} = a..b-1 (a,b] = ]a,b] = {a<x<=b} = {a<x&&x<=b} = a+1..b [a,b] = [...
stackexchange_codegolf
For any ragged list its dimensions will be a list of non-negative integers defined as follows: Elements that are not a list will have dimensions \$\textbf{[}\,\,\textbf{]}\$. An empty list has dimensions \$[0]\$. An \$n\$ dimensional list \$L\$ of length \$x\$ has dimensions \$x : k\$ where \$k\$ is the element wise m...
stackexchange_codegolf
A magic square is an n-by-n square grid, filled with distinct positive integers in the range 1,2,...n^2, such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal. Your task is to take an n-by-n matrix consisting of positive numbers, and a placeholder charact...
stackexchange_codegolf
Can Alice win the game? The game's rules are as follows. First, a finite non empty set of positive integers \$X\$ is defined. Then, Alice and Bob take turns choosing positive integers, with Alice going first. Each integer must be strictly less than the previous one, and the game ends when one of the players chooses \$1...
stackexchange_codegolf
Challenge: Write a lossless encoder/decoder that is able to compress its own source code. Usage: progname encode Encodes data provided on the standard input, writes the encoded representation of the data to the standard output. progname decode Decodes data produced by progname encode. Reads the encoded data from the s...
stackexchange_codegolf
Input An integer n and a pair of distinct integer valued (x, y) coordinates on the boundary of the grid. The coordinates are indexed from 1. For example, n=10 and (1,2), (10, 7). The points will always be on different sides of the grid and neither of them will be \$(1, 1)\$. Output The number of integer points in an n...
stackexchange_codegolf
If we assign each letter a respective integer, starting from 1, then a is 1, b is 2, c is 3, and so on. After z, the letters loop back around, but with a in front (aa, ab, ac). It then goes to ba, bb, bc... After this is completed, as you may have figured, another letter is added (aaa, aab, aac). "Prime letters" would...
stackexchange_codegolf
zipwith is a functional construct that takes three arguments: one binary function and two lists of the same length, and returns a single list where each element is constructed by applying the binary function to each pair of elements from the two lists: zipwith (a+b) [1,2,3] [4,5,6] = [5,7,9] You are to take a black-bo...
stackexchange_codegolf
Or Fix American Kennel Club's database As covered by the recent video by Matt Parker, the American Kennel Club permits thirty-seven (37) dogs of each breed to be assigned the same name (source), because of a database restriction for Roman numeral length. Given an integer, your task is to output the length of its Roman ...
stackexchange_codegolf
Task Suppose that p pepole have to split a bill; each of them is identified by a triple (Name, n, k) made up of: Name: the name; n: the amount she/he has to pay; k: the amount she/he actually paid. The challenge here is to find out how much who owes whom. Assumptions Input and output can be in any convenient format....
stackexchange_codegolf
Standard ML (or golfier: SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. (from Wikipedia) Though you almost certainly will never win a code golf challenge with SML, (ab-) using it for golfing can nevertheless be quite fun (<- keyword for function d...
stackexchange_codegolf
I've looked and could not find a post for this, if there is one, I'll remove it quick! Related and also related The goal is (hopefully) clear: create the shortest code (in bytes) that implements the AES256 ECB cipher mode. Either convert the result to Base64 or output a array of bytes. The input contains two parts. The...
stackexchange_codegolf
This will be a bit of a different challenge. Back in 2023, I developed a 2D esolang called Electra, and looking back at my hello world program, (which is 582 bytes by the way) I see a lot of room for golfing. There are some topics that aren't covered in the spec, e.g. in which order the currents are generated/interpret...
stackexchange_codegolf
If you've ever tried adding labels to a really dense plot, then you'll realise that sometimes labels will overlap one another, making them hard to read. We're going to do something similar but in 1D. Input will be a sequence of (label, x-coordinate) pairs, and output will be the result of drawing each point and label, ...
stackexchange_codegolf
In this code golf challenge, you will verify hashtags! #What_your_code_should_do Input is a string. Output a truthy value if it is a valid hashtag, and a falsy value otherwise. We define a string as a valid Hashtag if ... It starts with a hash (#). It doesn't have a number right after the hashtag (e.g. #2016USElection...
stackexchange_codegolf
Introduction In this challenge, we will be dealing with a certain infinite undirected graph, which I call the high divisor graph. Its nodes are the integers starting from 2. There is an edge between two nodes a < b if a divides b and a2 ≥ b. The subgraph formed by the range from 2 to 18 looks like this: 16-8 12 18 \|...
stackexchange_codegolf
Imagine you have an array of integers, whose non-negative values are pointers to other positions in the same array, only that those values represent tunnels, so if the value in position A is positive and points to position B, then the value in position B must be also positive and point to position A to represent both e...
stackexchange_codegolf
Introduction For a given rational number r, find a pair of integers p,q so that p/q=r and the number of less used bits in p and q are minimized (details below). Challenge A positive rational number r can be expressed as the ratio of two positive integers, r=p/q. The representation is not unique. For each of these repre...
stackexchange_codegolf
We define a tree-like list, or trist for short, as the empty list or a list containing only previously constructed trists. The natural numbers can either include 0 or not, according to your preference. The task is to create a pair of functions or complete programs f and g (they don't have to be named like this or even ...
stackexchange_codegolf
This is a very simple challenge, and it is to print the numbers -1, 0, and 1. The following paragraph is credited to Print numbers from 1 to 10 Your output format can be whatever your language supports. This includes arbitrary separators (commas, semicolons, newlines, combinations of those, etc., but no digits), and pr...
stackexchange_codegolf
Imagine you have two lights. These lights blink on and off at a specific rate: Light 0: Delay 0ms and then blink every 1000ms Light 1: Delay 500ms and then blink every 1000ms Let's simulate these lights for the first 2000ms: 0ms: Light 0 on 500ms: Light 1 on 1000ms: Light 0 off 1500ms: Light 1 off 2000ms: Light 0 ...
stackexchange_codegolf
Inspired by github.com/JackToaster/Reassuring-Parable-Generator, in turn inspired by xkcd.com/1263. The possible words are derived from the reassuring.cfg of that repository. Having a look at the reassuring.cfg (use the 12th commit) is suggested to see the grammar the output matches (The output is a list of all strings...
stackexchange_codegolf
Consider the following probability puzzle. We start with a string of bits all set to 0. At each step we choose a bit uniformly and independently at random and flip it. The value your code has to compute is the probability of getting to the all 1s bit string before you get back to the all 0s bit string. Let \$n\$ be the...
stackexchange_codegolf
What's the shortest, well-formed C++ code that exhibits undefined behavior?
stackexchange_codegolf
In this challenge, you need to find a specific pixel within an photograph (taken with a real camera). You are passed an (R, G, B) tuple and an image, and you need to return a point (x,y) within the image that matches the RGB color given. The image may have multiple points that match the color; you only need to find 1....
stackexchange_codegolf
Yes, I know there is a similar question, but this one specifically concerns any possible words, even with letters left over, while the linked one restricts to a permutation of the input Objective Have you ever had those moments in a Scrabble game where you're staring at your letters, trying to find a good word, and y...
stackexchange_codegolf
Can you think of a regular expression that does not match itself?
stackexchange_codegolf
Consider an array A of integers of length n. The k-max subarray sum asks us to find up to \$k \leq 3\$ (contiguous) non overlapping subarrays of A with maximum sum. If A is all negative then this sum will be 0. If A = [-1, 2, -1, 2, -1, 2, 2] and k=2 for example, then the two subarrays could be [2, -1, 2] and [2, 2] ...
stackexchange_codegolf
Given a ragged list of positive integers find the size of the largest list contained somewhere in it. For example: [1,[1,[8,2,[1,2],5,4,9]],2,[],3] Here the answer is 6 because one of the lists has 6 elements and all other lists have fewer. [1,[1,[8,2,[1,2],5,4,9]],2,[],3] ^ ^ ^ ^ ^ ^ The length doesn't ca...
stackexchange_codegolf
Challenge Assume two vectors \$\mathbf{a} = (a_1,a_2,\cdots,a_n)\$ and \$\mathbf{b} = (b_1,b_2,\cdots,b_n)\$ are given in an \$n\$-dimensional space, where at least one of \$b_1,\cdots,b_n\$ is nonzero. Then \$\mathbf{a}\$ can be uniquely decomposed into two vectors, one being a scalar multiple of \$\mathbf{b}\$ and on...
stackexchange_codegolf
your challenge is to draw this ASCII art: | | |- - - - | | - - - | | | | | | | |- - -| |- - - | | | | | | | | | | | | | |- - - - |- - - |- - - - - - remember this is code golf meaning you have to answer in the leas...
stackexchange_codegolf
Input: A grid of varying size only containing numbers in the range 00-99, the following four characters: ^; >; v; <, and spaces to fill (and new-lines of course). Output: The result of the sum (integer) when you follow the path. How does this work? You start at the arrow with the highest number, and follow the path t...
stackexchange_codegolf
Background Information: What is a Fenwick Tree? With a normal array, it costs \$O(1)\$ to access and modify an element, but \$O(n)\$ to sum \$n\$ elements. Working with a prefix sum array (an array where the \$i\$th value represents the sum of the first \$i\$ values in the underlying data), access and summation are \$O...
stackexchange_codegolf
Find the nearest Date to a TargetDate for a given Day of Week. For example, given a date of 20161219 and a day of week of Friday (6), the answer is 20161216. Another example, given a date of 20161219 and a day of week of Wednesday (4), the answer is 20161221. A final example, given a date of 20161219 and a day of week ...
stackexchange_codegolf
Wheat Wizard has once tried to come up with a parsing problem unsuitable for regex, but it failed due to Anders Kaseorg's Perl regex answer. This is the second attempt. Now that we know that Perl regex is far more powerful than we've imagined, this challenge aims to be un-golfy for it instead. Introduction A lambda ter...
stackexchange_codegolf
Construct a full program which outputs Hello, World!. The score of your submission will be equal to the sum of all of the ASCII values of the distinct characters. The lowest score wins! Rules It must be a full program which takes no input It must only print to STDOUT, nothing else It must be strictly less than 1000 by...
stackexchange_codegolf
According to Alexa rankings, the top 10 websites are: google.com youtube.com facebook.com baidu.com yahoo.com wikipedia.org amazon.com twitter.com qq.com google.co.in Being the top 10 visited websites, these are probably also the top 10 misspelled websites [Citation Needed]. Your task Your goal is to write a program o...
stackexchange_codegolf
In the face of some regrettable rules that turned the original into a glorified sorting task, I am posting a more challenging variant. Shout out to Luis Mendo for the suggestion of how to improve the original challenge. You've inherited a server that runs several apps which all output to the same log. Your task is to ...
stackexchange_codegolf
I'm not sure if this kind of golf is allowed, but here it is. Your objective is to create an image containing one pixel of every possible RGB color. The image with the smallest file size wins. Rules: The image must be a PNG. The image must contain exactly one of every possible RGB color. Acceptable image dimensions ar...
stackexchange_codegolf
Brainf**k is the most famous esoteric programming language and is the inspiration for hundreds of other esoteric languages. In fact, there are quite a few languages that are so heavily based off of Brainf**k that the only difference is the characters used. Your challenge is to interpret one of these languages. Brainf**...
stackexchange_codegolf
The French spell out numbers in a peculiar way. 1-16 are "normal" 17-19 are spelled out 10+7. 10+8, 10+9. 20-69 are "normal" (OK, OK! Not really, but they are in this challenge) 70-79 are 60+10, 60+11 ... 60+10+7, 60+10+8, 60+10+9. 80-99 are 4*20, 4*20+1, 4*20+2 ... 4*20+16, 4*20+10+7, 4*20+10+8, 4*20+10+9 Challen...
stackexchange_codegolf
Related: I double the source, you double the output! When Steve Jobs launched the iPhone 3G, the slogan said Twice as fast, half the price I changed the word fast to long to better represent this challenge. Objective Write a program that outputs a non-zero, even integer. If the source code is doubled, the value of t...
stackexchange_codegolf
Background We will be using a 3x3 cube for this challenge. Rubik's cubers have their own notation for movements on the cube: Each of the 6 faces has a clockwise turn notated with a single capital letter: UDLRFB. There are three additional letters MES denoting the three center slices. Counterclockwise rotations have a ...
stackexchange_codegolf
Given: a width, a height, and a set of sets of points. Output: An image where each set of points is connected and colored in (like a shape). Each shape must be a different color from all of the other shapes, but the actual color doesn't matter as long as each color is distinct. The shapes must be in order; whether you ...
stackexchange_codegolf
Write a program or function that takes a character as input and outputs a character. Also, choose a list of 13 distinct ASCII printable characters (32-126). When a character from this list is passed into the program or function, it should output the character at the corresponding position in Hello, world!. This way, ru...
stackexchange_codegolf
Challenge Create a program that outputs a square grid showing visible and non-visible points \$(x, y)\$ from the origin based on their greatest common divisor (GCD). A point \$(x, y)\$ is considered visible from the origin \$(0, 0)\$ if the \$\gcd(x, y) = 1\$. Otherwise, it's non-visible. Input An integer \$n\$, repre...
stackexchange_codegolf
This challenge is from a game, Keep Talking And Nobody Explodes. This is like one of those toys you played with as a kid where you have to match the pattern that appears, except this one is a knockoff that was probably purchased at a dollar store. – From the manual Objective The Simon Says module consists of 4 colored ...
stackexchange_codegolf
Since I've been seeing more ><> submissions floating around lately, I thought it might be a good idea to have a tips page. Please stick to one tip per post, unless they are closely related. Official Python interpreter Official Interpreter on TIO Online interpreter (some bugs present, but good for most cases) Another O...
stackexchange_codegolf
An LTL Formula l is defined by the following grammar (where <x> describes the non-terminal symbol x): <l> ::= <b> | F <l> | G <l> | X <l> | (<l> U <l>) | (<l> W <l>) | (<l> R <l>) | (<l> & <l>) | (<l> \| <l>) | !<l> <b> ::= BVar | True | False | (<i> < <i>) | (<i> <= <i>) | (<i> > <i>) | (<i> >= <i>) ...
stackexchange_codegolf
Amazingly, this simple task doesn't seem to exist already, so... Your task is to write a program that takes as input a 12 hour time, and converts it into "military time", or 24-hour time format. Input will be in the form: HH:MM am/pm Although slight variations are allowed: The space separating the am/pm from the res...
stackexchange_codegolf
Dr. Trump is the head psychiatrist at a mental hospital, which is populated by murdering psychopaths. If 2 psychopaths are left together, they will end up brutally injuring or even killing each other, so Dr. Trump needs to build walls to separate these psychopaths, but owing to the limited amount of funds he has left, ...
stackexchange_codegolf
Create the shortest function to print a magic square of given size. A magic square is a NxN matrix of distinct numbers and the sum of each row, column and diagonal is equal to a constant. A magic square of size 4 is: 07 12 01 14 02 13 08 11 16 03 10 05 09 06 15 04 And the constant is 34. The function should be able to...
stackexchange_codegolf
Your task is to write a program that runs in two different languages, and does the following: In one language, it palindromizes a given string. Take the string. abcde Reverse the string. edcba Remove the first character. dcba Glue it onto the original string. abcdedcba In another language, it depalindromizes a give...
stackexchange_codegolf
This happy individual is known in folklore as the Easter Bunny. Colours It is created using 4 colours: Light pink Dark pink White Black (I'm happy for these colours to be approximated in your answer. It does not need to be this precise shade) Shapes It is constructed of these shapes: Two tall ellipses in light pink...
stackexchange_codegolf
Note that this is not the same as Print the alphabet four times. This task is to write a program to generate four copies of each letter of the English alphabet, one letter per line, on standard output: A A A A B B B B etc. The output should include newlines after each letter. Lowercase letters and/or extra whitespace ...
stackexchange_codegolf
A superpermutation on n symbols is a string which contains every permutation of n symbols in its body. For instance, 123121321 is a superpermutation on three symbols because it contains 123, 132, 213, 231, 312 and 321 as substrings. The Challenge Given a string composed of n unique symbols (and, optionally, n), output ...
stackexchange_codegolf
the goal Build an optimizing Brainfuck implementation. Whether it is a compiler, an interpreter, a JIT compiler, or whatever else is up to you. scoring A reference implementation (bfi) will be given. Each implementation will run the same program (mb.b) also given at the end. Your score is time spent to run `mb.b` trans...
stackexchange_codegolf
The Problem A doomsday scenario is described by three numbers on a single line, n, m, and p. Following that line are n lines with m values per line. Each value represents the total units of water each cell can hold. The following p lines describe the weather for the next p days. 1 unit of rain falls on a single cell ea...
stackexchange_codegolf
This is a two-player card game which resembles a vastly simplified game of Texas Hold'em, combined with RPS (rock-paper-scissors) and the most basic mechanic of commercial turn-based card games. The deck A single full deck consists of 30 unique cards, where each card has one symbol out of RPS and one number between 0 a...
stackexchange_codegolf
Well, everyone loves Polyglots. You will be given two integers, in any standard form of input (no hardcoding). Your task is to write a polyglot which finds the minimum value in a language and the maximum value between the two numbers in the other language, and performs the following operations: The code which finds th...
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
Background The monkeys need your help again organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options as they appear in your insta-monkey collection. Each tower has three unique upgrade "paths", called "top", "middle", and "bottom", each having a...
stackexchange_codegolf
Inspired by Is it double speak?, I devised a harder challenge. Given a string, determine if the string is n-speak, for any \$n\geq 2\$. N-speak is defined by repeating each letter \$n\$ times. With \$n = 4\$, the string Hello is transformed to HHHHeeeelllllllloooo. Your goal is to figure out if the input is a valid out...
stackexchange_codegolf
My family has an e-commerce business. On our own site, we force people to choose their state from a dropdown menu when they enter their address, but through some other channels we use, customers can enter anything they want into the box. My mom loves the invoice templates I made for her, which are automagically generat...
stackexchange_codegolf
Golf Golf! This is my first challenge, so please be gentle! The challenge is to write a program that will output the correct score for a layout in the card game "Golf." The card game Golf has many variations. The house rules I use follow the standard rules for Six-Card Golf given by Pagat, with one slight difference. T...
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
Given a number n > 77, write a program or function that finds a set of distinct positive integers such that the sum of the set equals n, and the sum of the reciprocals of the set equals 1. Example for 80: 80 = 2 + 4 + 10 + 15 + 21 + 28    ⟶     1/2 + 1/4 + 1/10 + 1/15 + 1/21 + 1/28 = 1 Your program or function must...
stackexchange_codegolf
Since programming is predicted to become natural linguisized by the unstoppable advances in LLM technology, perhaps we can code golf LLMs themselves. Produce the shortest question that is not an arithmetic problem (we know it sucks at multiplication problems) that produces an obvious falsehood from ChatGPT with screens...
stackexchange_codegolf
This was originally a pure mathematics question, but I think I've got the best chance for an answer here. The Challenge For concreteness, consider Peano Arithmetic (PA). For some language L of your choosing, construct a computer program of length at most N bits in L such that: If it terminates, it outputs a number th...
stackexchange_codegolf
Given a possibly nested, non-empty array of single-digit positive integers (not guaranteed unique), output the ASCII-art representation as a tree, using the box-drawing characters ┌ ┴ ┐ ─ │ ┬ ┼. (These were copied from Code Page 437, but you can use any equivalent representation). Every integer of the array should be a...
stackexchange_codegolf
Inspired by the problem with the same name on Puzzling SE by our very own Dmitry Kamenetsky. You are to find the largest number that only uses every digit pair once, in a given base. For example, in ternary we have 2212011002. Challenge: Given a base from 2-10, output the largest number in that base with no repeating d...
stackexchange_codegolf