instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
You have been chosen to make a program that creates some pretty ASCII bar charts. Here is the input format: [List of words (they can have spaces)] [an integer >= 0] Bar 3 This is so cool 4 IDK-Why 6 The input will have multiple lines in this format, each one representing one bar in the graph. The output format of a gr...
stackexchange_codegolf
This puzzle is based on this Math.SE post. A more complex version of this problem can be found over here. Assume I have some number of black shirts and some number of white shirts, both at least 1. Both colors of shirt have a non-zero durability. All shirts of a given color start with the same durability. Every day, I ...
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
The Dutch system for naming one's ancestors is a lot more interesting than the English version. For English, the sequence goes "parent", "grandparent", "great-grandparent", "great-great-grandparent", "great-great-great-grandparent"; and in Dutch those terms are "ouder", "grootouder", "overgrootouder", "betovergrootoude...
stackexchange_codegolf
Introduction Often, people refer to dates as the "second Friday in August, 2018" or the "fourth Sunday in March, 2012". But it's hard to tell what date that is! Your task to is to write a program that receives a year, a month, a day of the week, and an integer, and output that date. Challenge For input, you will get a...
stackexchange_codegolf
A lot of PPCG users helped with the creation of this challenge, both in chat and the Sandbox, specifically Martin Ender, AdmBorkBork, Emigna and user202729 Our community has found it necessary to create a set of languages designed specifically for golfing, "golfing languages" as we call them. Such languages have evolve...
stackexchange_codegolf
Your task Take a list of strings as the input, and output the maximum average ord. Example Given the list ['hello', 'world', 'bye']: The average ord of 'hello' is: (ord(h) + ord(e) + ord(l) + ord(l) + ord(o)) / len('hello') = 106.4 The average ord of 'world' = 110.4 The average ord of 'bye' = 106.7 The maximum ave...
stackexchange_codegolf
Write a program for a specific language that in different orientations performs different tasks. Your code should have at least two non-empty lines and at least two non-empty columns and should complete at least one challenge from each category of challenges below when oriented in different ways. Orientations Your code...
stackexchange_codegolf
Shikaku is a 2D puzzle. The basic rundown of it is that a rectangular grid has some numbers in it, and you want to partition the grid into rectangular components such that each component contains exactly one number which is the number of grid squares in that component. This challenge involves a 1D simplification of thi...
stackexchange_codegolf
"All roads lead to Rome" is a saying that essentially means there are plenty of different ways of achieving an objective. Task Your task is to write a program that finds a set of link connections from one Wikipedia page to the Wikipedia page about Rome. Notice that it is not enough to find the word Rome with a hyperlin...
stackexchange_codegolf
Given 4096 16-bit integers, only four of which are unique and others appeared twice (so 2050 different integers exist). Find the four uniques. To time precisely and limit RAM usage, your program will be run on a 12MHz 8051(with 128B RAM). I'll test with a random case generated by some code to test, but we aim at the wo...
stackexchange_codegolf
Given \$a\$ and \$b\$, both odd \$n+1\$-bit integers, compute \$a/b\$ to a precision of \$n+1\$ bits in the 2-adic integers. That is, compute \$c\$ such that \$a = bc\, (\mathop{\rm mod} 2^{n+1})\$. \$n\$ should be your language's native integer size, or if native integers are bigints, take it as a parameter. If your l...
stackexchange_codegolf
Here's a very simple little problem that I don't believe has been asked before. Challenge Write a program or a function that takes in four positive integers that represents the lengths of movable but unbreakable and unbendable straight fences. Output the area of the largest rectangular yard that can be fully encompasse...
stackexchange_codegolf
Lets say you saw your friend enter his or her password into their Android phone. You don't remember how they made the pattern but you remember what the pattern looks like. Being the concerned friend that you are you want to know how secure their password is. Your job is to calculate all the ways that a particular pa...
stackexchange_codegolf
Preamble There was a unit test in our codebase which was shuffling a string of length \$52\$ formed from the set of letters \$[A-Z]+[A-Z]\$ and then using the first \$20\$ characters of that shuffled string. It failed quite a while after being written due to no repeated character being present in those twenty and we wo...
stackexchange_codegolf
You are to write a program that does one of the following. Only displays "Hello World" does nothing else Quits and nothing else (no output, no errors.) Takes one line of input, parses it as an integer, displays the first that many primes (or gives a nice error if it is given input that can't be parsed as an integer, o...
stackexchange_codegolf
Whoa, whoa, whoa ... stop typing your program. No, I don't mean "print ABC...." I'm talking the capitals of the United States. Specifically, print all the city/state combinations given in the following list in any order with your choice of delimiters (e.g., Baton Rouge`LA_Indianapolis`IN_... is acceptable), so long as...
stackexchange_codegolf
You are given a string of unknown length that contains a varied amount of (, {, [ and their respective closing parentheses (in this context all referred to as brackets). With one exception, all the brackets are all balanced, meaning an opening one has a corresponding closing one somewhere afterwards in the string. The ...
stackexchange_codegolf
In the physical world, invisible ink usually becomes invisible when it dries, and is then is readable if it is exposed to heat or chemicals of some kind. The invisible ink in this challenge will be readable when exposed to highlighting. Create a full program or function that takes in text from the console (using a prom...
stackexchange_codegolf
It's strange this question hasn't been asked yet, so here it is: Calculate the length of a string given through STDIN Rules As said, your string will be given through STDIN, not via command line arguments Print the length of the string to STDOUT Only ASCII chars will be given, and all printable ASCII chars count! This...
stackexchange_codegolf
Game of Game of Life Conway's Game of Life is a 0-player game. But that's okay! We can make it a multi-player game. This game is played on the smallest square grid that will accommodate a 6x6 square for each player (12x12 for 2-4 players, 18x18 for 5-9 players, etc). This grid is actually a torus, so it wraps in bot...
stackexchange_codegolf
Given a list of integer points in an n-dimensional space, output the geometric median. Note that the output is not necessarily integer. Your answer must be precise to at least two digits after the decimal point. You may assume that n < 16 and that every component of each point fits in a 32-bit signed integer. You may w...
stackexchange_codegolf
Write a program or function that "reacts" to a given integer n (input via function parameter/args/stdin) The program doesn't care about negative numbers, likes even, dislikes odd numbers and fears the number 13. It should output the following: if n<0: -------------------------- | | | ...
stackexchange_codegolf
Intro We have had histograms and counting, but not listing all of them. Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. This is a language agnostic code-golf edition of this year's sixth problem. I have explicit permission to post this challenge here from the original...
stackexchange_codegolf
Slope fields or direction fields, are a graphical representation of the solutions to a first-order differential equation of a scalar function. A slope field shows the slope of a differential equation at certain vertical and horizontal intervals on the cartesian plane, and can be used to determine the approximate tangen...
stackexchange_codegolf
A top-front-side puzzle is a puzzle where you are required to construct a 3-D shape of (usually cubic) blocks given three orthogonal views: a top view, a front view, and a side view. For example, given a top, front, and side view as follows: Top: Front: Side: . . . . . . . . . . . . . x x . . x ...
stackexchange_codegolf
The objective of this question is to create a program that pushes your computer's internal fan speed to its maximum RPM. Upon exiting the program, your fan should return to the normal operating RPM. Rules: You may not perform a CPU intensive task in order to modify the fan's speed. Exiting the program may be via user...
stackexchange_codegolf
This question is a part of the lean LotM. A ring is a type of structure that takes the rules of addition and multiplication we are familiar with and abstracts them, so we can reason about them. To do this we state a number of expected properties as axioms and see what we can say about systems that follow these axioms....
stackexchange_codegolf
Given a non-empty string (or an integer, or a list/array if you prefer) composed exclusively of digits in the range [1-9], your task is to write a function (or a whole program) that applies a "Match-3 type of rule" from left to right and outputs the resulting string, like this : [parameter] "12223" -> [returned value] ...
stackexchange_codegolf
The primorial \$p_n\#\$ is the product of the first \$n\$ primes. The sequence begins \$2, 6, 30, 210, 2310\$. A Fortunate number, \$F_n\$, is the smallest integer \$m > 1\$ such that \$p_n\# + m\$ is prime. For example \$F_7 = 19\$ as: $$p_7\# = 2\times3\times5\times7\times11\times13\times17 = 510510$$ Adding each num...
stackexchange_codegolf
Say I have a pile of boxes: AAA BBB I can create it in two steps: BBB ↓ (empty) --- AAA ↓ BBB But with this: AB BA I need three steps: A ↓ (empty pile) --- BB ↓ A --- A ↓ B BA Your challenge Given a pile of boxes, output the minimum number of steps needed to create that pile. A step consists of dropping a ro...
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
Challenge Premise Bob is a novice pianist who can only play sequences of single notes. In addition, he does quite an interesting thing: for every note after the first, if it's higher than the previous note was, he uses the finger directly to the right of the previous finger used; if lower, to the left; if the same pitc...
stackexchange_codegolf
Test Driver • Challenge Discussion • Submit Adventurer (Image Source) Several rival adventurers are raiding the ruins for treasure, but they can only carry so much at a time and have their limits of endurance. They want to get the most valuable treasure and get out before they become too tired to continue. They are tr...
stackexchange_codegolf
Challenge For any two non-empty strings A and B, we define the following sequence : F(0) = A F(1) = B F(n) = F(n-1) + F(n-2) Where + denotates the standard string concatenation. The sequence for strings "A" and "B" starts with the following terms: A, B, BA, BAB, BABBA, ... Create a function or program that, when given...
stackexchange_codegolf
/o\ Jimmy has been receiving a lot of attention on this site recently and it has caused Jimmy to get a little stressed. The bodybuilder Jimmys /-o-\ started bad mouthing the OG / acrobat /o\ Jimmys saying they are way cooler because they are bigger. But of course the acrobat Jimmys thinks they are way cooler since afte...
stackexchange_codegolf
The other day, my son asked me to build him a staircase using Lego-ish blocks. And I came up with something like this: Then my kid asked me for a program using the least number of bytes that generated a similar staircase in a computer screen. I am not that good at code-golf, so I need your help. I need a program that:...
stackexchange_codegolf
From the Wikipedia article: Location arithmetic (Latin arithmeticæ localis) is the additive (non-positional) binary numeral systems, which John Napier explored as a computation technique in his treatise Rabdology (1617), both symbolically and on a chessboard-like grid. What? Location numerals is a way of writing numb...
stackexchange_codegolf
Challenge Given a positive-length string \$S\$, a divisor of \$S\$ is another (not necessarily distinct) string for which there exists a number \$a\$ such that when we repeat the divisor \$a\$ times, we get the string \$S\$. For example, the string abcd is a divisor of the string abcdabcd with \$a=2\$. Your challenge i...
stackexchange_codegolf
Intro In J. R. R. Tolkien's Lord of the Rings, this phrase is on the cover of each book. Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone, Nine for Mortal Men doomed to die, One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. One Ring to...
stackexchange_codegolf
Overview In this challenge, you will be given two numbers which are both a small offset larger than a multiple of a medium-size number. You must output a medium-sized number that is almost a divisor of both of the numbers, except for a small offset. The size of the numbers involved will be parameterized by a difficulty...
stackexchange_codegolf
Task As input you have: a positive integer N And you should output: The number of integers in \$[1,N]\$ (an inclusive range) which end with the digit \$2\$ in base ten. Test cases 1 -> 0 2 -> 1 5 -> 1 10 -> 1 12 -> 2 20 -> 2 30 -> 3 54 -> 6 97 -> 10 100 -> 10 Rules It is a code-golf so the lowest score in bytes wi...
stackexchange_codegolf
This tweet lists the possible orders for Wings of a Chinese restaurant1: When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However minimizing the price of an order at this restaurant isn't such a simple task, so I'd like to be prepared for my next orde...
stackexchange_codegolf
I'm hungry. Let's microwave something. Given a numerical input of between 1 and 4 digits, output the number of seconds that the microwave should run. Details The trick is figuring out if the user is inputting seconds or a combination of seconds and minutes. The ones and the tens places should be interpreted as seconds ...
stackexchange_codegolf
Challenge Given the phase of the moon, draw it using ASCII art. Your program must handle new moon, waxing crescent, first quarter, waxing gibbous, full moon, waning gibbous, last quarter, and waning crescent. Your input will be an integer. 0 -> new moon 1 -> waxing crescent 2 -> first quarter 3 -> waxing gibbous 4 -> f...
stackexchange_codegolf
Task As input you have: a positive integer N And you should output: The number of integers in \$[1,N]\$ (an inclusive range) which end with the digit \$2\$ in base ten. Test cases 1 -> 0 2 -> 1 5 -> 1 10 -> 1 12 -> 2 20 -> 2 30 -> 3 54 -> 6 97 -> 10 100 -> 10 Rules It is a code-golf so the lowest score in bytes wi...
stackexchange_codegolf
Given no input, your task is to generate the following: a b c d e f g h i j k l m n o p q r s t u ...
stackexchange_codegolf
I'm trying to shorten a bash solution to a Code Golf challenge, which requires an output of true or false. I've managed to condense the key piece of the code down to a substring check, to determine if the provided argument, $1, is a substring of a particular hard-coded fixed string, of the form: [[ FIXEDSTRING = *$1* ]...
stackexchange_codegolf
Background I feel that for a site named code-golf we have a shockingly little amount of golf being played. Let's fix that. Challenge Determine whether the hole of a minigolf course can be reached after exactly a certain number of movements and whether it can be reached at all. How to play Inputs are an integer "power l...
stackexchange_codegolf
The Cantor function is continuous everywhere and constant almost everywhere, but has an average slope of 1: The function can be found recursively: \$f_0(x)=x\$ \$f_{n+1}(x)=\left\{\begin{matrix}\frac{1}{2}f_n(3x)&x\in[0,\frac{1}{3})\\ \frac{1}{2}&x\in[\frac{1}{3},\frac{2}{3})\\ \frac{1}{2}+\frac{1}{2}f_n(3x-2)&x\in[\f...
stackexchange_codegolf
Background A bijective base b numeration, where b is a positive integer, is a bijective positional notation that makes use of b symbols with associated values of 1 to b. Unlike its non-bijective counterpart, no symbol has a value of 0. This way, each non-negative integer n has a unique representation in bijective base ...
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
Introduction We have 22 Collatz conjecture-related challenges as of October 2020, but none of which cares about the restrictions on counter-examples, if any exists, to the conjecture. Considering a variant of the operation defined in the conjecture: $$f(x)= \cases{ \frac{x}{2}&for even x \cr \frac{3x+1}{2}&for odd x }...
stackexchange_codegolf
Your challenge is to turn input text to brain-flak code that will output the text. Tutorial taken from here with permission here Brain-Flak has two stacks, known as 'left' and 'right'. The active stack starts at left. If an empty stack is popped, it will return 0. That's it. No other variables. When the program starts,...
stackexchange_codegolf
An even distribution number is a number such that if you select any of it's digits at random the probability of it being any particular value (e.g. 0 or 6) is the same, \$\frac1{10}\$. A precise definition is given later on. Here are a few examples: \$\frac{137174210}{1111111111} =0.\overline{1234567890}\$ is an even...
stackexchange_codegolf
Task Any one of these two: Determine if a given position (an ordered non-empty collection of integers in the range ‒8 to 8, or ‒7 to 7 if you want) is a valid Dimensional Chess position. List all the valid positions in any order. Make sure to describe your input (if not listing all) and output formats. The 2368 vali...
stackexchange_codegolf
Intro This is based on an actual problem I recently faced while making a computer game and I thought it would make for a nice round of code-golf. There are seven main spectral classes of star which put out varying amounts of heat. The geology of planets around a star are greatly influenced by the amount of heat receive...
stackexchange_codegolf
Challenge Given a single word as input, determine if the word is odd or even. Odd and Even words Assume the general rules: odd + odd = even even + odd = odd odd + even = odd even + even = even In the alphabet, the odd letters are: aeiou And the even letters are: bcdfghjklmnpqrstvwxyz The same applies to capital lett...
stackexchange_codegolf
Your task is to create a program that is to mimic Big Ben (Twitter). Task Whenever a new hour has begun (according to your computer's local time or UTC), you have to output BONG repeated hour times (with a space between the words). For example, when it's 3 o' clock, you have to output BONG BONG BONG. The time format fo...
stackexchange_codegolf
To "shift" over a number n places, do the following: Remove the last n digits Add n copies of the first digit to the beginning of the number For example, to shift the number 31415 three places, take out the last three digits to get 31, and then add three more copies of the first digit, 3, to the end, giving 33331. If...
stackexchange_codegolf
Background One of the commonly meme'd aspects of javascript is its incredibly loose type coercion that allows for +!![]+[+[]] == '10' this technique can also be used to create letters as seen in the following example: [[][[]]+[]][+[]][-~[]] == 'n' [undefined+[]][+[]][-~[]] // [][[]] -> undefined ['undefined'][+[]][-~[]...
stackexchange_codegolf
Introduction For a given rational number r, find a pair of integers p,q so that p/q=r and the number of less used bits in p and q are minimized (details below). Challenge A positive rational number r can be expressed as the ratio of two positive integers, r=p/q. The representation is not unique. For each of these repre...
stackexchange_codegolf
Challenge: In a hypothetical scenario, the countdown timer for a race has random intervals between the counts, to prevent premature starting, e.g. 3 (0.82 seconds pass), 2 (0.67 seconds pass), 1 Input: nothing Output: Write a program (or function) that prints the 3 numbers with a random time interval from 0.50 seco...
stackexchange_codegolf
I see from this SMBC comic that Zach Weinersmith is offering a generous 14 points to anybody who can find a way of generating the following series: 0, 1, 4, -13, -133, 52, 53, -155 Now, we all know that there are infinite ways of generating any given numeric series, so Zach is clearly just giving those points away. Bu...
stackexchange_codegolf
Task Create a program that calculates the factorial of a number using no built-in factorial functions. Easy? The catch is that you must write your entire program (including testing it) in haiku form. You can use as many haikus as you need, but when pronounced, they must follow the 5-7-5 syllable format. Scoring This i...
stackexchange_codegolf
Background A few months ago, the adventure of your life was just about to start. Now, in this precise moment (yeah, now), after months of suffering and hard work, you and a group of friends are standing on the top of the world. Yes, you are right, you are on the summit of Sagarmāthā. However, things aren't going as wel...
stackexchange_codegolf
Challenge Given two question IDs, try to figure out how similar they are by looking at the answers. Details You will be given two question IDs for codegolf.stackexchange.com; you may assume that there exist questions for both IDs that are not deleted, but are not necessarily open. You must run through all of the answer...
stackexchange_codegolf
Wheat Wizard has once tried to come up with a parsing problem unsuitable for regex, but it failed due to Anders Kaseorg's Perl regex answer. This is the second attempt. Now that we know that Perl regex is far more powerful than we've imagined, this challenge aims to be un-golfy for it instead. Introduction A lambda ter...
stackexchange_codegolf
In most programming languages, the string Hello, World! can be represented as "Hello, World!". But if you want to represent "Hello, World!" you need to escape the double quotes with backslashes for "\"Hello, World!\"", and to represent that you also need to escape the backslashes resulting in "\"\\\"Hello, World!\\\"\"...
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
For example, how many adjacent swaps are at least needed to convert some string such as BVVKCV to one without any instances of VK? Input-length of the string will be within the range 1 <= length <= 200. VK will be hardcoded across all test cases. Input string examples: Input: VKVKVVVKVOVKVQKKKVVK Output: 8 Input: VV...
stackexchange_codegolf
This is a 3x3 ASCII jigsaw puzzle: _____ _____ _____ | _| |_ | | (_ _ _) | |_ _|_( )_|_ _| | (_) |_ _| (_) | | _ _) (_ _ | |_( )_|_ _|_( )_| | _| (_) |_ | | (_ _) | |_____|_____|_____| This is also a 3x3 ASCII jigsaw puzzle: _____ _____ _____ | |_ _| | | _ ...
stackexchange_codegolf
This challenge was greatly inspired by this Stack Overflow post. Challenge Given a bunch of clients in terms of when they enter a room and when they exit it, determine the period(s) of time when the room has a maximum number of people. The time resolution should be to the minute. For example, if there are three clients...
stackexchange_codegolf
Your program should find the number of string pairs (pairs of 2) that contain all vowels (a e i o u), when given an integer N and N strings. There are easy ways to do this, but I'm looking for the quickest possible solution. Example: INPUT: 4 password unique orbiting ointmental OUTPUT: 2 EXPLANATION: password has a,o...
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
Part of the lean Language of the Month A pong* is a set \$P\$ with an operation \$+\$, that satisfies the following properties: \$ \forall a, b \in P : (b + b) + a = a\\ \forall a, b \in P : a + (b + b) = a\\ \forall a, b, c \in P: a + (b + c) = (a + b) + c \\ \$ This makes a pong*, just a group where every element is ...
stackexchange_codegolf
Pascal's triangle is a triangular diagram where the values of two numbers added together produce the one below them. This is the start of it: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 You can see that the outside is all 1s, and each number is the sum of the two above it. This continues forever. Your challenge is to chec...
stackexchange_codegolf
Background When you run tail -f file in bash, the file is outputted and then any subsequent appends. However, when you remove something that has already been displayed, tail outputs: tail: nameoffile: file truncated Your Challenge When given an input f, append tail: [value of f]: file truncated (with trailing & leadin...
stackexchange_codegolf
Usually to run multiple commands consecutively one would do: sudo apt update && sudo apt upgrade # 35 characters I can't help but feel there's a neat trick to running these with less keystrokes, and you golfers here love challenges :) I've found a ton of answers around various SE Sites related to running arguments to ...
stackexchange_codegolf
Inspired by this Puzzling challenge, and easier version of my previous challenge. Challenge A 2D rectangular grid is given, where each cell is either an empty space or a wall. You start at the top left cell, and you need to exit through the bottom right cell. You can move to one of four adjacent cells in one step. You ...
stackexchange_codegolf
The title says it all; Given a number in the binary (base-2) number system, output the same number expressed in unary (base-1). You should take the binary number as a string (optionally with a separator), list, or equivalent structure of digits, using any number or digit you like for the digits. The unary output can us...
stackexchange_codegolf
Logo is a programming language that was designed back in 1967 that has great potential for creating graphics in relatively few bytes compared to other languages. Logo is an educational programming language that utilizes Turtle Graphics. There are multiple interesting implementations of Logo including: Apple Logo Atari...
stackexchange_codegolf
The task is the following. Given an integer x (such that x modulo 100000000003 is not equal to 0) presented to your code in any way you find convenient, output another integer y < 100000000003 so that (x * y) mod 100000000003 = 1. You code must take less than 30 minutes to run on a standard desktop machine for any in...
stackexchange_codegolf
On some terminals, pressing backspace generates the control code ^H to delete the previous character. This gave rise to a snarky idiom where edits are feigned for comedic effect: Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ. Given a string with one or more ^H's, output the result of backsp...
stackexchange_codegolf
The absolute value of a number \$x\$ is normally written as \$|x|\$. The left and right side of the absolute value uses the same symbol, so it is not immediately obvious how to parse nested absolute values e.g. \$||1-2|+|3-|4-5|||\$ Your goal is to parse such an expression containing nested absolute values: The express...
stackexchange_codegolf
Nichomachus's Theorem relates the square of a sum to the sum of cubes: and has a beautiful geometric visualization: Challenge: Create the 2d part of this visualization in ascii. You will need to ensure that all visual demarcations are upheld by your diagram. This is simplest to do with four "colors," though it's pos...
stackexchange_codegolf
Let \$A\$ be a positive integer consisting of \$n\$ decimal digits \$d_1,d_2,...,d_n\$. Let \$B\$ be another positive integer. For the purpose of this challenge, we call \$A\$ a copycat of \$B\$ if there exists at least one list of positive integers \$p_1,p_2,...,p_n\$ such that: $$\sum_{i=1}^{n}{{d_i}^{p_i}}=B$$ \$A\$...
stackexchange_codegolf
King of the Torus! Your job is to conquer the torus, but wait, there are multiple other players banded together in teams facing you! You will need to use your wit's to conquer the torus. There are three teams: red, blue and green. Teams are self-assigned arbitrarily. If the teams are even you may join the team of your ...
stackexchange_codegolf
After giving back the results of the last topology exam to his students, Pr. Manifold was worried about complaints. Since he is aware his students know where his office is located, Prof. Manifold decided to transform his office into a bunker with a 10 digit password (all characters are digits). But he suspected his st...
stackexchange_codegolf
Objective Given an ASCII character, toggle its "shift-ness" on the standard US keyboard (ANSI-INCITS 154-1988 (R1999)), then output it. Mapping ) ↔️ 0 ! ↔️ 1 @ ↔️ 2 # ↔️ 3 $ ↔️ 4 % ↔️ 5 ^ ↔️ 6 & ↔️ 7 * ↔️ 8 ( ↔️ 9 " ↔️ ' + ↔️ = , ↔️ < - ↔️ _ . ↔️ > / ↔️ ? : ↔️ ; (Capital Latin letters) ↔️ (Small Latin letters) [ ↔️ { \...
stackexchange_codegolf
Your boss just emailed you a list of 12 programming tasks he needs done as soon as possible. The tasks are simple enough but your boss, being a young software tycoon suckled by social networking, insists that your solutions be able to fit within a single Twitter tweet. This means that you only have 140 bytes worth of c...
stackexchange_codegolf
What is the shortest way to secure a site with Javascript? I am new to Code Golfing, and this is what I've come up with so far. I bet that this could be improved though: Challenge: Make a script which redirects http:// to https:// with the least bytes of code Attempts: Original code (150ish BYTES!): if (window.locati...
stackexchange_codegolf
Write a function or program that encodes a string into a Code 39 format barcode, where each character is encoded as five bars separated by four gaps. Either two of the bars and one of the gaps are wide and others are narrow (10*4 codes), or three of the gaps are wide and none of the bars are (4 codes). This gives 44 di...
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
I want to avoid responding to illegal or spoofed addresses. One type that's easy to detect is an address that should not exist on a packet received by my router: a special-use address. Challenge Given an IPv4 32-bit address, identify whether it is valid general-use address. Challenge rules Special-use addresses, as de...
stackexchange_codegolf
The Golden Ratio Bureau is obsessed with this new thing they call base-phi. You see it and decide to code-golf, as is your natural instinct. To be specific, base-phi is a number system like base 10, except it uses the number phi, or the golden ratio, as its base. A ones digit would be x*10^y, but in base phi 10 is repl...
stackexchange_codegolf
Recreational languages win at code golf too much. This challenge is simple, when using higher level functions. The task is as follows: Given any valid url, which is guaranteed to result in a valid HTML document (for example https://en.wikipedia.org/wiki/Ruby_on_Rails, which has 9 images), count the number of images di...
stackexchange_codegolf
A half cardinal cyclic quine is a cyclic quine with two states, one perpendicular to the other. Rules You can decide which rotation you want to implement, clockwise or counter-clockwise. Once rotated, any gaps in your code should be replaced with spaces to preserve the positioning. Your program must satisfy the communi...
stackexchange_codegolf
Here is a relatively simple two dimensional array challenge. Imagine a battlefield of 625 foot soldiers. You command the odd troops, but unfortunately the strength of the even troops overwhelms you. Thankfully, your soldiers have a secret power: If the power of each odd troop and the fellow odd allies surrounding them ...
stackexchange_codegolf
The Monkey has swung home to find his tree all in pieces. He likes order and scoops up all his 'tree-parts' and sets them out in 3 groups. The Monkey's 3 nested lists: STEP = [['S', '1', 'B', '3'], ['S', '3', 'B', '11'], ['S', '5', 'B', '12'], ['S', '4', 'B', '13'], ['S', '2', 'B', '14']] TRANSITION = [['T', '2', 'B',...
stackexchange_codegolf