instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Surprisingly, I don't think we have a code-golf question for determining if a number is semiprime. A semiprime is a natural number that is the product of two (not necessarily distinct) prime numbers. Simple enough, but a remarkably important concept. Given a positive integer, determine if it is a semiprime. Your ou...
stackexchange_codegolf
Task Given a winning Wordle play results (clues), the target ("secret") word and a list of words, output a possible sequence of words leading to such results. The words in the list will be distinct and so should be the output. You may assume that for given inputs a solution exists. If there is more than one, you may ou...
stackexchange_codegolf
Given a positive number \$n\$, find the number of alkanes with \$n\$ carbon atoms, ignoring stereoisomers; or equivalently, the number of unlabeled trees with \$n\$ nodes, such that every node has degree \$\le 4\$. This is OEIS sequence A000602. See also: Paraffins - Rosetta Code Example For \$n = 7\$, the answer is \...
stackexchange_codegolf
The Task You are to write some ASCII Art Text as seen from this website for generating ASCII art! Rules Input will only be alphabetical text and spaces, and will be input as a single line. It is also case-insensitive. You needn't fix if the output text is longer than the terminal width. As long as it would be correct i...
stackexchange_codegolf
Background You awake on the ground. Above you is a giant stepped pyramid-like structure. Based on your ancient history lessons, you recognize it as a ziggurat. You have been transported by Dr. Sargostein back into ancient Mesopotamia to play a game. In this King of the Hill Ziggurat challenge, you will write a bot that...
stackexchange_codegolf
A prime gap is the difference between two consecutive primes. More specifically, if p and q are primes with p <q and p+1, p+2, ..., _q_−1 are not primes, the primes p and q define a gap of n = q_−_p. The gap is said to be started by p, and to have length n. It is known that arbitrarily large prime gaps exist. That is, ...
stackexchange_codegolf
Display the 12 numbers on a clock face exactly like this: 12 11 1 10 2 9 3 8 4 7 5 6 To better see the grid, here's one with dots: ...........12............ ....
stackexchange_codegolf
Help, I've been diagnosed with prosopagnosia! This means I'm no longer able to recognise faces.... :( Can you help me? The challenge You will be given an image as a matrix of regular ASCII characters separated by new line characters, and your task is to determine if it contains a face. Faces will look something like th...
stackexchange_codegolf
Given a positive input \$n > 0\$, output the amout of two types based on their rarity. The two types are called \$A\$ and \$B\$, we know the followings: \$n\$ is a limited input and the maximum is \$nmax\$ At the start \$B\$ is twice as rare as \$A\$ As the presence of \$A\$ increade the rarity of \$B\$ decreases When...
stackexchange_codegolf
Given a positive integer, write it as the sum of numbers, where each of them is in \$\{kt|k\in{1,9,81},t\in{1,2,3,...,64}\}\$. How many numbers at least are used? Shortest code win. Samples: Input Output Method 1 1 1 2 1 2 64 1 64 65 2 64+1 72 1 72 343 2 342+1 576...
stackexchange_codegolf
The title is an homage of the Natural Number Game, which is a nice interactive tutorial into proving certain properties of natural numbers in Lean. The definitions used in Lv1 will be reused here. I've done some improvements: Now it starts with import tactic, which means you can freely use powerful mathlib tactics. I...
stackexchange_codegolf
While the binomial coefficient are the coefficients of \$(1+x)^n\$, m-nomial coefficients are the coefficients of \$(1+x+x^2+...+x^{m-1})^n\$. For example, \$m(3,5,6)\$ is the coefficient of \$x^6\$ in the expansion of \$(1+x+x^2)^5\$. Write a program/function that takes 3 numbers as input and outputs the corresponding...
stackexchange_codegolf
Given a positive integer, find its smallest positive integer multiple which is a run of 9 followed by an optional run of 0. In other words, find its smallest positive integer multiple which is matched by the regex /^9+0*$/. For example, if the given positive integer is 2, then return 90, since 90 is a positive integer ...
stackexchange_codegolf
King of the Cards Code available here! In this King of the Hill challenge, you must write a bot that can play Crazy Eights. This is a card game often played by children, in which the objective is to empty your hand. How to Play The game of Crazy Eights is deceptively simple. At the beginning of the game, each player ge...
stackexchange_codegolf
Find the shortest way to generate a random number between 0-9 without repeating the last generated number. Here is an example written in javascript. var n=t=0; while(n==t){ t=Math.floor(Math.random()*9); } n=t; I don't know if it is possible, but it would be interesting if there is a solution using only one variabl...
stackexchange_codegolf
A number is in base-b simplified Goodstein form if it is written as b + b + ... + b + c, 0 < c ≤ b The simplified Goodstein sequence of a number starts with writing the number in base-1 simplified Goodstein form, then replacing all 1's with 2's and subtracting 1. Rewrite the result in base-2 simplified Goodstein for...
stackexchange_codegolf
Suppose we want to encode a large integer \$x\$ as a list of words in such a way that the decoder can recover \$x\$ regardless of the order in which the words are received. Using lists of length \$k\$ and a dictionary of \$n\$ words, there are \$\binom{n+k-1}k\$ different multisets possible (why?), so we should be able...
stackexchange_codegolf
As we all know, most Pokemon are created by combining some English (or Japanese) words; these words are the Pokemon's "etymology." For example, "charmander" is "char" and "salamander" put together. Your task is, given a Pokemon's etymology and number, output the original Pokemon name. A short answer will be able to com...
stackexchange_codegolf
A001057 is one way to represent an integer as a natural number. It lists them according to the following pattern: 0, 1, -1, 2, -2, 3, -3, 4, -4, ... In this challenge, you'll take two distinct integers as input and return which is at a higher index in this enumeration. Take -2 and 1 as an example: -2 comes after 1, so...
stackexchange_codegolf
In the poker game there are 1277 unique 'High Card' ranks. It's 1287 (13 over 5) if we include all straights. The challenge is to write a function which returns an integer value corresponding to the rank of each 'High Card' poker combination including all straights. Possible cards are(in ascending order): '23456789TJQK...
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
Create a bootloader that executes given Brainfuck program. This is code-golf, so the program with least bytes wins. Being a bootloader, the size of the program is counted in non-zero bytes in the compiled code. Brainfuck 30000 8-bit overflowing cells. Pointer wraps over. Some notes about operations: Input must be read...
stackexchange_codegolf
Haplology Haplology is a linguistic term: the omission of one occurrence of a sound or syllable that is repeated within a word, for example probly for probably. For this challenge, it means specifically, replacing any sequences of two or more letters that are repeated two or more times with just one copy. For example...
stackexchange_codegolf
For my CS class, my instructor has given us the assignment of creating a rectangle made of asterisks with diagonal lines drawn through it in Java. He also told us to write it in as few bytes as possible. I've gotten it down to 190 bytes, but I need to find a few to simplify this code even more to decrease bytes. Can an...
stackexchange_codegolf
You've recently made an account on a dodgy gambling site, where for a fee of 25 dollars, they will pay you back a random amount between 0 and 50 dollars. After getting around 5 dollars twice, you decide to prove the site is a scam. After accessing their external firewall with the default password, you find your way ont...
stackexchange_codegolf
Choose a challenge from the Cops thread, determine the third hidden message, and describe how the system works. Keep in mind limitations and possibilities available to Cops: You are not expected to guess any cryptographic secrets or additional information required to extract the hidden messages, as they should have al...
stackexchange_codegolf
THE TASK DEFINITIONS Consider the points {1,2,3,4,5} and all their permutations. We can find the total number of possible permutations of these 5 points by a simple trick: Imaging filling 5 slots with these points, the first slot will have 5 possible numbers, the second 4 (as one has been used to fill the first slot) t...
stackexchange_codegolf
Given an \$n\times m\$ matrix \$A\$ and two integers \$w,h\$, output a matrix of \$w\times h\$ called \$B\$, such that $$B_{i,j} = \int_{i-1}^i\mathbb dx\int_{j-1}^j A_{\left\lceil \frac xw\cdot n\right\rceil,\left\lceil \frac yh\cdot m\right\rceil}\mathbb dy\text{ (1-index),}$$ $$B_{i,j} = \int_i^{i+1}\mathbb dx\int_j...
stackexchange_codegolf
Introduction: In my recent Strikethrough the Word Search List challenge I mentioned the following: When I do the word-search puzzles, I (almost) always go over the words in order, and strike them through one by one. In some cases I do them in reversed order as a change of pace, although that doesn't matter too much r...
stackexchange_codegolf
Introduction The game takes place in a small world with different towns. The rulers of the towns hate each other and would like to rule the world. The people are divided into two groups, warriors and lowborns. However, lowborns can raise to warriors. You are the ruler of three of these towns. Gameplay When the game beg...
stackexchange_codegolf
Given only a straightedge and compass, inscribe a rhombus inside the given rectangle, sharing two opposite points. Input Input is the dimensions of the rectangle. In the example shown, that would be 125, 50. You can take input in whatever way is most convenient (as two integers, list, strings, etc). The larger dimensi...
stackexchange_codegolf
Given two inputs, a number n and a dimension d, generate the nth d-dimensional pyramid number. That was confusing, let me try again. For d = 1, the numbers start 1,2,3,4,5 and is the number of points in a line n points long. For d = 2, the numbers start 1,3,6,10,15 and is the number of points in a triangle with side le...
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
When I was a kid, and wanted to count the dollar bills in my life savings, I would count out loud: one, two, three, four, five, six, seven, eight, nine, ten; eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty; twenty-one, twenty-two, twenty-three, twenty-four, twenty-five.....
stackexchange_codegolf
The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd. The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is: _________ | | | | _...
stackexchange_codegolf
Challenge : Given a word, check whether or not it is an isogram. What : An isogram is a word consisting only of letters with no duplicates (case insensitive). The empty string is an isogram. Examples : "Dermatoglyphics" ---> true "ab" ---> true "aba" ---> false "moOse" ...
stackexchange_codegolf
Box blur is a simple operation for blurring images. To apply box blur, simply replace each pixel with the average of its and the surrounding 8 pixels' values. Consider, for example, the following example, in which each "pixel" has a one-digit value: \begin{array} {|r|r|}\hline 1 & 1 & 1 \\ \hline 1 & 7 & 1 \\ \hline 1 ...
stackexchange_codegolf
Description : You are given a string of numbers (positive and negative but not decimals) along with the number of entries like so. Like so 8 '1 2 5 0 7 -9 12 -8' Task : Your job is to return the number closest to zero be it +ve or -ve. Your input will be separated by spaces only. You are free to return the answer in a...
stackexchange_codegolf
Tonight, 31 January 2020, Brexit will happen and the United Kingdom will leave the European Union, the first time that the number of EU member states will decrease. Your job is to take a date and output the number of EU1 members on that date, according to the following table: | Start | End | Number of memb...
stackexchange_codegolf
N children, with no two sharing their exact size, are lined up in some order. Each can only compare heights with their immediate neighbours. When the teacher shouts "raise hands if you are the tallest", they do so if they are taller than both their neighbours, and they do so simultaneously. If only one raises their han...
stackexchange_codegolf
For this challenge you will print the coordinates and color of each piece at the start of a game of checkers. Enter the x and y (comma seperated) for every square (indexed 0-7) on a checkerboard, followed by a "r" or "b" (for red or black) where the top of the board (closer to y=0) is red and the bottom is black. newl...
stackexchange_codegolf
Given two arrays of non-negative integers \$A = [A_1,A_2,\ldots,A_n]\$ and \$R = [R_1,R_2,\ldots,R_n]\$ which are equal in length, return an array which has the element \$A_1\$ repeated \$R_1\$ times, then element \$A_2\$ repeated \$R_2\$ times, all the way up to \$A_n\$. Standard loopholes are forbidden. As this is co...
stackexchange_codegolf
In @Adám's Dyalog APL Extended, the ⍢ (under) operator means conjugation: apply one function, then a second function, then the inverse of the first. It's fun to think of real-life actions in terms of conjugation: A problem is transformed by g into another domain where it more readily solved by f , and then transfor...
stackexchange_codegolf
Challenge My challenge, is for you to generate a Menger Sponge based on the level/iteration given. You need to draw it in 3d, anyway you can. Examples Inputs: 0, 1, 2, 3 Outputs: Background Information What is a Menger Sponge In mathematics, the Menger sponge (also known as the Menger universal curve) is a fractal c...
stackexchange_codegolf
Task Given two positive integers, output the number of carries needed to add them together in long addition in base 10. Examples ¹¹¹ <-- carries 999 + 1 ---- 1000 Three carries are needed. ¹ 348 + 91 ---- 439 One carry is needed. Testcases 999, 1 -> 3 398, 91 -> 1 348, 51 -> 0 348, 52 -> 2 5, 15 -> 1 9...
stackexchange_codegolf
Surprisingly, I don't think we have a code-golf question for determining if a number is semiprime. A semiprime is a natural number that is the product of two (not necessarily distinct) prime numbers. Simple enough, but a remarkably important concept. Given a positive integer, determine if it is a semiprime. Your ou...
stackexchange_codegolf
Your task is to convert non-empty strings - between strings using the 26 letters, and programs, which are strings of bytes, where each byte has 256 possible values. You should use the same codepage your answer is written in for the possible values of bytes. You need to do the following to do the conversion: Convert th...
stackexchange_codegolf
This is a very simple challenge. Task Whenever your code is run, your code should output the next sunset date and time in GMT for all capital cities on Earth. You should get the list of capitals from the below table. The dates and times should be outputted sorted by the name of the capital. You don’t need to output t...
stackexchange_codegolf
What general tips do you have for golfing in Emotinomicon? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Emotinomicon (e.g. "remove comments" is not an answer). Please post one tip per answer.
stackexchange_codegolf
I'm looking for a program such that, given a finite list of strings, can find short regexes to match exactly all of them and nothing else. Since there are multiple languages that express regexes differently, there can correspondingly be multiple regex generators. Each answer must discuss regex generation in one langaug...
stackexchange_codegolf
How to spot them Take a positive integer k. Find its divisors. Find the distinct prime factors of each divisor. Sum all these factors together. If this number (sum) is a divisor of k (if the sum divides k) then, this number k, is a BIU number Examples Let's take the number 54 Find all the divisors: [1, 2, 3, 6, 9, 18, ...
stackexchange_codegolf
Challenge Write two programs that: run in two different programming languages. These may not be two versions of one language. when one program is run, it outputs the second program, and vice versa. The two programs must be different (no polyglots). Here's the catch though: The programs must be radiation hardened....
stackexchange_codegolf
Homologous series, any of numerous groups of chemical compounds in each of which the difference between successive members is a simple structural unit. As an example, Alkane is a homologous group where the chemical compounds are in \$C_nH_{2n+2}\$ format. \$CH_4\$ (Methane) is part of the Alkane group because \$CH_4 \t...
stackexchange_codegolf
Sandbox Post Intro The information panels are everywhere. When the technology became cheaper, the paper posters were transformed into luminous signs that show words that appear on one side and come out on the other, like the one on the figure: When one of these signs starts up, it usually starts empty and the text lea...
stackexchange_codegolf
Inspired by Digits in their lanes Input: An ASCII-art of width ≤ 11, consisting of spaces and #. (You can choose any two distinct characters instead.) Example: # ### # # # # # # # # # ### # # ### # ########### # # # # # ### # # ...
stackexchange_codegolf
Given a natural number n write a program or function to get a list of all the possible two factors multiplications that can be used to achieve n. To understand better what is pretended you can go to http://factornumber.com/?page=16777216 to see when n is 16777216 we get the following list: 2 × 8388608 4 × 41943...
stackexchange_codegolf
Your task is to create a program or function that takes, as input, a natural number (n) between 1 and 25 (inclusive) and prints an isometric representation of a slide and ladder with n number of rungs. Ladder and slide specifications The ladder is always oriented on the left and the slide on the right. We're viewing it...
stackexchange_codegolf
What is the shortest way of generating a random string with a given length and with only alphanumeric characters allowed? example of a random string: with N = 9 output would be aZua7I0Lk the given length N can be assumed to be always greater than 0 if necessary you can assume 256 as a maximum value for N, but solution...
stackexchange_codegolf
For this challenge, a word is defined as a string of letters, separated by spaces. Given a string of words, and an integer i representing an index into that string, output the whole word which contains the character at index i. For example (using 0-based indexing), with the string code golf, and the index 6, the 7th ch...
stackexchange_codegolf
Inspired by this challenge. Goal: Given a pre-configured switchboard and a list of indexes, invert the switches at the given indexes. A switchboard is made up of some number of switches (v or ^) wrapped in -'s and arranged into rows of varying length. Here is an example switchboard: -v-^-v- -^-v- -v-^-v- To invert/fli...
stackexchange_codegolf
Recently, I have found a bijective mapping \$f\$ from positive integers to finite, nested sequences. The purpose of this challenge is to implement it in the language of your choice. The Mapping Consider a number \$n\$ with the factors \$2^{a_1}3^{a_2}5^{a_3}\cdots p^{a_i}\$ where \$a_i > 0\$ $$f(n) = \{f(a_2+1),f(a_3+1...
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
True color (24-bit) at Wikipedia is described in pertinent part as 24 bits almost always uses 8 bits of each of R, G, B. As of 2018 24-bit color depth is used by virtually every computer and phone display and the vast majority of image storage formats. Almost all cases where there are 32 bits per pixel mean that...
stackexchange_codegolf
I've recently stumbled upon a Russian site called acmp.ru, in which one of the tasks, HOK, asks us to find the LCM of two positive integers. The full statement, translated to English is as follows: The only line of the input contains two natural numbers A and B separated by a space, not exceeding 46340. In the only l...
stackexchange_codegolf
There are one hundred members of the United States Senate. Assuming that nobody filibusters and that the Vice President isn't cooperating, at least fifty-one members are necessary to pass a bill. But some members work together better than others, entropy-wise. Your task: Output the last names of at least 51 of the US s...
stackexchange_codegolf
This is a code-challenge with a custom scoring system, where the lowest score wins. Introduction Many smartphones allow to enter text by swiping your finger across the 2D virtual keyboard. This technology is usually combined with a prediction algorithm that outputs a list of guessed words, sorted from most likely to le...
stackexchange_codegolf
I have a bunch of ASCII art that I have recovered from a failed hard drive. Unfortunately, all of the newlines were stripped out, and I don't know the resolution of the original artwork. I do know that each one was originally rectangular, but to make matters worse, all the white space at the beginning and end was strip...
stackexchange_codegolf
When Alice was touch typing on her QWERTY keyboard (Figure 1), she accidentally shifted both of her hands rightwards by one key, so q became w, w became e, etc. (p became [). Spaces were not affected because the space bar was quite big. Your task is to help her fix her message using the shortest number of bytes, i.e. u...
stackexchange_codegolf
Gray Code is a number system where only 1 bit of the number changes from one number to the next number. Print the 8 bit Gray Code values of 0 to 255. Shortest Code wins! Start of output: 0 00000000 1 00000001 2 00000011 3 00000010 4 00000110 5 00000111 6 00000101 7 00000100 ... You only have to print the Gra...
stackexchange_codegolf
A theorem in this paper1 states that every integral n-by-n matrix M over the integers with trace M = 0 is a commutator, that means there are two integral matrices A,B of the same size as M such that M = AB - BA. Challenge Given an integral matrix M with trace M = 0 find some integral matrices A,B such that M = AB - BA....
stackexchange_codegolf
A first order separable ordinary differential equation is (arguably) the easiest type of differential equation to solve, and takes the form of $$N(y)\frac{dy}{dx} = M(x) \\ y(x_0) = y_0$$ For two given functions \$N(y)\$ and \$M(x)\$ and an initial condition \$y(x_0) = y_0\$. Your task is to take \$N(y)\$, \$M(x)\$, \...
stackexchange_codegolf
Introduction A palindromic closure of an input string is the shortest palindrome that can be constructed out of the input string where the final palindrome starts with the input string. For this challenge, we will consider a two-way palindromic closure such that Left Palindromic Closure of an input string is the short...
stackexchange_codegolf
Here's a simple challenge, so hopefully lots of languages will be able to participate. Given a positive integer \$n\$, output \$A076039(n)\$ from the OEIS. That is, start with \$a(1)=1\$. Then for \$n>1\$: $$a(n)=\left\{ \begin{array}{ll} n\cdot a(n-1), & \text{if } n>a(n-1) \\ \lfloor a(n-1)/n \rfloor, & \text{otherw...
stackexchange_codegolf
Goal Your task is to create a program taking no input that returns the link to your answer. You can find a link to your answer by clicking at the share button on your answer. Rules Standard loopholes apply except for searching for the answer online. In fact, you are expected to find the answer online. You are allowed ...
stackexchange_codegolf
Let's make a little stupid program that simulates the meme "Mr. incredible becoming uncanny", but in this case, our little ASCII friend is going to react to our code length. Objective: Create a program that takes anything (preferably a program) as input and outputs this: Pov: <face> you score X on codegolf Where X ...
stackexchange_codegolf
From the wikipedia: Net neutrality is the principle that Internet service providers and governments regulating the Internet should treat all data on the Internet the same, not discriminating or charging differentially by user, content, website, platform, application, type of attached equipment, or mode of communicatio...
stackexchange_codegolf
Língua do Pê, or P Language, is a language game spoken in Brazil and Portugal with Portuguese. It is also known in other languages, such as Dutch and Afrikaans. (Wikipedia) There are some dialects in this language game. The different languages the game is played with even have their own unique dialects. Some people are...
stackexchange_codegolf
This is part of a cops-and-robbers challenge. Go here for the cops' part. The Robbers' Challenge A cop's answer can be cracked by removing any subset of characters from the Haystack program, so that it outputs Needle instead of Haystack (while still being a valid submission in the same language). You don't have to find...
stackexchange_codegolf
Let me tell you about a simple number system. (which I made up just for this challenge) This system contains the functions (), [], {}, and <>. 1. () When () is given no arguments, it evaluates to 0. When () is given one or more arguments, it evaluates to the sum of the arguments. 2. [] When [] is given no arguments, it...
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
What is the shortest amount of code that can find the minimum of an inputted polynomial? I realize that you can import packages like Numpy and others, but using only user defined functions, what is the shortest way to do this? For example, if 6x6 + 4x3-12 is entered (ignore parsing issues), what would be the shortest a...
stackexchange_codegolf
Given the measures of two of the interior angles of a triangle (x and y; the other angle can be easily calculated with 180 - x - y), draw a line segment that cuts this triangle into two isosceles triangles. You need to output the angle measures of both of your triangles. However, because the base angles are the same, y...
stackexchange_codegolf
The goal here is to simply reverse a string, with one twist: Keep the capitalization in the same places. Example Input 1: Hello, Midnightas Example Output 1: SathginDim ,olleh Example Input 2: .Q Exmaple Output 2: q. Rules: Output to STDOUT, input from STDIN The winner will be picked 13th of July on GMT+3 12:00 (One...
stackexchange_codegolf
The generalised harmonic number of order \$m\$ of \$n\$ is $$H_{n,m} = \sum^n_{k=1} \frac 1 {k^m}$$ In this challenge, we'll be considering the generalised harmonic numbers of order \$2\$: $$H_{n,2} = \sum^n_{k=1} \frac 1 {k^2}$$ This sequence begins \$1, \frac 5 4, \frac {49} {36}, \frac {205} {144}, \dots\$ and conve...
stackexchange_codegolf
Write a program or function that given n ≥ 1 returns the number of solutions to ±1 ± 2 ± 3 ± ... ± n = 0. For n = 6 there are no solutions, so the answer is 0. For n = 4 there are two solutions, so the answer is 2 (the two solutions are 1 - 2 - 3 + 4 = -1 + 2 + 3 - 4 = 0). This is OEIS sequence A063865. Some example in...
stackexchange_codegolf
Based on Chunky vs. Smooth Strings. Squiggles /\_/\/\__/\/\/\/\_/\_/\ are fun to make on a keyboard when you are really bored. But not all squiggles are created equal. Some squiggles are smooth, like \___/, and some are chunky, like /\/\/\/\. Others are just downright broken, like ////_\\\ Inside every squiggle of N...
stackexchange_codegolf
Just like code-golf, restricted-source pushes one to exploit quirks and hidden features of the Python language. We already have a place to collect all these tips for code-golf, those for restricted-source remain transmitted by word of mouth or hidden deep within the python documentation. So today I would like to ask y...
stackexchange_codegolf
(language-specific challenge) Specification: Language: ECMAScript, any version[1] Challenge: Somewhat like python's itertools.groupBy: Your function Array.group(f) should take as input an "equivalence function" f whose output defines our notion of an "equivalence key" for array elements (like a sort key). The return va...
stackexchange_codegolf
With all the gyms closed down with the COVID-19 situation, we have to exercise with the weight we have lying around at home. The problem is, we have a small selection of plates at varying weights, and can't immediately determine if we can create a setup at the desired weight. Given an unsorted array of weighted plates...
stackexchange_codegolf
Challenge You will be given a table as input, drawn with ASCII | and _. Your task is to set the chairs around it. Example Input: ____ | | | | | | | | |____| Output: _^_^_ < > | | < > | | <_ _ _> v v Those chairs are made of <> and v^. Another example: The line must have as many chairs ...
stackexchange_codegolf
NPM's sloc is a moderately popular tool for counting source lines of code in a file. The tool will attempt to strip out both single and multiline comments and count the remaining lines in order to get an estimate of the 'true' number of lines of code. However, the parser used is based on regular expressions and is quit...
stackexchange_codegolf
Background This is the first part of a 3-hole golf course on text processing. The over-arching idea is that if you take an input text and pipe it through the solutions to all three challenges (with a small amount of glue code), it will spit out a beautifully formatted paragraph. In this first challenge, your task is a ...
stackexchange_codegolf
Background For my code-golf submissions in C, I need a processing tool. Like in many other languages, whitespace is mostly irrelevant in C source (but not always!) -- still makes the code much more comprehensible for humans. A fully golfed C program that doesn't contain a single redundant whitespace often is barely rea...
stackexchange_codegolf
As TIO can show, every letter of the Latin alphabet is represented when it comes to languages. For every letter there is at least 1 programming language whose name begins with that letter. Your task is to create a polyglot in order to demonstrate that. Your program should be runnable in between 2 and 26 different langu...
stackexchange_codegolf
UTF-1 is one of the methods to transform ISO/IEC 10646 and Unicode into a sequence of bytes. It was originally for ISO 10646. The UTF-1 encodes every character with variable length of byte sequence, just like UTF-8 does. It was designed to avoid control codes. But it was not designed to avoid duplication of a slash cha...
stackexchange_codegolf
Consider all 2^n different binary strings of length n and assume n > 2. You are allowed to delete exactly b < n/2 bits from each of the binary strings, leaving strings of length n-b remaining. The number of distinct strings remaining depends on which bits you delete. Assuming your aim is to leave as few remaining diff...
stackexchange_codegolf
Let's do an exercise together, shall we? Simply follow the movements of the stickman. What stickman you ask? The one we are about to create! Make a program that allows for a string-input only containing integers, and outputs the following nine stick-figures with an interval in between: @ \@/ |@_ _@| @/ \@ |@| \@\ /...
stackexchange_codegolf
Cops' challenge This cops-and-robbers challenge challenges the Cop to write a non-empty program that, when run, produces some non-empty output in language A, and, when reversed, produces some non-empty output in language B. The program may produce any output to STDERR when run in either language, but may not take input...
stackexchange_codegolf
You must make a regex that matches everything except itself. For example, PPCG must not match PPCG, but must match everything else, like something, PPC, and PPCG!. Surrounding slashes are not considered part of the regex in flavors where they are usually part of the syntax. The same is true of all delimiters. The rege...
stackexchange_codegolf
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \end{cases} $$ It can be proved that it always terminates and evaluates to the simple function below: $$ t(x, y, z) = \begin{cases}...
stackexchange_codegolf