instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Background: I often find that, when browsing a Stackexchange site, I begin to wonder how people get the amount of reputation that they have. I know I can always count on codegolf SE to solve my problems, so here it is: Create a program that will accept a positive integer which represents a person's reputation. We will ...
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
Your task is to modify the original Plan 9 cat tool for UNIX, in order to make it a fully turing complete language interpreter. You may make use of ANSI escape codes and the backspace character (\x08) to aid in this. You must submit: A modified version of the Plan 9 cat tool A hexdump of the turing machine that can be...
stackexchange_codegolf
A palindrome is a string which is the same when read forwards and backwards. For example "racecar" is a palindrome, but "Racecar" is not. A substring is a contiguous set of characters in a larger string. Your task is to write a program or method which takes a string or character array as input and outputs the length of...
stackexchange_codegolf
421 is a rather popular dice game in France and some other European countries. It is mostly played in bars and pubs to determine who's going to buy the next round of drinks. The full game is usually played in two rounds, with tokens that each player tries to get rid of, but this is irrelevant here. (Wikipedia page in F...
stackexchange_codegolf
Problem Build an octal calculator that can do the following operations: Add (+) Subtract (-) Multiply (*) Divide (/) Check is prime Counting in octal is like this with decimal (Octal) (Decimal) 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 10 8 11 9 and so on.....
stackexchange_codegolf
Somehow, we don't yet have a challenge for finding the inverse of an arbitrarily-sized square matrix, despite having ones for 3x3 and 4x4, as well as a more complex version. Your task is, given a square \$n\times n\$ non-singular matrix \$M\$, output the matrix \$M^{-1}\$ that satisfies $$MM^{-1} = I_n$$ There are a nu...
stackexchange_codegolf
Uptime is a very important metric, as we all know, so we'd like to measure the uptime since our service was first launched. The SLA specifies an uptime of a certain number of nines, such as 3 nines for at least 99.9% uptime, or 1 nine for at least 90% uptime, and you're wondering if you've actually met the SLA or not. ...
stackexchange_codegolf
The Fibonacci sequence is a fairly well known thing around here. Heck, it even has its own tag. However, for all that, we sure like to stick to our roots of 1, 1, ... (or is it 0, 1, ...? We may never know...). In this challenge, the rules are the same, but instead of getting the nth item in the Fibonacci sequence, you...
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
Given a positive integer, we can form a new number that's described by its digits taken pairwise (with a leading 0 added for numbers with odd number of digits). For eg.: 1234 can be read as one 2, three 4s - so, the output for 1234 is 2444. 643 has an odd number of digits, so a leading zero is added to make it even....
stackexchange_codegolf
Whenever you make a move on a Rubik's Cube, there is a reverse move which undoes the first move. Because of this, every algorithm (set of moves) has a reverse algorithm which undoes the first algorithm. The goal of this challenge is to find the reverse of a given algorithm. Specification: The input consists of an array...
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
Background Conway chained arrow notation is a notation to express very large numbers. It consists of zero or more positive integers separated by right arrows, e.g. \$2 \to 3 \to 4 \to 5 \to 6 \$. Assuming \$p, q, a_1, \dots, a_n\$ are positive integers and \$X\$ is an abbreviation for a nonempty chain \$a_1 \to a_2 \to...
stackexchange_codegolf
Or, "Swap the first and last letters of each word" Your challenge is to, given a string of alphabetical ASCII characters as well as one other character to use as a delimiter (to separate each word), swap the first and last letters of each word. If there is a one-character word, leave it alone. The examples/testcases us...
stackexchange_codegolf
Break two numbers up into their powers of 2, if they share any, return a falsey value. Otherwise, return a truthy value. If one input is 0, the answer will always be truthy. if one input is 255, the answer will be falsey if the other is not 0. Example Given 5 and 3 5 = 2⁰ + 2² 3 = 2⁰ + 2¹ Both share 2⁰, return falsey....
stackexchange_codegolf
The Stern-Brocot tree is a binary tree of fractions where each fraction is acquired by adding the numerators and denominators of the two fractions neighbouring it in the levels above. It is generated by starting with 0/1 and 1/0 as "endpoint fractions", and from there, iterating by placing one fraction between each con...
stackexchange_codegolf
Thanksgiving in the United States is coming up on November 24th. Many people will have a large dinner with their families, traditionally including turkey and many side dishes. This typically means the family members must coordinate who's going to bring each of the various dishes. In this challenge, the goal is to write...
stackexchange_codegolf
The language Splinter is an esoteric programming language where data is stored in 'splinters'. There are three different types of syntax: Simple character output: \character, outputs a character Splinter storage: (splinter name){code}, stores the code into the splinter with the correct name for later use as is. No...
stackexchange_codegolf
This should be easy: given an arbitrary string, your program will give it a name. Requirements Your program will accept an input of a UTF8 string, and output a string representing the input's "name", how you define this name is arbitrary, but it must comply with some conditions. I/O Ranges The input will at most be 382...
stackexchange_codegolf
Your task is simple: tell me who wins the battle of the letters. The troops There are three different "troops" in this battle, summarized by this table. name | health | damage A 25 25 B 100 5 C 10 50 You may use any three unique characters to represent the the troops, but m...
stackexchange_codegolf
Multi-level marketing related challenge. A peer wants to get rewarded. So it attracted N investors (N>=1), each i-th investor invested x[i]. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T a peer could be rewarded. But only if a following conditions are satisfied: Minimum amount of investors should be gre...
stackexchange_codegolf
Repost and improvement of this challenge from 2011 A vampire number is a positive integer \$v\$ with an even number of digits that can be split into 2 smaller integers \$x, y\$ consisting of the digits of \$v\$ such that \$v = xy\$. For example: $$1260 = 21 \times 60$$ so \$1260\$ is a vampire number. Note that the dig...
stackexchange_codegolf
Recently, I've seen Hare Krishna people with their mantra on the emblem and I've found it may be quite interesting to code golf. The challenge Write the Hare Krishna mantra, i.e.: Hare Krishna Hare Krishna Krishna Krishna Hare Hare Hare Rama Hare Rama Rama Rama Hare Hare Winning criteria This is code-golf, so shortest...
stackexchange_codegolf
I have the code below working. But there must be a better way. file <- "http://s3.amazonaws.com/assets.datacamp.com/production/course_1127/datasets/tmp_file.csv" x <- read.csv(file = file) ts <- xts(x = x, order.by = as.Date(rownames(x), "%m/%d/%Y")) cd=coredata(ts) for (j in 1:length(names(ts))) cd[,j]<-cd[,j]/cd[1,...
stackexchange_codegolf
You met a 4-th dimensional being who challenged you to a game of dice. The rules are simple: each player rolls 3 6-sided dice and takes the sum of each combination of 2 dice. The player with the highest sum wins. If the first-highest sum is a tie, consider the second-highest sum, and so on. Your opponent's dice look no...
stackexchange_codegolf
In this challenge we are going to consider lists of integers such that for every member \$x\$ at index \$i\$ then the indexes \$i+x\$ and \$i-x\$ have the value \$x+1\$ or are out of bounds for the list. We will call these trampoline lists. If we play around with these for a while we can notice that if we start a list...
stackexchange_codegolf
Task Given a letter (A, B, C), and a number (0-10), output the size of the matching standard paper size (Series A and B) or the matching standard envelope size (C series) in millimetres in the format aaaa x bbbb where aaaa and bbbb are the width and height measurements in millimetres as per ISO216 (Series A & B) or ISO...
stackexchange_codegolf
The challenge is actually extremely simple. Pick 5 distinct letters (you can just pick the 5 that allow you the shortest code if you like) and output them to the console. However, the twist is that they must be from the following list: AAA BBBB CCCC DDDD EEEEE FFFFF GGG H H A A ...
stackexchange_codegolf
Telephones in the United States (and perhaps some other places) have letters associated with some of the numbers. 2 = A, B, C 3 = D, E, F 4 = G, H, I 5 = J, K, L 6 = M, N, O 7 = P, Q, R, S 8 = T, U, V 9 = W, X, Y, Z No letters are associated with the number 0 or 1. Your challenge: Given any phone number in seven-digit...
stackexchange_codegolf
Siteswap is a notation for juggling patterns. The other siteswap puzzle is great and it explains siteswap in greater detail than here. This puzzle is meant to be a bit simpler! Numberphile recently interviewed Colin Wright which helped develop the notation. The part at ~16min will be useful for this challenge. Another ...
stackexchange_codegolf
This sequence is defined as Starts with 1, 2, 3 The next element of the sequence is the first number greater than the previous three that is co-prime with each of the previous 3 elements in the sequence. In other words, if the previous 3 elements are a, b, c, then the next is the first integer n>c such that gcd(a,n)=...
stackexchange_codegolf
Introduction Every string has an "alphabet", composed of the characters that make it up. For example, the alphabet of \$abcaabbcc\$ is \${a, b,c}\$. There are two operations you can do with alphabets: getting the alphabet of a string, and seeing if another string has a given alphabet. Challenge Given two strings, you m...
stackexchange_codegolf
Inspired by this challenge, and similar to this and this. After seeing these, I figured I would continue the trend as there was no inclusive/exclusive sum. The goal here is to sum an interval of integers, either inclusive and exclusive, and output the total to stdout. Input format: either a ( or [ followed by 2 comma s...
stackexchange_codegolf
Cell Phone Keyboard Typing This question was asked a while back, but was closed due to poor specs. So, I'm redoing it, with better specs. This question is related, but goes in the opposite direction. Before T9 came around, in order to type a character in a text message, you had to press one of the number keys a number ...
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
From Wikipedia: The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828, and is the limit of (1 + 1/n)n as n approaches infinity. Challenge Calculate the number e to 15 digits after the decimal point. This means that your output must start wi...
stackexchange_codegolf
Input: A list of integers Output: Put each digit (and the minus sign) in its own lane, in the order -0123456789, ignoring any duplicated digits. Example: Input: [1,729,4728510,-3832,748129321,89842,-938744,0,11111] Output: -0123456789 <- Added as clarification only, it's not part of the output 1 2 7 ...
stackexchange_codegolf
Many formulas in math involve nested radicals (square root signs inside other square roots signs). Your task here is to draw these using ascii art. Specs You will be given two integers, the number inside the radical, and the number of radicals. I think the best way to explain what you have to do is with an example. Her...
stackexchange_codegolf
In this challenge, I have a field of avocados which I'd like to juice as quickly and completely as possible. Can you write a program or function to help me work out how to juice all the avocados perfectly? As input, you'll get the avocados as an mxm square grid, where m is an integer between 3 and 6. Each square contai...
stackexchange_codegolf
Part of Advent of Code Golf 2021 event. See the linked meta post for details. Related to AoC2017 Day 9. Weekends are Bubbler's days off from posting these lol A large stream blocks your path. According to the locals, it's not safe to cross the stream at the moment because it's full of garbage. You look down at the str...
stackexchange_codegolf
A string is dot-heavy when its morse representation contains more dots than dashes. For example, the letter E is a single dot, which means it is Dot-heavy. Input The input string will only contain characters in the range of [a-z] or [A-Z]. You can decide if they should all be upper case, or all lower case. AAA is fine...
stackexchange_codegolf
This is a brainfuck version of Largest Number Printable, and this. Let's think about brainfuck interpreter such that, Has array that can be stretched left & right arbitrary large Each cell can contain arbitrary large integer Can contain negative integer too When the interpreter starts, every cell is intialized by ...
stackexchange_codegolf
Write a program or function that takes N, and S and outputs the number of palindromes of length S you can build using an alphabet of size N such that any prefix of size between 2 and S-1 is not a palindrome. For example if N were 2 and S were 5 The valid palindromes would be 01110 10001 And thus the answer would be 2 ...
stackexchange_codegolf
One of many unique features of the Malbolge programming language is its highly unintuitive OP operator, referred to only as "op" in the documentation and source code but popularly known as the "crazy" operator. As described by Ben Olmstead, the creator of the language, in its documentation: "don't look for pattern, it'...
stackexchange_codegolf
Introduction: I collect twisty puzzles. Most twisty puzzles are produced and sold by Chinese companies. Most well-known companies ask permission from puzzle designers to produce their designs and work together towards a product on the market. In this case, puzzle designers are of course very happy and proud that one of...
stackexchange_codegolf
Make a quine. Simple enough, except it has to be a palindrome and accept input. Now, any side of a palindromic quine is one half of it. For example, one side of the hypothetical quine AAAA is AA. One side of AAAAA is AA (the center symbol is ignored). Your job is to make a quine like this that accepts input. If the inp...
stackexchange_codegolf
Alice is an intern in a company that uses Brainfuck as a primary language for both client-side and server-side development. Alice just has written her first code and she's a bit nervous as she's getting ready for her first code review. Alice wants to make her code properly formatted and look nice, but she has no time t...
stackexchange_codegolf
Write the shortest program or function that will determine if an input is a valid Go type. Spec This challenge will use the following simplified subset of Go types. For more information, see the Golang specification. "Primitive" types: bool int,uint,float(32|64),complex(64|128),byte,rune string *T where T is any ty...
stackexchange_codegolf
Introduction This is the evolution of this previous challenge which was about checking satisfieability of normal formulae in conjunctive normal form (CNF). However, this problem is NP-complete and watching algorithms finish is just boring, so we're gonna simplify the problem! Specification Input You may tune the follow...
stackexchange_codegolf
I was looking for a very easy task to look how short of a code can be produced on a beginners exercise. The goal is to produce a simple table that looks like this common java/c# code is about 4 lines. So get your golfing-languages ready ;) Try to align the matrix in any way it is readable. 1 2 3 .. 10 2 4 6 .. ...
stackexchange_codegolf
Introduction Recently I was trying out one of the more obscure use-cases of a modern smartphone: Calling someone by number. While typing it in, I noticed that some of my phonebook entries were displayed, even though the number I was trying to call was different! After some experiments, I figured out why. What it does ...
stackexchange_codegolf
In Keep Talking and Nobody Explodes, players are tasked with defusing bombs based on information from their "experts" (other people with a manual). Each bomb is made up of modules, one of which can be passwords, where the expert is given this list of possible passwords, all five letters long: about after again b...
stackexchange_codegolf
Because we can't get enough of esoteric language golfs, can we? ///—pronounced slashes—is a fun little language based on the s/// regex-replacement function of Perl fame. It contains only two special characters, slash / and backslash \. You can find a full article on it at the esolangs wiki, but I will reproduce a desc...
stackexchange_codegolf
This challenge is inspired by @LuisMendo's MATL answer to my "binary multiples" challenge. Task Pick a code-golf challenge that is open and that has been posted before this one; let me call it the "linked challenge". The linked challenge must be a challenge whose task involves producing output. Write the shortest code ...
stackexchange_codegolf
Develop a program to check if a given word is part of a language defined by the following rules: The language has a set of rules. The empty string is considered a valid word in the language. Two words from the language can be concatenated to create a new word in the language. If X is a word in the language, then "A" +...
stackexchange_codegolf
You're a professional hacker and your boss has just ordered you to help a candidate win an upcoming election. Your task is to alter the voting machines data to boost the candidate's results. Voting machines store voting results as two integers : the number of votes for your candidate (v1) and the number of votes for th...
stackexchange_codegolf
Your task is to given two integer numbers, a and b calculate the modular multiplicative inverse of a modulo b, if it exists. The modular inverse of a modulo b is a number c such that ac ≡ 1 (mod b). This number is unique modulo b for any pair of a and b. It exists only if the greatest common divisor of a and b is 1. Th...
stackexchange_codegolf
Introduction On March 24th, 2015 @isaacg golfed his Pyth answer from 44 to 42 bytes. Since a crossed out 44 (44) looks a lot like a regular 44, @Optimizer made the following comment: striked out 44 is still normal 44 :( After that, on October 21st, 2015, @Doorknob♦ golfed his Ruby answer from 44 to 40 (and later 38) ...
stackexchange_codegolf
Curry is the Language of the Month this month and some users are starting to get into it, so let's get some tips together. Haskell and Curry are similar in a lot of ways and a lot of tips for Haskell work well in Curry and vice versa. So I'd like in this question to gather tips for code-golf in Curry, that would be use...
stackexchange_codegolf
Write a program to print or return one of these strings verbatim: abcdefghijkmnopqrstuvwxyz ABCDEFGHIJKMNOPQRSTUVWXYZ Notice that there is no L.
stackexchange_codegolf
Given a linear equation mx+n, return n and m. However, the equation may be in any of the following formats: 5x+2 -> 5 2 5x-2 -> 5 -2 5x -> 5 0 -2 -> 0 -2 x -> 1 0 Here are the formats, where each ? stands for a positive integer written without leading zeroes ?x+? ?x-? -?x+? -?x-? x+? x-? ? -? ?x -?x x All of t...
stackexchange_codegolf
Traditionally when you compare two strings you use lexicographical comparison. That can be described by the recursive algorithm: $$ f(x, y)= \left\{\begin{array}[rr] \\ \mathrm{EQ} & \mathrm{if}\,\mid x\mid=0\,\mathrm{and}\,\mid y\mid=0 \\ \mathrm{GT} & \mathrm{if}\,\mid x\mid>0\,\mathrm{and}\,\mid y\mid=0 \\ \mathrm{L...
stackexchange_codegolf
Your task is to take an ASCII art image and output it rotated clockwise by 45 degrees and scaled by a factor of \$\sqrt 2\$. The scaling comes from using a lattice pattern which introduces space between the characters. To explain it visually, a \$3 \times 3\$ block would be processed like so: 123 456 789 becomes 1 ...
stackexchange_codegolf
Your task, if you wish to accept it, is to write a program that outputs a positive integer (higher than 0). If the source code is duplicated the output must remain the same. The tricky part is that if the source code is typed three times (triplicated?) the output will be multiplied by 3. Rules You must build a full pr...
stackexchange_codegolf
Background A Hamiltonian path is a path on a graph that steps through its vertices exactly once. On a grid, this means stepping through every cell exactly once. On a square grid, a Chess King can move to a horizontally, vertically, or diagonally adjacent cell in one step. Challenge Count the number of Hamiltonian paths...
stackexchange_codegolf
The Premise: You are writing a C driver for a screen for use on an embedded system. The screen uses a tortured version of SPI that requires data to be sent LSb (least-significant-bit) first, but MSB (most-significant-byte) first. A fast way to do this (if you have the memory) is to use the integer value of each byte to...
stackexchange_codegolf
This is a Cops and Robbers challenge. This is the robber's thread. The cop's thread is here. The cops will pick any sequence from the OEIS, and write a program p that prints the first integer from that sequence. They will also find some string s. If you insert s somewhere into p, this program must print the second inte...
stackexchange_codegolf
Your task is to create a program that outputs the string: Hello, Toroidal Earth! with an optional trailing newline. Additionally if I remove the first line1 of your program and add it as a line after the end of your program the new program should be a valid solution to this challenge in the same programming language. ...
stackexchange_codegolf
If I want to type the string aaa, the least keystrokes I can type it in is 3: a a a. But if I want to type the string aaaaaa, I can do it in 5: a a a ctrl-c ctrl-v, where the ctrl-c refers to copying aaa and the ctrl-v refers to pasting it. Specifically, starting with an empty "buffer" and an empty "clipboard": The ke...
stackexchange_codegolf
Introduction Compute is a esoteric joke language. From the esolangs entry: Compute has no required syntax and has the power to solve any and all problems. It is smart enough to interpret any human language (English, Spanish, Latin, etc), any programming language (C++, Java, brainfuck, etc), or any kind of data you can...
stackexchange_codegolf
There is a challenge Let's play tennis by Daniel. He proposes to place a court in the North-South direction. My proposal is to create a court to play tennis in the East-West direction too. You have to print a tennis court, but you have to do it in the fewest bytes possible because of confidential reasons. Tennis court...
stackexchange_codegolf
Challenge Given a string and a number, divide the string into that many equal-sized parts. For example, if the number is 3, you should divide the string into 3 pieces no matter how long the string is. If the length of the string does not divide evenly into the number provided, you should round down the size of each pie...
stackexchange_codegolf
Input 4 integers w, x, y, z from the range -999 to 999 inclusive where none of the values is 0. Output 4 integers a, b, c, d so that aw + bx + cy + dz == 0 where none of the values is 0. Restrictions Your output should be the solution with the smallest sum of absolute values possible. That is the smallest value of \$|...
stackexchange_codegolf
Given the following input: An integer n where n > 0. A string s where s is not empty and s~=[0-9A-Z]+ (alpha-numeric capitals only). Using a standard, simplified QWERTY keyboard (as shown below): 1234567890 QWERTYUIOP ASDFGHJKL ZXCVBNM Perform the following operation: Find the original row that each character is in...
stackexchange_codegolf
Write the shortest program that generates guitar tabs for the chords given as input. So that the guitarists among you don't have an advantage, and to make it deterministic (and probably easier to code), here are the only forms of the chords authorized: Major chords: E F F# G G# A A# B C C# D D# e 0...
stackexchange_codegolf
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Santa and the Elves are secretly preparing for a new tourist train service, called "North Pole Railroads". The train will travel through various sightseeing spots near the North Pole. As a part of this project, they want to know how ma...
stackexchange_codegolf
In long multiplication, after multiplying the numbers, you are left with the partial products, in this challenge you will output those partial products. Because long multiplication is long, to compensate your code will need to be as short as possible. Examples 34, 53 102, 1700 48, 38 384, 1440 361, 674 1444, 25270, ...
stackexchange_codegolf
You are given two regexes and your task is to determine if the strings matched by the first regex are a subset of the strings matched by the second regex. For this we are going to use a limited mathematical definition of a regex. A regex is defined recursively as one of: ε - This matches only the string "" 0 - This ma...
stackexchange_codegolf
If you remember back to your schooling years, you might remember learning about Truth Tables. They seemed boring, but they are basis for logic and (some would argue) all computing... Problem Your mission, should you choose to accept it is to write a program, function, or widget of code that can output a truth table gi...
stackexchange_codegolf
Forget BIDMAS! Write a program that takes an equation and an operator precedence order, and prints the result. Example input format: 1.2+3.4*5.6/7.8-9.0 */+- Rules & guidelines: The only operators that are defined are addition (+), subtraction (-), multiplication (*), and division (/). No parentheses, no exponentiati...
stackexchange_codegolf
Introduction Unlike English, German is considered to have quite a phonemic writing system. That means that the correspondence between spelling and pronunciation is close. Given any word you aren't familiar with, you would still know how to pronounce it because of the spelling system. This means a computer should be abl...
stackexchange_codegolf
This quite literally came to me in a dream. A common combination padlock design has letters on the dials so you can set the combination to a word. Unfortunately, I can't read, but I can count. Considering I am in a hurry, send the shortest path around the dials to open the 4 letter lock, given the current letters and t...
stackexchange_codegolf
Given a number n, Output an ordered list of 1-based indices falling on either of the diagonals of an n*n square matrix. Example: For an input of 3: The square shall be: 1 2 3 4 5 6 7 8 9 Now we select all the indices represented by \, / or X (# or non-diagonal positions are rejected) \ # / # X # / # \ The output sha...
stackexchange_codegolf
A reflexicon is a self-descriptive word list that describes its own letter counts. Take for example the one found by Ed Miller in 1985 in English: Sixteen e’s, six f’s, one g, three h’s, nine i’s, nine n’s, five o’s, five r’s, sixteen s’s, five t’s, three u’s, four v’s, one w, four x’s This reflexicon contains exactl...
stackexchange_codegolf
Given an expression matching the regex /^[-~]*x$/, evaluate it in terms of x and output a string matching the regex /^-?x[+-]\d+$/. For example, the string -~x evaluates to x+1, while the string -~-x evaluates to -x+1, and the string -~-~--x evaluates to x+2. We start from x and evaluate the string right to left. - neg...
stackexchange_codegolf
Break two numbers up into their factorials; if they share any, return a falsey value. Otherwise, return a truthy value. (inspired by this recent question) In other words, write each input number as the sum of factorials (of positive integers) in the greediest possible way; return a truthy value if no factorial appears ...
stackexchange_codegolf
UTF-8 is a relatively simple way to encode Unicode codepoints in a variable-width format such that it doesn't easily confuse code that isn't Unicode aware. UTF-8 overview Bytes in the range of 1-0x7F, inclusive, are normally valid Bytes with the bit pattern 10XX XXXX are considered continuation bytes, with the six lea...
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
Who are they? Primus-Orderus Primes (POP) are primes which contain their order in the sequence of primes. So the nth prime, in order to be POP, must contain all the digits of n in a certain way which I'll explain. Examples Let's get things clearer: All digits of n must appear among the digits of POP in the same order t...
stackexchange_codegolf
Given two strings \$A\$ and \$B\$ with edit (Levenshtein) distance \$x\$, find a third string with edit distance \$a\$ to \$A\$ and edit distance \$b\$ to \$B\$ so that \$a+b=x\$ and \$a=int(x/2)\$ (that is half of \$x\$ rounded down to the nearest integer). The input is the two strings \$A\$ and \$B\$ and their edit d...
stackexchange_codegolf
Given as input a positive nonzero integer n >= 10 and a sequence of digits 0-9 (which may be taken as a string or a list), find the first contiguous subsequence of digits in the sequence that sums to n and output the start and end indexes. You may use zero- or one-based indexing. If no such subsequence exists, your pro...
stackexchange_codegolf
This challenge is a harder version of this one. A variable number of trits is an array of 0 or more trits (a trit is a ternary digit). So [0, 2, 2, 1] is a variable number of trits, but so is []. Write a function or program that, given an non-negative integer returns a variable number of trits such that every integer h...
stackexchange_codegolf
The Background Imagine the English alphabet written out in a row in capital letters -- ABCDEFGHIJKLMNOPQRSTUVWXYZ. Suppose we have a special variable-width lens such that, when placed over the row, it shows a certain "window" of the alphabet, with letters outside the lens hidden from view. Additionally, this lens has a...
stackexchange_codegolf
Input A binary string \$s\$ of length \$n\$ and a positive integer \$k \leq n\$. Output The number of binary strings with Levenshtein distance exactly \$k\$ from the string \$s\$. Example outputs Each example gives the largest possible output for the given \$(n, k)\$ pair. k=1, s=1010, output=14 k=2, s=1010, outupt=55...
stackexchange_codegolf
In a challenge of CodingGame, there is a challenge that ask you to decode a string composed by reversed words ('Hello world' > 'olleH dlrow') then each characters converted into ascii value separeted by space: >>> decode('111 108 108 101 72 32 100 108 114 111 119 32 41 58') Hello world :) The challenge is to be the fa...
stackexchange_codegolf
Create A "Hello, World!" program but without any vowels. Winner is the program with the least bytes. Rules: No vowels are allowed in the code. Must print to STDOUT Must be a full program. Submissions are measured in Bytes Any language goes as long as there aren't any vowels Edit: Y is only a vowel if there aren't any...
stackexchange_codegolf
Expand a number Your task is to expand an integer greater than 0 in the following manner: Split the number into decimal digits and for each digit generate a list according to these rules: if the digit is odd, the list starts with the digit and goes down to 1; if the digit is even, the list starts with the digit and go...
stackexchange_codegolf
Given a string which is guaranteed to be either odd, even, square, cube, prime or composite, your program or function must return an integer \$100\le N\le 999\$ which meets this description. Rules Your code must be deterministic. The choice of the integers is up to you. However, the six answers must be distinct. (For ...
stackexchange_codegolf
I recently learned from a comment by MathOverflow user pregunton that it is possible to enumerate all rational numbers using iterated maps of the form \$f(x) = x+1\$ or \$\displaystyle g(x) = -\frac 1x\$, starting from \$0\$. For example, $$0 \overset{f}{\mapsto} 1 \overset{f}{\mapsto} 2 \overset{g}{\mapsto} -\frac12 \...
stackexchange_codegolf