instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Given a \$n\$-dimensional vector \$v\$ with real entries, find a closest permutation \$p\$ of \$(1,2,...,n)\$ with respect to the \$l_1\$-distance. Details If it is more convenient, you can use permutations of \$(0,1,...,n-1)\$ instead. If there are multiple closest permutations, you can output any one or alternativel...
stackexchange_codegolf
Every integer can be expressed in powers of 2. You know this as the binary system Assume you are given a set of k numbers (0 < k < 2^n). You want to decide for this set whether every integer power of 2 up to 2^(n-1) occurs at least m times One example: n = 7 (2^n = 128, ) k = 5 set = {100, 91, 88, 63, 44} m = 3 Solut...
stackexchange_codegolf
One thing that is constantly frustrating when golfing ARM Thumb-2 code is generating constants. Since Thumb only has 16-bit and 32-bit instructions, it is impossible to encode every immediate 32-bit value into a single instruction. Additionally, since it is a variable length instruction set, some methods of generating ...
stackexchange_codegolf
Your job will be to write a function or a program, that will take an integer n>0 as input and output a list of the edges of the n-dimensional hypercube. In graph theory an edge is defined as a 2-tuple of vertices (or corners, if you prefer), that are connected. Example 1 A 1-dimensional hypercube is a line and features...
stackexchange_codegolf
You are on a plane filled with boxes, and you get a sequence of movements, say "up right right down left": You move up, pushing all boxes in front of you away: You move right, right and down, getting and finally left. This time you only push one box rather than infinite boxes: At the end, there are 4 spaces. Given ...
stackexchange_codegolf
4-state barcodes Many postal services (Royal Mail UK, Canada Post, US Mail, etc) use a 4-state barcode to encode information about their mail. Rendered in ASCII, it may look something like this: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A 4-state barcode is a row ...
stackexchange_codegolf
From Wikipedia: The centroid of a non-self-intersecting closed polygon defined by n vertices (x0,y0), (x1,y1), ..., (xn−1,yn−1) is the point (Cx, Cy), where and where A is the polygon's signed area, In these formulas, the vertices are assumed to be numbered in order of their occurrence along the polygon...
stackexchange_codegolf
The 3Blue1Brown Youtube channel released a video a year ago called "Why do colliding blocks compute pi?" which describes a model where a block A of mass \$a\$ slides into a block B of mass \$b\$, which then pushes block B into a wall, causing it to bounce off the wall and then collide again with block A. The miracle of...
stackexchange_codegolf
I work from Monday to Friday. I start my day at 8:12 and have lunch from 12:00 to 12:42. My workday ends at 16:30. If you are wondering why 8:12 and 12:42: 8:00 is the goal, but I never actually make it 12:42 because I take 45 minute breaks, but this works better for the challenge spec Challenge Write a function o...
stackexchange_codegolf
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text. Your input will consist in a list of list with 3 parameters: X coordinate Y coordinate String How? We know that a Cartesian plane contain 2 axes \$(X, Y)\$ and 4 quadrants where the signs of the \...
stackexchange_codegolf
Introduction Yes, it's as simple as that. Download any file from the internet! Rules You must use your language's API. You must output the file you downloaded to STDOUT, the console, a file, etc. Input should be empty, or the URL you wish to download, but the url must count to byte count.. Good luck!
stackexchange_codegolf
We seem to never get tired of alphabet-related challenges... The recipe Given a string of letters S, and two positive integers M, N, produce an alphabet soup with the letters of S occupying random positions in a rectangular bowl of size M×N, framed by a non-alphabetic, non-space character to represent the rim of the...
stackexchange_codegolf
Given an unsorted list of unique, positive integers, output the shortest list of the longest possible ranges of sequential integers. INPUT An unsorted list of unique, positive integers e.g. 9 13 3 11 8 4 10 15 Input can be taken from any one of the following: stdin command-line arguments function arguments OUTP...
stackexchange_codegolf
Your task is simple: write a program that will replace random pixels in a black 16px * 8px rectangle (width by height) with a white pixel. The holes must be uniformly random, and you should output the 16px by 8 px image with the white pixels inserted. Replace only 1 pixel per column (16 total replaced pixels) You don'...
stackexchange_codegolf
Your task is to generate an emoticon of three characters, the first character being one eye, the second the mouth, and the third another eye. Each eye is a random one of these characters: $'*+-;O^`ox~, and the mouth is a random one of these: ,-._coux. Each eye and the mouth must be on the same general level. These eyes...
stackexchange_codegolf
This time, you are working on a regex. Your regex is meant to approximately full-match the base-10 representations of primes \$0 \le p < 1000\$, while ignoring any non-numeric string or composite in the range. You can full-match 2, 53 or 419, but not 0, 82 or example. The approximately is important -- a minimum of 900 ...
stackexchange_codegolf
Inspired by this video by Matt Parker The distances between the letter keys of a QWERTY keyboard are somewhat standardised. The keys are square and both the horizontal and vertical spacing are 19.05mm (so if there were no gaps between the keys, their side lengths would be 19.05mm), and the three rows of keys are offset...
stackexchange_codegolf
When I was in grade 3, we were taught how to solve a very simple math problem. It was equaling the denominators of two or more fractions. Let's take two proper fractions:- $$ \frac{1}{2},\frac{2}{3} $$ First we will take the Least Common Multiple of the denominators of the two fractions, the LCM of \$2,3\$ are \$6\$. T...
stackexchange_codegolf
The Corpus are a fictional faction from the popular video game Warframe who have a somewhat interesting language. Whilst other factions in the game such as the Grineer have some logic behind their language, the Corpus is simply a lossy substitution of the English language. All Corpus words are the same as their English...
stackexchange_codegolf
Background Sudoku is a number puzzle where, given an \$ n \times n \$ grid divided into boxes of size \$ n \$, each number of \$ 1 \$ to \$ n \$ should appear exactly once in each row, column and box. In the game of Chess, the King can move to any of (at most) 8 adjacent cells in a turn. "Adjacent" here means horizonta...
stackexchange_codegolf
Task Given a string of English names of digits “collapsed” together, like this: zeronineoneoneeighttwoseventhreesixfourtwofive Split the string back into digits: zero nine one one eight two seven three six four two five Rules The input is always a string. It always consists of one or more lowercase English digit nam...
stackexchange_codegolf
Introduction Little Jimmy is going trick or treating. He lives in an odd neighborhood: some houses give out candy, and some give out toothbrushes. Now, Jimmy does not want to get too many toothbrushes. He wants candy! You must help him get some. Challenge Each street in Jimmy's neighborhood has a number. Each house on...
stackexchange_codegolf
The variable star designation is an identifier for a variable star (a star that fluctuates in brightness). It consists of either a 1-2 letter code or (when the letter code is no longer sufficient) a 'V' followed by a number. This code is followed by the genitive of the star constellation the star is found in (eg. "RR C...
stackexchange_codegolf
A huge storm is ravaging the world and as you and your family run away from it, you come across a gigantic shelter run by a girl. She tells you that "she sells sanctuary" and that different types of rooms are offered at different prices. A room may only house one person. The challenge Write a program which takes in two...
stackexchange_codegolf
Ok I've been on a bit of a triangle kick recently so here's another one. Clark's Triangle is a triangle where the leftmost entry of each row is 1 and the rightmost entries are made up of multiples of 6 which increase as the row number increases. Here's a visualization 1 6 1 . 12 1 . . 18 1 . . . 24 1 . ...
stackexchange_codegolf
This challenge is inspired by this app. The test cases are borrowed from that app. This is a fastest-code challenge, where the objective is to solve the largest test cases in the least amount of time. There are provided some smaller test cases, so that people might test their algorithms faster. You'll be given a squa...
stackexchange_codegolf
When I was a kid, there was a "really cool" shortcut to count to 100: 1, 2, miss a few, 99, 100 Output the exact string above, in the fewest characters possible, without using these characters: 0, 1, 2, 9
stackexchange_codegolf
Write a program that prints the RGB color of a given pixel on the screen. The program should read a line from stdin in the format x,y, where x and y are unsigned integers. The pixel (0,0) is the top left pixel in the screen. The program should then output a line to stdout in the format RRR,GGG,BBB, which represents the...
stackexchange_codegolf
Lambda calculus is a system of computation based on single-argument functions; everything in it is such a function. Due to this functional nature, juxtaposition is commonly used to denote function application, grouped from left to right. For example, \$(f g) h=f g h\$ denotes what would conventionally be written \$(f(g...
stackexchange_codegolf
Backstory If you visit the Steward Badge Page, you will see no one has received one of these badges from PPCG yet. However, there are two users: DJMcMayhem & Martin Ender, that are only a few reviews away from this badge! Challenge Your challenge is to write a program or function that when run outputs DJMcMayhem's revi...
stackexchange_codegolf
We haven't had a string question for a while (5 days to be precise), so let's go for one. Given a string s and a positive integer n, take every nth element of s, repeat it n times, and put it back into s. For example, if n = 3 and s = "Hello, World!", every third character is Hl r!. You then repeat each character n tim...
stackexchange_codegolf
You find yourself in a strange place. A frighteningly dark maze, lit only by dim candles resting in the occasional hallway. Numerous paths lie only in impassable darkness, foreboding and-- ...Hm? What? Pick up a candle and carry it with you? No, no, that would be extremely rude. The Task Given a maze as input, output t...
stackexchange_codegolf
Have you ever wondered, when doing shopping, how to pack your products into 2 bags you're carrying so that a total weight would be distributed among them as evenly as possible? Your task is to write a function, that takes a list of positive numbers (lets say integers for simplicity) as an input. It should return two li...
stackexchange_codegolf
Given a positive integer n, do the following (and output every stage): start with a list containing n copies of n. do the following n times: at the ith step, gradually decrement the ith entry of the list until it reaches i So, for example, if the given n is 4, then you start with [4,4,4,4], and then at the first step...
stackexchange_codegolf
This rar file, when decompressed, gives a 65024-byte exe file. Requiring you to output the contents of that file would be absolutely no fun. But you aren't required to do that. Actually, you're to do something opposite: Output a binary of the same length (65024 bytes), such that no byte equals the byte at same position...
stackexchange_codegolf
Your task is to output all possible ways to end a game with a tie (all rows, columns, and diagonals are completely filled and do not have 3 X's or 3 O's, and there are exactly 5 X's and 4 O's in total) in Tic-Tac-Toe (assuming X goes first): OXO XXO XOX OXX XOX OOX XOX XOO XOX XXO OXO OXX XOX XOX OXX XXO O...
stackexchange_codegolf
Inspired by Make a Rectangle from a Triangle. Task There is a famous formula on the sum of first \$n\$ squares: $$ 1^2 + 2^2 + \dots + n^2 = \frac{n(n+1)(2n+1)}{6} $$ It is known that this number is composite for any \$n \ge 3\$. Now, imagine a collection of row tiles (a tile of shape \$1 \times k\$ with the number \$k...
stackexchange_codegolf
You are starting up a cryptocurrency exchange website which supports conversion from USD to two currencies, foo-coin and bar-coin. Write a program that takes the exchange rate for each coin to USD as arguments and outputs the maximum value of USD that cannot be completely divided into the two currencies (assuming these...
stackexchange_codegolf
Definition (from Wikipedia) A Pythagorean triple consists of three positive integers a, b, and c, such that a² + b² = c². The typical example of a Pythagorean triple is (3,4,5): 3² + 4² = 9 + 16 = 25 which is 5² Task: Given an integer number c, write a program or function that returns the list of pythagorean triples wh...
stackexchange_codegolf
The C preprocessor is not turing-complete, but you can do some pretty cool stuff with it. The challenge is to make an integer adder with it. You can use any representation you like: base 2, base 10, unary, separate each digit with a comma, etc. Whatever you do, you may only use the C preprocessor. The rules are simple:...
stackexchange_codegolf
See also: Rotatagons Challenge Given a string as input, output its wordagon. Wordagons A wordagon is a way of representing a string in a hexagon. Now, let's create a wordagon from the string hexa: Firstly, you start with the first character in the string a place it in the centre: h Then, you take the next character in...
stackexchange_codegolf
Challenge: Create a program or function that takes an integer input, which outputs a new program/function as specified below. Input: Integer n: Time in seconds before the Time Bomb explodes. Output: The original program which had the time in seconds n as input, will output a new program/function that does the following...
stackexchange_codegolf
You are given a string of terrain, with molehills and mountains: /\ / \ _/\__ / \ ___/ \_/ \_ ____/\___/ \___ Your job is to replace every molehill in the string with an equivalent mountain centered in the same col...
stackexchange_codegolf
Output all 95 bytes from 0x20 to 0x7E inclusive (printable ASCII including space), in any order, each at least once. The source code of your program must use all of those bytes, each at least once. Your program must be irreducible (meaning you cannot strictly remove some characters from the program and then have it st...
stackexchange_codegolf
Introduction: Pete likes doing word search puzzles. Despite that, he has trouble searching for words vertically, (anti-)diagonally, or reversed. Because of that, he'll always search for the words left-to-right, and rotates the entire puzzle in increments of 45 degrees clockwise. In addition to that, he'll also always s...
stackexchange_codegolf
You have to print out your username, by only using the characters in your username. Standard loopholes are forbidden This is not code-golf, so shortest does not win Don't modify your username please And each language be used one time
stackexchange_codegolf
Introduction There have been a few examples of the smallest possible OCI container that does "X". However these examples never correctly handle termination signals. Challenge Produce the smallest possible container that correctly handles PID 1 signal responsibilities. The container does not need to manage child process...
stackexchange_codegolf
Is it a good chord? Definition of a chord: We define a chord as three notes together. Definition of a note: We define a note as a number between 1 and 7, inclusive. As in music, we define 1 as do, 2 as re, 3 as fa, etc. However, the note names are not important. They will not be included in the question and likely not ...
stackexchange_codegolf
Task Implement a kind of "some users are typing" system, which can be found in Discord and some other chat clients. If 1 user (say, Bubbler) is typing, output Bubbler is typing... If 2 users (say, Bubbler and user) are typing, output Bubbler and user are typing... If 3 or more users are typing (say, Bubbler, randomuse...
stackexchange_codegolf
Given a list of at least two words (made only of lowercase letters), construct and display an ASCII ladder of the words by alternating the direction of writing first to the right, then to the left, relatively to the initial direction from left to right. When you finish writing a word, change the direction and only then...
stackexchange_codegolf
For this challenge you are going to make a function (your function may be a complete program) that takes a list as input and returns a permutation of that list. Your function must obey the following requirements. It must be deterministic. Composing your function with itself a variable number of times should be capabl...
stackexchange_codegolf
Just because the reverse and palindrome were not too challenging individually :) Write a program (full program or function) that satisfies the following: given a string input, the program as-is outputs the input string unchanged. the program reversed outputs the input string reversed. the program palindromized outputs...
stackexchange_codegolf
About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You can find the leaderboard along with some more information about the series in the first post. Although I have a bunch of i...
stackexchange_codegolf
You are given a string, which will contain ordinary a-z characters. (You can assume this will always be the case in any test, and assume that all letters will be lowercase as well). You must determine how many unique combinations can be made of the individual characters in the string, and print that number. However...
stackexchange_codegolf
When writing a programm 1 missing character can ruin everything, wouldn't it be great if the programm told you what was missing ? Task: Create any (non Empty) programm, that takes no input and outputs nothing. That when 1 Character is removed from the programm, outputs that Character. Input: None Output: Output nothing...
stackexchange_codegolf
Challenge Write a program or function that takes a number \$n\$ and returns the smallest \$k\$ such that concatenation \$n'k\$ is a square. This sequence is described by A071176 on the OEIS. I/O Examples input --> output 1 --> 6 (4^2) 10 --> 0 (10^2) 35 --> 344 (188^2) 164 --> 836 (406^2) 284 --> 2596 (168...
stackexchange_codegolf
Problem Assume you have a single 7-segment display without a decimal point, so 7 "lines" that can be labelled A through G as seen here. This display will only show the numbers from 0 to 9 as usual, like so: Any time this display changes from one number to another, some of its lights will have to change their state fr...
stackexchange_codegolf
You are to write a program which outputs a single positive integer \$n\$. The integer may have leading zeros and whitespace, and/or trailing whitespace. Then, choose a positive integer \$m > 1\$. When the program is repeated exactly \$m\$ times, it should output \$m \times n\$ (and only \$m\times n\$). When repeated an...
stackexchange_codegolf
Given an input of a list of slices of a string, output the original string. Each slice will be given as a list of length 2, containing the start position of the slice (an integer ≥0) and the slice itself. If your language does not support arrays of arbitrary types, you may also take this as a struct or similar, or simp...
stackexchange_codegolf
Given an input string and a wrapping string, find the location of the first input string char in the wrapping string and replace it with the wrapping string char 1 step to the right of that, find the second char in the wrapping string and replace it with the char 2 steps to the right, find the third and replace it with...
stackexchange_codegolf
Introduction Your job is to write a function or program that detects if a number a is less than a number b. But... You are not allowed to use built-in alternatives for equals, less than, greater than, less than or equal to, greater than or equal to, or not equal to operators. (Writing your own implementation is allowed...
stackexchange_codegolf
Task You must write a program in Language A that will output the source code for a program in Language B which will then output the source code for a program in Language C and so on and so forth. The final program must output the x root y where x and y are the inputs e.g. in Python: print(int(input()) ** (1/int(input()...
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
Qat is a tool that lets you search for words matching a given pattern, often used by crossword and other word puzzle writers and solvers. In this challenge, you will have to implement a specific part of Qat, namely a subset of the "equation solver". Equations The output of a Qat query depends on the dictionary you use ...
stackexchange_codegolf
Write a program which can encode text to avoid reusing characters, and convert back. Both normal and encoded forms are restricted to a particular character set: the space character with code point 32, the tilde character ~ with code point 126, and all characters between. This is 95 total characters. It's a printable s...
stackexchange_codegolf
This is the Cop post. The Robber post is here. Your task is to take an integer input N and output the Nth digit in the sequence OEIS A002942. The sequence consists of the square numbers written backwards: 1, 4, 9, 61, 52, 63, 94, 46, 18, 1, 121, 441, ... Note that leading zeros are trimmed away (100 becomes 1, not 00...
stackexchange_codegolf
Word changer is a game where you are trying to turn one word into another via single-character edits, with each step being its own word. For this challenge, edits may be replacements, insertions, or deletions. For example, WINNER → LOSER can be done with this route (there may be others): WINNER DINNER DINER DINE LINE L...
stackexchange_codegolf
Write a program or function that takes input and outputs/returns a full program (in the same language) that outputs said input. Note that the input may contain any printable ASCII character or newline (AKA 0x20-0x7f and 0x0a). However, the input will not have trailing whitespace nor preceding whitespace, nor will it be...
stackexchange_codegolf
Steganography hides a given message inside a given carrier, producing a package that does not look suspicious. For this challenge, you will write a program that takes an ASCII message and an ASCII carrier as input, and return or print a package that is identical to the carrier except characters corresponding to the mes...
stackexchange_codegolf
I was just playing the board game Sorry! with some people, and I realized that I could base a few interesting challenges off of it. This one is pretty simple. You task is simply to output an ascii-art version of a sorry board, placing pieces where I tell you to. Specs First, here is an image of an actual Sorry! board f...
stackexchange_codegolf
A Math.SE user have a funny game explained as such: Pick a random positive integer X. Add +1, 0, -1 to make it divisible by 3Keep track of how much you've added and subtracted. That is your "score".. Divide by 3 to create a new X. Repeat steps 2 and 3 until you reach one. I'm expecting the shortest code to give the...
stackexchange_codegolf
Challenge The goal is to output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo. Context. (Maybe another interesting challenge could be printing all of the other examples? This would probably use similar logic but involve either a function or just a for loop.) Rule(s) You cannot output anything other t...
stackexchange_codegolf
Revised formatting and instructions Given a list of moves for a Cracker Barrel peg board game, or as @Steveverrill stated, Peg Triangle Solitaire: Game 1 Game 2 Game 3 1: 0 ,-1, -1 C, -1, -1 4, -1, -1 #starting point 2: 3, 1, 0 3, 7, C B, 7, 4 #jump_from, jump_over, jump_to 3: A, 6...
stackexchange_codegolf
The Challenge I was looking into small code examples for a specific language as a small tutorial and came accross a simplified Blackjack that should be implemented. In this Challenge you will have to implement a full Blackjack game, with 5 Decks. The Game You are playing against a Dealer and he has 5 Decks of Poker pla...
stackexchange_codegolf
Challenge Inspired by this video. As you may know, a palindrome is a word that is spelled the same forward as it is backward. The word "PULP" is not a palindrome, but when translated into Morse Code (with the spacing between letters removed), "PULP" becomes ".--...-.-...--." which is a palindrome. Your task is to write...
stackexchange_codegolf
This challenge is not code golf. Please read the scoring before you attempt to submit an answer. You will be given a multi-line string as input. You should output the size of the largest contiguous chunk of non-space characters. Contiguous just means that the chunk is a single piece rather than multiple disconnect...
stackexchange_codegolf
A composition of an integer \$n\$ is a representation of \$n\$ as a sum of positive integers. For example the eight compositions of 4 are as follows: 4, 3 + 1, 1 + 3, 2 + 2, 2 + 1 + 1, 1 + 2 + 1, 1 + 1 + 2, 1 + 1 + 1 + 1. The challenge is to output the number of compositions of \$n\$ in which the greatest part is odd....
stackexchange_codegolf
As you probably know, a Fibonacci Number is one which is the sum of the previous two numbers in the series. A Fibonacci Digit™ is one which is the sum of the two previous digits. For instance, for the series beginning 1,1, the series would be 1,1,2,3,5,8,13,4,7,11,2... The change occurs after the 13, where, instead of ...
stackexchange_codegolf
Your task is pretty simple, calculate the n-th element of A190810. Elements of A190810 are calculated according to these rules: The first element is 1 The sequence is increasing If x occurs in the sequence, then 2x+1 and 3x-1 also do You can use 1-based or 0-based indexing, but if you use 0-based indexing, please say...
stackexchange_codegolf
I was going through a bizarre thread on Reddit, and came across this: ( ͡°( ͡° ͜ʖ( ͡° ͜ʖ ͡°)ʖ ͡°) ͡°) It's representing a group of people smiling somewhat suspiciously. (In the challenge below though, spaces to the left of the right eyes were dropped somehow while I was writing the challenge. Note the spec). Your goa...
stackexchange_codegolf
Introduction The Boids Algorithm is a relatively simple demonstration of emergent behavior in a group. It has three main rules, as described by its creator, Craig Reynolds: The basic flocking model consists of three simple steering behaviors which describe how an individual boid maneuvers based on the positions and ve...
stackexchange_codegolf
For the purposes of this challenge a substring \$B\$ of some string \$A\$ is string such that it can be obtained by removing some number of characters (possibly zero) from the front and back of \$A\$. For example \$face\$ is a substring of \$defaced\$ \$ de\color{red}{face}d \$ This is also called a contiguous substri...
stackexchange_codegolf
The game shapez.io has a huge variety of shapes you can produce, such as: Each shape has a unique short code, for example the above is CrWbScRu. This means, going clockwise from top right, red circle (Cr), blue wedge (Wb), cyan star (Sc), uncolored rectangle (Ru). There are four different shapes: Rectangle - R Wedge ...
stackexchange_codegolf
In graph theory, a Cactus is a connected graph such that any distinct two simple cycles in the graph share at most one vertex. Here is a Cactus with 3 simple cycles outlined with dashed lines. The following graph is similar to the one pictured above but is not a Cactus because the two vertices labeled in red are share...
stackexchange_codegolf
Overview The cover of a book will be provided in the following ASCII format: ______ | | | | | | | | ------ The input can be in any reasonable format (eg. a list of strings, a nested list of characters, etc.) Inside the "borders" of the cover, other printable ascii characters might appear, which contribute ...
stackexchange_codegolf
Your job is to create the longest period iterating quine, where the length of each program in the sequence is bounded by 500 bytes. That is, if you repeat the following steps: Start with your initial program Run the current program Go back to step 2 You will eventually get back to your original program. The number of...
stackexchange_codegolf
Let n and b be positive integers larger than 1. Output the distance from n to the next power of b. For n=5 and b=3, the next power of 3 from 5 is 9 (3^2 = 9), so the output is 9 - 5 = 4. For n=8 and b=2, the next power of 2 from 8 is 16 (2^4 = 16), so the output is 16 - 8 = 8. Note that n is a power of 2 in this exampl...
stackexchange_codegolf
Your challenge today is to write a program or function which takes a list l and gives the positions in l at which each successive element of l sorted appears. In other words, output the index of the smallest value, followed by the index of the second smallest value, etc. You can assume that the input array will contain...
stackexchange_codegolf
Given a positive integer, determine if it can be represented as a concatenation of two square numbers. Concatenated numbers may not begin with 0 (except for 0). Any leading zeros in input should be ignored. Examples 11 -> true // because 1 and 1 are squares 90 -> true // because 9 and 0 are squares 1001 -> true // ...
stackexchange_codegolf
You have 2 numbers, both stored separate as numeric data type. First number is always 6 digits long. Second number can vary between 1 and 4 digits. If it's less than 4 digits, it needs to be padded with numeric value 0. End result always needs to be 10 digits number. Order has to be respected. n1|n2 Example #1: n1 = 11...
stackexchange_codegolf
For a given number n, output an strictly decreasing array whose sum is n and its lexicographical order is the smallest for any possible outputs Smallest lexicographical order means that for or sum n=9 the following strictly decreasing arrays are possible: [[9],[8,1],[7,2],[6,3],[5,4],[6,2,1],[5,3,1],[4,3,2]]. Putting t...
stackexchange_codegolf
In this challenge you will write code to take a list of positive integers and output all maximal linear sublists. A sublist is is a list which can be created by deleting values from the the input list. Sublists have more structure than just lists. They in a way "remember" which values are deleted. Similarly we say tha...
stackexchange_codegolf
Challenge Forsyth–Edwards Notation (FEN) is a standard notation for describing a particular board position of a chess game. Your challenge is to evaluate the score using the FEN string. This is an example of a FEN string: 5k2/ppp5/4P3/3R3p/6P1/1K2Nr2/PP3P2/8 Using this string, you can calculate the material score for ...
stackexchange_codegolf
This is the second in a series of puzzles that I will be posting every Monday at Midnight PST. The first puzzle is located Here. Context: A reclusive billionaire has created a game show to attract the world's best and brightest programmers. On Mondays at the stroke of midnight, he chooses one person from a pool of app...
stackexchange_codegolf
Related: Cleaning up decimal numbers Background A continued fraction is a way to represent a real number as a sequence of integers in the following sense: $$ x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{\ddots + \cfrac{1}{a_n}}}} = [a_0; a_1,a_2,\cdots,a_n] $$ Finite continued fractions represent rational number...
stackexchange_codegolf
Output the numbers 1-16 (or any other set of 16 distinct items). Then, repeatedly, output a random value chosen uniformly from the last 16 items outputted. After the same item is printed 16 times in a row, halt. If a number appears multiple times in the last 16 values, it should have proportionally more chance to be ch...
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
Given an input string, write a program that outputs the total number of lines and curves it has. The Challenge Take input from STDIN, or any other input method. Output to STDOUT, or any other output method, the total number of lines and curves contained in the string, in that order, based on the below table in the cod...
stackexchange_codegolf
Challenge Given the formula of a chemical, output the Mr of the compound. Equation Each element in the compound is followed by a number that denotes the number of said atom in the compound. If there isn't a number, there is only one of that atom in the compound. Some examples are: Ethanol (C2H6O) would be C2H6O where ...
stackexchange_codegolf
Challenge Write a program that takes as input a text and output "That's me!" if the input is equal to the program own source code, and "That's not me!" otherwise. Notes This is codegolf, in each programming language the shortest program wins. The input can be taken from program arguments or function argument, and the ...
stackexchange_codegolf