instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Write a program or function (hereafter "function") that returns or prints the source code of four new functions: Increment, decrement, undo, and peek. The initial function contains an internal integer value of 0. Each of the returned functions contains a value based on that value, and each behaves differently: Increme...
stackexchange_codegolf
Given a matrix of integers \$M\$ and a list of four integers \$L\$, find the sub-matrix \$N\$ whose corners are given by \$L\$ and return the sum of its elements. Suppose you're given the list \$L = [-8, -3, 2, 9]\$ and the following matrix \$M\$. The numbers in the list are highlighted in blue to illustrate: $$ \begi...
stackexchange_codegolf
Modern mathematics has been formalised using set theory by various systems of axioms. Zermelo Frankel set theory with the axiom of choice (ZFC) forms an intuitive set of axioms and is hence most popular, though stronger choices exist. Inspiration: A Relatively Small Turing Machine Whose Behavior Is Independent of Set T...
stackexchange_codegolf
I can't believe we don't have this already.. It's one of the most important data-structures in programming, yet still simple enough to implement it in a code-golf: Challenge Your task is to implement a stack that allows pushing and popping numbers, to test your implementation and keep I/O simple we'll use the following...
stackexchange_codegolf
The challenge is to golf a program that checks if a statement of propositional calculus/logic is a logical tautology (i.e. it is true for all possible values of the variables). Input Input formulas will use P, P', P'' ect. as variables. They can either be true or false. (P and P') means both P and P' are true. (P or P'...
stackexchange_codegolf
This challenge is inspired by this app. This is a much easier version of this challenge. This challenge is code-golf, while the other one is fastest-code. You'll be given a square input grid, of dimensions 6-by-6 which is divided into 6 areas, where the cells of each area have a unique identifier (I'll use lower case...
stackexchange_codegolf
Your task make a bot that plays Atomas, with the highest score. How the game works: The gameboard starts with a ring of 6 "atoms", with numbers ranging from 1 to 3. You can "play" an atom between two atoms, or on another atom, depending on the atom itself. You can either have a normal atom, or a special atom. The norma...
stackexchange_codegolf
Inspired by what I'm doing at work right now. Your program should take one parameter, the path to the file It should convert all the windows style newlines (\r\n) to unix style (\n) and write the result back to the file
stackexchange_codegolf
Inspired by this challenge (or, more specifically, by misreading it), I've come up with the following challenge: Given an input string S, reverse the order of all uppercase characters, and all lowercase characters. Leave all non-letter characters in place. For instance: Note that the uppercase W (the first uppercase l...
stackexchange_codegolf
Stevin's Notation is a way to represent decimals in a non-fractional way. The Flemish mathematician and engineer Simon Stevin is remembered for his study of decimal fractions. Although he was not the first to use decimal fractions (they are found in the work of the tenth-century Islamic mathematician al-Uqlidisi), it ...
stackexchange_codegolf
Task Your task is to produce string that contains average characters of string. First character of result would be average character of first character (which is first character) and second character average of two first characters and so on. What is average character? Strings are arrays of bytes. Average character of ...
stackexchange_codegolf
For the purposes of this question, the prime factorial of a number n is the result of multiplying all prime numbers smaller than n, and then multiplying the result by n. Your Task: Write a program or function to find the prime factorial of a number, as outlined above. Input: An integer n where n is greater than one...
stackexchange_codegolf
Take an arbitrarily sized string as input. This string represents a baseball plate appearance, in which each character represents a pitch as follows: Strike: S Ball: B Foul ball: F Hit by pitch: H Ball in play: X (For those wondering, this is a very very simplified version of Retrosheet's notation) Your program must...
stackexchange_codegolf
Task Write a program that will output another distinct program, and so on, while using as few distinct characters (and as few bytes) as possible. For example, program 1 should output program 2, and when program 2 is executed, it should output program 3. This can be nested as deeply as needed, but must be at least 3 dis...
stackexchange_codegolf
Given a level from a simple platform game, your task is to make a program or function to determine if a level is winnable. Platform game levels are 4 characters tall and any number of characters wide. There is exactly one platform for each horizontal space in a level: ======= = == = = ...
stackexchange_codegolf
This is a simple one: create the shortest browser script to change every appearance of force on a web page into horse. This script needs to be able to be pasted into the console and work on most modern browsers. You must replace all occurences of the word force and conjugates of the word force (forcing, forced, reinfor...
stackexchange_codegolf
Let's play some code-golf! The challenge is to find the winner of a game of Tic-Tac-Toe. This has been done many times by giving a board that has one clear winner but here is the twist: The cells are numbered like this: 1|2|3 -+-+- 4|5|6 -+-+- 7|8|9 You get an array of exactly 9 moves like that: {3, 5, 6, 7, 9, 8, 1, ...
stackexchange_codegolf
Goal: A tree can be represented as a nested list: the list elements represent nodes, and a node is a pair of the node name and node children. Your program takes as input a nested list of pairs, and should output a pretty tree. Examples: Here are four example test cases below ["stump",[]] ["trunk",[["branch",[["leaf...
stackexchange_codegolf
An airlines company has several planes of the same type.Each plane has a seating capacity of 24 X 3 rows and 8 seats in each row split has shown. 1 [a] [b] [c] [d] [e] [f] [g] [h] 2 [a] [b] [c] [d] [e] [f] [g] [h] 3 [a] [b] [c] [d] [e] [f] [g] [h] If 4 people book-allocate 4 seats in middle row.Else 2 on the right ...
stackexchange_codegolf
Let's assume that $$ f(x) = \frac{Ax+B}{Cx+D} $$ Where, \$x\$ is a variable and \$A\$,\$B\$,\$C\$,\$D\$ are constants. Now we have to find out the inverse function of \$f(x)\$, mathematically \$f^{-1}(x)\$, To do this first we assume, $$ y = f(x) \\\rightarrow y=\frac{Ax+B}{Cx+D} \\\rightarrow Cxy+Dy=Ax+B \\\rightarrow...
stackexchange_codegolf
Creating a golfing language can be hard. Let's help budding golfing language creators out and provide some helpful tips on how to create one. I'm looking for tips on: The design process Implementation Community engagement One tip per answer would be appreciated, and tips like "don't create a new language, use an exis...
stackexchange_codegolf
If you visit Code Golf often, you may have heard of Kolmogorov complexity. It's usually defined as the amount of bytes required to express some string in a programming language. Here the Kolmogorov-complexity of a natural number is defined similarly: the number of bytes required to represent it in a programming languag...
stackexchange_codegolf
tinylisp is, in its essence, a very stripped-down version of Lisp, as the name suggests. It was made by @DLosc for an "interpret this language" challenge, which can be found here. It features a small amount of builtins, which can be used to create practically anything. There is a repository for the "official" tinylisp ...
stackexchange_codegolf
Challenge You must create a simple model of how disease spreads around a group of people. Rules and Requirements The model must be a 1000 by 1000 2D array with each element being a different person. The user must input three variables using argv: the probability of transmission (how likely someone is going to infect so...
stackexchange_codegolf
This challenge is based on, and contains test cases from, a programming course I took at Aalto University. The material is used with permission. Two and a half years ago there was a challenge about spoonerisms in English. However, in Finnish spoonerisms are much more complicated. Spoonerisms in Finnish In Finnish, the ...
stackexchange_codegolf
Given a width and a block of text containing possible hyphen- ation points, format it fully- justified (in monospace). Fully justified means it is aligned on the left and the right, and is achieved by increasing the spacing between words until each line fits. Related: Justify a text by adding spaces Align the t...
stackexchange_codegolf
Write a program that outputs its source code in reverse when run, and outputs its source forwards when I reverse the source. If your program is "abcd", when run with no arguments it should output "dcba", and when I run the program "dcba" it should output "abcd." This is a quine challenge, so both your forwards and reve...
stackexchange_codegolf
The Challenge Given two strings containing only lowercase letters and no spaces, the result should be the shorter string, followed by an underscore, followed by the longer string with the first instance of a character removed for each character it contains that is in the shorter string. You can assume the strings will...
stackexchange_codegolf
The challenge involve simply toggling a string within another string. Explanation If the toggle string is a substring of the main string, remove all instances of the toggle string from the main string; otherwise, append the toggle string at the end of the main string. Rules All string are composed of printable ASCII...
stackexchange_codegolf
Background This challenge is about Convolutional neural networks, and its two main building blocks, namely Convolutional layer and Pooling layer. For simplicity, we ignore the "depth" of the images and intermediate tensors, and just look at the width and height. Convolutional layer A convolutional layer works like a ke...
stackexchange_codegolf
Inspired by this conversation in chat. Your goal in this challenge is to emulate a ninja and count how many deaths he has left. Specs You ninja starts out with 9 deaths left. He also gets an integral starting health as an input. Then, he takes as input a list of events in his life that alter his health. These can be ne...
stackexchange_codegolf
I got to wondering yesterday if I could write a program to comb through a given word search and output the answers. It was actually surprisingly easy. Now I wonder just how small we can get. Rules Your first input is a string or collection of n lines, each of which is n characters long Your second input is a list of ...
stackexchange_codegolf
Golf Golf! This is my first challenge, so please be gentle! The challenge is to write a program that will output the correct score for a layout in the card game "Golf." The card game Golf has many variations. The house rules I use follow the standard rules for Six-Card Golf given by Pagat, with one slight difference. T...
stackexchange_codegolf
Your task is to print the titles of the questions with the five highest scores (upvotes minus downvotes) here on CodeGolf.SE, while skipping over any closed, locked and on-hold questions. Currently these are: Produce the number 2014 without any numbers in your source code Showcase your language one vote at a time Ameri...
stackexchange_codegolf
Task Continuously print a random character (a-z, A-Z, 0-9) not separated by a newline (\n). Expected output b7gFDRtgFc67h90h8H76f5dD55f7GJ6GRT86hG7TH6T7302f2f4 ... Note: output should be randomised. Requirements/Rules Output must be continuous (i.e. never ending), Output may not comprise of newlines, Output must b...
stackexchange_codegolf
Your task will be to take a balanced-string and a integer representing a Levenshtein distance (the number of characters that have to be inserted, deleted or changed to make one string into another) and you must find the number of balanced strings with that distance from the original string (i.e. the neighborhood of tha...
stackexchange_codegolf
Challenge You've given a map to a friend that looks a bit like this: | / | / | \ | \ D A simple map that starts at the top and ends at the bottom. Sadly, your friend doesn't get it. Can you decode the map so that he can read it? Input The input is a string of characters co...
stackexchange_codegolf
You know those letterboards outside old-style cinemas which show upcoming films - perhaps you have a miniature one in your home? If you've operated one, you'll know that you can normally add letters from either side of a row. But the slots (in which you slide letters) are thin, so it's impossible to swap the order of ...
stackexchange_codegolf
A bracelet consists of a number, \$\mathit{N}\$, of beads connected in a loop. Each bead may be any of \$\mathit{C}\$ colours. Bracelets are invariant under rotation (shifting beads around the loop) and reflection (turning the bracelet over). Here are all \$11\$ bracelets with exactly two beads of each of three differe...
stackexchange_codegolf
Edit: I will be posting a newer version of this question on meta-golf soon. Stay tooned! Edit #2: I will no longer be updating the challenge, but will leave it open. The meta-golf version is available here: https://codegolf.stackexchange.com/questions/106509/obfuscated-number-golf Background: Most numbers can be writte...
stackexchange_codegolf
Hold up..... this isn't trolling. Background These days on YouTube, comment sections are littered with such patterns: S St Str Stri Strin String Strin Stri Str St S where String is a mere placeholder and refers to any combination of characters. These patterns are usually accompanied by a It took me a lot of time to m...
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
After all assignments are submitted, a dictionary is created that maps student number to the hash of their file. This dictionary, or hashmap, or mapping (whatever your language calls it) will look as follows: {100: "aabb", 104: "43a", 52: "00ab", 430: "aabb", 332: "43a"} The key is the student number, and the value is ...
stackexchange_codegolf
Backstory [which is not true] A piano is set up like this: However, on my piano, all of the black keys are broken! I still want to be able to play some chords on my broken piano though. In music, a chord is a group of notes that are played together. To allow for input of chords, I will first define what a semitone is....
stackexchange_codegolf
Given a rectangular haystack of size at least 2x2 composed of all the same printable ASCII characters, output the location (counting from the top-left) of the needle which is a different character. For example, if the following haystack is input: ##### ###N# ##### ##### The output should be 3,1 when zero-indexed (what...
stackexchange_codegolf
Today, my girlfriend and I started with this year's Advent of Code to improve our Python. So far we only did Day 1 and the first part of Day 2. The latter, I found to be very fun, so, to spice it up a little, and with a tip o' the head to Eric Wastl, here's my attempt at turning it into a Code Golf challenge. Task Your...
stackexchange_codegolf
Introduction: I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post al...
stackexchange_codegolf
Consider this nested array [[1,2,4],[1,2,3],[2,3]] In each subarray in which 1 appears, a 2 appears. You might say that 1's presence is dependent on 2's presence. The converse is not true, as 2 appears in a subarray without 1. Additionally, 3 is dependent on 2, and 4 is dependent on 1 and 2. Task Given a list of lists ...
stackexchange_codegolf
Center The Text! In this challenge you will be centering various lines. Examples Foo barbaz Foo barbaz Hello World Hello World Programming Puzzles & Code Golf Programming Puzzles & Code Golf Specifications Each input line will always have at least one non-whitespace character, you may assume the on...
stackexchange_codegolf
Idea from the doubler challenge, this may be more difficult. The program should output a positive integer or decimal point value higher than 0. If I duplicate the source code, the output should halve the original integer or decimal point value. But the trickier part is: If I duplicate your code any integer value \$n\$ ...
stackexchange_codegolf
Inspired by Expand exponentation. Knuth's up arrow notation is used for big numbers such as Graham's number. If we look deeper, we can see how it makes big numbers. One arrow means exponentiation. e.g. 2↑3 equals 2^3 = 8. Two or more arrows means repeating the instructions of n-1 arrows. e.g. 2↑↑3 equals 2↑2↑2 equals 2...
stackexchange_codegolf
Giuga numbers (A007850) are composite numbers \$n\$ such that, for each prime factor \$p_i\$ of \$n\$, \$p_i \mid \left( \frac n {p_i} -1 \right)\$. That is, that for each prime factor \$p_i\$, you can divide \$n\$ by the factor, decrement it and the result is divisible by \$p_i\$ For example, \$n = 30\$ is a Giuga num...
stackexchange_codegolf
Inspired from Is this site down or is it just me? Challenge You have to print if a website server is online or not, for you. Input The domain name, like codegolf.stackexchange.com Output 1/True if online 0/False if offline Rules Any kind of web access is allowed URL shorteners allowed Except 2 no. Rule, all standa...
stackexchange_codegolf
Challenge Your goal is to write a program that prints another program. That printed program should print another program, and the new program should print another program, until the end. Rules Each program must less than 256 bytes. (If this needs to be changed, leave a comment) The last program must be an empty progra...
stackexchange_codegolf
Background The monkeys need help organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options. Each tower has three unique upgrade "paths", each having a tier represented by a number between 0 and 5 inclusive, 0 meaning no upgrade. Up to two paths m...
stackexchange_codegolf
You can determine the volume of objects based on a given set of dimensions: The volume of a sphere can be determined using a single number, the radius (r) The volume of a cylinder can be determined using two numbers, the radius (r) and the height (h) The volume of a box can be determined using three numbers, the lengt...
stackexchange_codegolf
Challenge Given an integer n (where 4<=n<=10**6) as input create an ASCII art "prison door"* measuring n-1 characters wide and n characters high, using the symbols from the example below. Example ╔╦╗ ╠╬╣ ╠╬╣ ╚╩╝ The characters used are as follows: ┌───────────────┬─────────┬───────┐ │ Position │ Symbol │ Char ...
stackexchange_codegolf
In Haskell the list notation: [a,b,c] Is just syntactic sugar for: a:b:c:[] And the string notation: "abc" Is just syntactic sugar for: ['a','b','c'] This means that the string: "abc" Is the same as: 'a':'b':'c':[] Task Given a string you should output what the de-syntaxed version would look like in Haskell. Rule...
stackexchange_codegolf
You are the owner of a restaurant. You are opening in a new area in Cartesia where there is only one main road, known as the y-axis. You want to place your restaurant such that you minimize the total distance from your restaurant and each of the houses in that area. Input: The input will be n, the number of houses hous...
stackexchange_codegolf
Part 1 of the task is here Flags Mashup Bot is a small Twitter bot that generates a new country name based on two random country names and tweets the result every couple of minutes. Task Your task is to replicate what the bot does by writing a script or a function based on the following criteria: The input is two cou...
stackexchange_codegolf
The Catalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics. The nth Catalan number is the number of Dyck words (balanced strings of parenthesis or brackets such as [[][]]; formally defined as a string using two characters a and b such that any substring starting from the beginning has...
stackexchange_codegolf
I once saw on the xkcd fora a format for expressing numbers in an odd way. In this "factor tree" format: The empty string is 1. Concatenation represents multiplication. A number n enclosed in parentheses (or any paired characters) represents the nth prime number, with 2 being the first prime number. Note that this ...
stackexchange_codegolf
Write the shortest program that takes a single integer as input and prints out a Suanpan abacus Testcases Input: 314159 Output: |\======================================/| || (__) (__) (__) (__) (__) (__) || || (__) (__) (__) (__) || || || || || || || || || || || || || || ||...
stackexchange_codegolf
Input A single hex 6-digit colour code, capital letter, without #. Can also be a 24-bit integer if you prefer. Output The closest HTML color name (e.g red, or dark-salmon, as defined as https://www.w3schools.com/colors/colors_names.asp or see below). Distance is defined by summing the difference in red, green and blue ...
stackexchange_codegolf
Write a regular expression substitution string which can base64 decode a string using only a regular expression engine built into the language. Eg: # Example in python import re print(re.sub(..., ..., "SGVsbG8gd29ybGQK")) # "Hello world\n" # ^^^ ^^^ # These count towards your byte count, the...
stackexchange_codegolf
All-pairs shortest paths is a standard pathfinding problem. This is a twist on that. Definitions We are searching for paths on a directed graph. Graphs are defined by square matrices, for example 0 3 2.5 1 0 1 0 -1 0 Write M(r,c) = value in M at row r, column c is the cost to travel from node r to node c. The gra...
stackexchange_codegolf
In this challenge, you'll print out the SBCS of Jelly, a popular golfing language. Its code page looks like this: _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F 0_ ¡ ¢ £ ¤ ¥ ¦ © ¬ ® µ ½ ¿ € Æ Ç Ð 1_ Ñ × Ø Œ Þ ß æ ç ð ı ȷ ñ ÷ ø œ þ 2_   ! " # $ % & ' ( ) * + , - . / 3_ 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 4...
stackexchange_codegolf
Your task is to create a plain hunt (a bell ringing pattern) with n bells. An example with 6 bells: 123456 214365 241635 426153 462513 645231 654321 563412 536142 351624 315264 132546 123456 Each number "bounces" off the side of the grid. From Wikipedia: Each bell moves one position at each succeeding change, unless ...
stackexchange_codegolf
The aim of this challenge is to find an impossibly short implementation of the following function p, in the langage of your choosing. Here is C code implementing it (see this TIO link that also prints its outputs) and a wikipedia page containing it. unsigned char pi[] = { 252,238,221,17,207,110,49,22,251,196,250,2...
stackexchange_codegolf
Blokus is a board game in which players take turns placing pieces on a \$ n \times n \$ square grid. In this version of the game, there will be just one person playing. The person is given \$ 21 \$ unique polyominoes, ranging from \$ 1 \$ to \$ 5 \$ tiles each. They then proceed to place down a subset of the pieces ont...
stackexchange_codegolf
Universal Command Sequence Definition An \$n\$-maze is a \$n\times n\$ chessboard which has "walls" on some edges, and a "king" on the board that can move to the 4 adjacent cells, which cannot pass through any walls. Starting from any cell the king should be able to reach every cell on the board. A command sequence is ...
stackexchange_codegolf
Cops' Challenge Robbers' challenge here. It has now been four days since the challenge was posted so all new answers should be marked as non-competing in the title. These answers can still be cracked by robbers but will not go towards their total, and cannot win this challenge. In this cops-and-robbers challenge, you...
stackexchange_codegolf
Definitions An algebraic number is a number that is a zero of a non-zero polynomial with integer coefficients. For example, the square root of 2 is algebraic, because it is a zero of x^2 - 2. The corresponding polynomial is called the minimal polynomial of the algebraic number, provided that the polynomial is irreduci...
stackexchange_codegolf
Create a program that outputs itself. However, if the source code is repeated n times (meaning to concatenate a copy of the source code to the end n-1 times), then there should be 1/n probability outputting the original source code, a 1/n probability of outputting the source code repeated twice, a 1/n probability of o...
stackexchange_codegolf
A drug comes in 5mg, 2.5mg, and 1mg sized pills. The drug is taken once a day. The total daily dose will be only one of the following (all in mg): 1, 2, 3, ... 20, 22.5, 25, 27.5, 30, 32.5, 35, 37.5, 40, 42.5, 45, 47.5, 50 In words: any whole number less or equal to 20, then at 2.5mg increments up to 50. Your task is t...
stackexchange_codegolf
Introduction So the Challenge is to give out all combinations with two Inputs. The length of the string is also optional and you should be able to edit this. I've selected this channel because I thought it would be very easy to do it "normally" but the challenge itself could be very interesting. I had to create that fo...
stackexchange_codegolf
In this challenge, you play chess without seeing any of your opponent's pieces or moves. Or your own pieces. Or whether your own moves succeeded. You send only a stream of moves, with no feedback. If your move is legal (when it is your turn) it will be played, otherwise it is silently discarded. I/O The only input is t...
stackexchange_codegolf
Challenge Given a colour raster image* with the same width and height, output the image transformed under Arnold's cat map. (*details see below) Definition Given the size of the image N we assume that the coordinates of a pixel are given as numbers between 0 and N-1. Arnold's cat map is then defined as follows: A pixe...
stackexchange_codegolf
Definition We say a pair of integers \$(a,b)\$, where \$0<a<b<N\$ and \$N\$ is an integer larger than 4, is an inverse neighbor pair respect to \$N\$ if \$ab\equiv1\text{ }(\text{mod }N)\$ and \$1\le b-a\le\log_2{N}\$. There may be no such pairs respect to some integers \$N\$. To illustrate the definition, consider \$...
stackexchange_codegolf
The Venetian election system was... complicated. The Great Council came together and put in an urn the ballots of all the councilors who were older than 30. The youngest councilor went to St Mark's Square and chose the first boy he met who drew from the urn a ballot for each councillor and only those 30 who got the wo...
stackexchange_codegolf
In the original Shantae game, there are transformation dances that you have to input in time using the D-Pad, A, and B. If you complete a predefined sequence while dancing, you will transform into the corresponding form (or teleport or heal). Your task is to output the corresponding effect when given an input. The catc...
stackexchange_codegolf
What general tips do you have for golfing in Lexurgy? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Lexurgy (e.g. "remove comments" is not an answer). Please post one tip per answer. Lexurgy is a tool created by Graham Hill/def-gthill meant for conlang...
stackexchange_codegolf
The generalised harmonic number of order \$m\$ of \$n\$ is $$H_{n,m} = \sum_{k=1}^n \frac 1 {k^m}$$ For example, the harmonic numbers are \$H_{n,1}\$, and \$H_{\infty,2} = \frac {\pi^2} 6\$. These are related to the Riemann zeta function as $$\zeta(m) = \lim_{n \to \infty} H_{n,m}$$ Given two positive integers \$n > 0\...
stackexchange_codegolf
Inspired by this challenge Given an integer in the range 0 <= n < 2**64, output the minimum sized container it can fit in out of bit: 1 nibble: 4 byte: 8 short: 16 int: 32 long: 64 Testcases: 0 -> 1 1 -> 1 2 -> 4 15 -> 4 16 -> 8 123 -> 8 260 -> 16 131313 -> 32 34359750709 -> 64 This is code-golf, so the shortest ans...
stackexchange_codegolf
Here is the 3rd ABACABA city: _ A|_| B|__| A|_|_ C|___| A|_| B|__| A|_| It is made out of the ABACABA sequence, which is basically: A (1st iteration) place B - AB repeat A - ABA (2nd iteration) Place C - ABAC Repeat ABA - ABACABA (3rd iteration) and you get the idea. The buildings have a height (corresponded by no...
stackexchange_codegolf
Given a positive integer n, output the smallest base b >= 2 where the representation of n in base b with no leading zeroes does not contain a 0. You may assume that b <= 256 for all inputs. Test Cases 1 -> 2 (1) 2 -> 3 (2) 3 -> 2 (11) 4 -> 3 (11) 5 -> 3 (12) 6 -> 4 (12) 7 -> 2 (111) 10 -> 4 (22) 17 -> 3 (122) 20 -> 6 (...
stackexchange_codegolf
Given a directory (such as C:/), given from stdin or read from a file, produce a directory tree, with each file/folder indented based on its depth. Example If I have a C:/ drive which only contains two folders foo and bar, and bar is empty while foo contains baz.txt, then running with input C:/ produces: C:/ bar/ ...
stackexchange_codegolf
Inspired by this Task Your task is to output the average character of your code. What is an average character? Say we have a string golf(). We then take the ASCII value of each separate symbol, so our string is 103 111 108 102 40 41, and calculate the average of those values, rounded to an integer. In our case the aver...
stackexchange_codegolf
Languages, such as C++, have introduced a new comparison operator: <=>. This operator returns -1, 0, or 1† when comparing two items together: −1 means the left-hand side is smaller,  0 when both values are equal, +1 means the right-hand side is smaller. Here is what I have been coming up with in x86-64: 556: 48 8b...
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
One day, I saw the challenge to multiply two strings and I thought I might be able to do one better. That challenge was fake. It was elementwise maximum. It was not real multiplication. So I set out to make something real. Real division between two strings. I quickly realized that this would make an amazing challenge,...
stackexchange_codegolf
Originally posted (and deleted) by @Tlink, which was most likely inspired from this StackOverflow question. Since it was a shame it got deleted, because it seemed like a good challenge in general, I figured I'd repost it with proper formatting and rules. (I've tried contacting @Tlink and get his/her permission to post ...
stackexchange_codegolf
My stovetop has 10 different settings of heat (0 through 9) and a very odd way of cycling through them. When I hit plus (+) it increments the number, unless the number is 9 in which case it becomes 0, or the number is 0 in which case it becomes 9. When I hit minus (-) it decrements the number, unless the number is ze...
stackexchange_codegolf
Your task is to write code that will leak at least one byte of memory in as few bytes as possible. The memory must be leaked not just allocated. Leaked memory is memory that the program allocates but loses the ability to access before it can deallocate the memory properly. For most high level languages this memory ...
stackexchange_codegolf
Objective Given a permutation of 4 distinct items, classify the permutation by the normal subgroup(s) it belongs. Input/Output Format You gotta choose the followings as the hyperparameters for your submission: The 4 distinct items. The permutation serving as the identity permutation. The input format is to accept a...
stackexchange_codegolf
The program should start out with 2 separate files, here named "a" and "b". "a" and "b" should be what I am calling inverse quines: "a", when run, should output "b"'s source code, and "b", when run, should output "a"'s source code, for example: ./a #source code of b, optionally followed by newlines ./b #source code of ...
stackexchange_codegolf
Today I installed MonoGame and ran the test application, which creates a basic colored window. I was surprised to see that the process was using 32.2 MiB of memory, and I thought it could be improved. Your challenge is to write a program that creates a 640 by 480 window displaying only black pixels. Whatever program u...
stackexchange_codegolf
Write a program using only printable ASCII characters that takes no input. For reference, here are the 95 printable ASCII characters in order: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ When your program is run it should print 0 (plus an optional trailing newline) t...
stackexchange_codegolf
I use "suffix" loosely here to mean "any sub-string that follows the prefix". "Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first character of the input text (for the first word). A "prefix" in the middle of a word is ignored. E.g. if your input prefix is "...
stackexchange_codegolf
Inspiration. Inverse. Evaluate a given omnifix expression. Omnifix is like normal mathematics' infix notation, but with additional copies of each symbol surrounding the arguments. The outer symbols take the place of parentheses, and there is therefore no need for additional parentheses. You must support addition, subtr...
stackexchange_codegolf