instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Given a string or list, calculate the effects of gravity on that string/list. The string will be made of 5 characters: N has a weight of 2 L has a weight of 1 S has a weight of -2 D has a weight of -1 (the 5th character is whatever you want, it means empty space. I use (space) in my examples) Items with negative we...
stackexchange_codegolf
This is a Cops and Robbers challenge. This is the cop's thread. The robber's thread is here. As a cop, you must pick any sequence from the OEIS, and write a program p that prints the first integer from that sequence. You must also find some string s. If you insert s somewhere into p, this program must print the second ...
stackexchange_codegolf
This challenge is quite simple to conceptualise, but likely a lot harder to execute. In this challenge, the program will have to detect the number N of its characters that have been randomly changed (at least half of the program will always remain). Then, it will have to output the Nth prime number. A 'change' can only...
stackexchange_codegolf
The Challenge For this challenge, you are supposed to determine if a given number is in the Cantor set. So first, let's define the Cantor set. First, start with the numbers between 0 and 1. Any numbers outside this range are not in the Cantor set. Now, let's divide the numbers into three equal parts: [0,1/3], [1/3,2/3]...
stackexchange_codegolf
"First they came..." is a poem by Martin Niemöller: First they came for the Socialists, and I did not speak out- Because I was not a Socialist. Then they came for the Trade Unionists, and I did not speak out- Because I was not a Trade Unionist. Then they came for the Jews, and I did not speak out- Because I was not a...
stackexchange_codegolf
Given (in any structure; flat list, two lists of lists, a tuple of matrices, a 3D array, complex numbers,…) the coordinates for two non-degenerate triangles ABC=[[Ax,Ay],[Bx,By],[Cx,Cy]] and PQR=[[Px,Py],[Qx,Qy],[Rx,Ry]], determine if they are similar, that is, they both have the same shape, or one has the same shape ...
stackexchange_codegolf
Background Puzzlang is a derivative of Brainfuck, where the symbol X executes a BF command based on three characters on top of it, and anything else does nothing. The following is the translation table for Puzzlang, where X is the literal X and . stands for anything else: > < + - . , [ ...
stackexchange_codegolf
In R print(x, digits=n) does something a little complicated. It always shows all the digits to the left of the decimal point and then, if there are any digits to the right it rounds the whole number so that at most n digits are shown. However, leading 0s are not counted. Here are examples to show how the function work...
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
Your challenge is to write N snippets of code such that, when you concatenate the first K ≥ 1 together, they produce the number K. The higher N, the better. Here's the catch: you may not use any character more than once across your snippets. Rules You may use the same character multiple times in one (and only one) sni...
stackexchange_codegolf
Definitions: A line is a possibly empty sequence of characters terminated by a “newline character.” A “newline character” is a character that cannot be a component of the aforementioned character sequence. A line number comment is a character sequence that does not alter the meaning of source code in the programming l...
stackexchange_codegolf
Description A Caesar Shift is a very simple monoalphabetic cipher where each letter gets replaced by the one after it in the alphabet. Example: Hello world! -> IFMMP XPSME! (IBSLR, EGUFV! is the output for the actual challenge, this was an example of shifting by 1.) As you can see, spacing and punctuation remain unatt...
stackexchange_codegolf
The Fibonacci sequence is a fairly well known thing around here. Heck, it even has its own tag. However, for all that, we sure like to stick to our roots of 1, 1, ... (or is it 0, 1, ...? We may never know...). In this challenge, the rules are the same, but instead of getting the nth item in the Fibonacci sequence, you...
stackexchange_codegolf
Given 4 points on the 2D planes A, B, C, D, calculate the area of the intersection region of the triangles OAB and OCD, where O is the center of the plane, having coordinate (0, 0). Algorithms that runs in constant time complexity (in terms of arithmetic operations) are encouraged, but not forced. Rules Each point is ...
stackexchange_codegolf
Classic Tetris was often a difficult game to play. One problem was that you could only work with the Tetris piece you were given, so if you had an awkward board, it would sometimes be difficult to find a suitable location to put your piece. Another problem was that you could only look one piece ahead, so it was difficu...
stackexchange_codegolf
Can you recover a sequence of letters from a sequence of dots and dashes? In Morse code, x is represented by -..-, but without the help of spaces, -..---.-... could represent xmas, or dole, or teettteteee, etc. I took the lyrics from "Rudolph, the Red-Nosed Reindeer" to make the following sequence of letters: youknowda...
stackexchange_codegolf
Tamagotchi and Giga Pets were small electronic devices which simulated a little virtual pet. This pet had several stats, like health, hunger, etc. I recently wrote this example: import msvcrt,os,sys;d=m=100;h=s=t=p=0;f=10 while 1: os.system('cls'if os.name=='nt'else'clear');print("health:",d,"\nhunger:",h,"\nsleep:",...
stackexchange_codegolf
Challenge: Get the JavaScript string value containing only the "-" character using code only containing the following three symbols: +[]. Note: I'm not sure if this is possible. Scoring criterion: The number of bytes of code used. Why? I've set myself a challenge to be able to write code using only the above three char...
stackexchange_codegolf
Input: A string (or the closest thing to that in your language) Output: The same string but converted to sentence case Rules: For this challenge, sentence case can be considered "The first letter of each sentence is capitalized. The rest are lowercase." (i.e. proper nouns do not have to be capitalized) If the input do...
stackexchange_codegolf
If the agent is at the origin it always moves right when you choose it. The goal is to get one agent to 10. The cost is the sum of the square of the total number of moves (left or right) taken by each individual agent until the first agent gets to 10. You want to minimise the expected cost Once you have fixed a strateg...
stackexchange_codegolf
Given a positive integer n. Generate a JSON array (can be a string, or your language's built-in JSON representation as long as we can get valid JSON, (your code does not need to include outputting the string, you can just use the built-in JSON representation)) containing two empty JSON arrays, then, add a set of 2 empt...
stackexchange_codegolf
The TV series "Breaking Bad" replaced the letters Br and Ba with a periodic-table like representation, printing [Br35]eaking [Ba56]d. Create a program that takes a string input, does a replacement and prints an output. The replacement shall subsidize any substring that matches an element symbol with the notation demons...
stackexchange_codegolf
What general tips do you have for golfing in V? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to V (e.g. "remove comments" is not an answer). Since V is heavily based on vim, most of the tips for golfing vim would apply too. But there are some features in...
stackexchange_codegolf
Here is Minkowski's question mark function: It is a strictly increasing and continuous function from the reals to themselves that, among other unusual properties, maps rational numbers to dyadic rationals (those with a power-of-two denominator). Specifically, suppose the continued fraction representation of a rational...
stackexchange_codegolf
You're a chef and you love cooking with your spices, but recently you've taken a liking to organizing your spices based on how often you use them. But you have no time to be writing down when you used your spice last. Simply, you swap and move spices around, and this seems to do the trick. But of course you're a chef a...
stackexchange_codegolf
Challenge Consider the rainbow as seven colours, represented by strings as Red Orange Yellow Green Blue Indigo Violet. Your task is to create a program that receives one of these colours as input and outputs next in order rainbow colour. This includes overlapping Violet -> Red Input A string containing one of rainbow c...
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
Main objective The main objective is to output a text, it doesn't mind which text or where the text gets its output (it can be on a browser window, the default console etc). It just requires the condition that what is output must be indeed "real chars" (the ones in UNICODE for example), it's not considered valid to dis...
stackexchange_codegolf
Your challenge, should you choose to accept it, is to write a program in a language of your choice that, when given a string (limited to printable ASCII) as input, outputs a new program in the same language that outputs that string without using any characters from that string in the code. But this task is impossible a...
stackexchange_codegolf
Write the shortest function to convert an IP address into it's integer representation and output it as an integer. To change an IPv4 address to it's integer representation, the following calculation is required: Break the IP address into it's four octets. (Octet1 * 16777216) + (Octet2 * 65536) + (Octet3 * 256) + (Octe...
stackexchange_codegolf
You will be given a 2-D array A of integers, and a length N. Your task is to find within the array the straight line (horizontal, vertical or diagonal) of N elements that yields the highest total sum, and return that sum. Example N = 3, A = 3 3 7 9 3 2 2 10 4 1 7 7 2 5 0 2 1 ...
stackexchange_codegolf
Given an mxm chess board, find a minimum number of pieces of the given kind and place them on a chess board in such a way that all squares are either occupied or attacked by at least one piece. Input The input consists of two parameters: m, the number of squares on each side; and a letter which indicates which piece to...
stackexchange_codegolf
In Java/.NET/C/JavaScript/etc. you can use ternary-ifs to shorten if-statements. For example (in Java): // there is a String `s` and an int `i` if(i<0)s="Neg";else if(i>0)s="Pos";else s="Neut"; Can be shortened with a ternary-if to: s=i<0?"Neg":i>0?"Pos":"Neut"; Challenge: Input: A regular if-else (possible with nes...
stackexchange_codegolf
As discussed in the Lounge room on Stack Overflow: if you can't implement the Quicksort algorithm given en.wikipedia.org/wiki/Quicksort in any language you have minimal knowledge of, you might want to consider a different profession. @sbi but SBI also noted that maybe BrainF*** was an exception. So, here's the puzzle...
stackexchange_codegolf
Write a program, given an input n, will generate all possible n-tuples using natural numbers. n=1 (1),(2),(3),(4),(5),(6)... n=2 (1,1),(1,2),(2,1),(2,2),(1,3),(3,1),(2,3),(3,2),(3,3)... n=6 (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1)... The output may be in any order that does not break any other rules. The program...
stackexchange_codegolf
Your task is to implement a Tetris strategy balanced in terms of score vs code size. In this version of the game tetrominoes are rotated and dropped from above into a grid of 20 rows and 10 columns. While falling, they cannot be rotated or moved horizontally. As usual, a dropped piece stops when it reaches the bottom o...
stackexchange_codegolf
Note: When I refer to a bridge, I mean it in the non-mathematical sense Introduction You are on a network of islands which are connected by wooden bridges and you want to see if you can burn every bridge in the island network. However, you can only burn a bridge once you've walked over it. Once a bridge has been burned...
stackexchange_codegolf
For the purpose of this challenge, arguments are things you pass to a function at the call site, while parameters are what the function uses in its implementation. Or, more succinctly: arguments = external, parameters = internal. While there are several modern languages that have support for argument labels for func...
stackexchange_codegolf
Given a non-empty string of lowercase ASCII letters a-z, output that string with each consecutive “run” of the same letter lengthened by one more copy of that letter. For example, dddogg (3 d’s, 1 o, 2 g’s) turns into ddddooggg (4 d’s, 2 o’s, 3 g’s). This is code-golf: the shortest answer in bytes wins. Test cases aab...
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
Here goes a quick proof by Alan Turing that there is no program H that can solve the halting problem. If there was, you could make a program X such that X(n) = if H(n,n) == Halt then output X(n) else output ":-)". What is the value of H(X,X)? Your job is to make a partial halting solver, such that when some X of your c...
stackexchange_codegolf
Problem: Given a string representing a mathematical expression with constants (pi, e, psi, i), basic arithmetic operations (+, -, *, /), parentheses, fractions, and exponentiation, write a program or function to convert a string to its equivalent LaTeX code. The input string will only contain digits, arithmetic operato...
stackexchange_codegolf
You probably know the rhetorical question of whether a glass is half full or half empty. I'm getting a little tired of the phrase, so I decided that it's time to eliminate this confusion about glass fullness or emptiness programmatically. Your task is to write a program that takes an ASCII art representation of an ugly...
stackexchange_codegolf
Given a number \$n ≥ 2\$, a blackbox function \$f\$ that takes no arguments and returns a random integer in the range 0...n-1 inclusive, and a number \$m ≥ n\$, your challenge is to generate a random integer in the range 0...m-1 inclusive. You may not use any nondeterministic builtins or behaviour, your only source of ...
stackexchange_codegolf
Introduction A queue is an abstract data type where elements are added to the front (enqueue) and removed from the back (dequeue). This is also known as the FIFO (First In First Out) principle. It is best shown with an example: Challenge Given a non-empty array that contains positive integers and elements that indica...
stackexchange_codegolf
You mission today is to invent a text compressor. Task You'll write two functions: The packer is a function that accepts a string of ASCII characters (U+0000 to U+007F) and outputs a Unicode string (U+0000 to U+10FFFF), containing the fewest characters possible. The unpacker is a function that accepts an encoded Unico...
stackexchange_codegolf
Sometimes when you're lying in bed and reading a message, your phone screen will pop into landscape mode right in the middle of a sentence. Only being able to read left to right, you find yourself incapacitated, unable to process the text in front of you. To ensure that this won't happen again, you decide to make every...
stackexchange_codegolf
I forgot towel day Sandbox link PHP script for both examples (error, formatting the string) Corrected php script, the input is self explanatory PHP script with more input comment/uncomment $argv to see different results As you may know, May 25 is well known as Towel Day, because of the many uses a towel can have. A si...
stackexchange_codegolf
Gödel's β function takes three natural numbers as arguments. It is defined as β(x,y,z) = rem(x, 1 + (z + 1) · y) = rem(x, (z · y + y + 1) ) where rem(a, b) denotes the remainder after integer division of a by b. The β Lemma now states that: For any sequence of natural numbers (k_0, k_1, … , k_n), there are natural nu...
stackexchange_codegolf
In this challenge, the goal is to find the values of some variables after a number of assignments are done. An example input: a = 5 b = 4 c = a = b a = 2 b = a This would result in: a = 2 b = 2 c = 4 Each statement will be one of the following: A variable name ([a-z_]+) A numeric value ([0-9]+) An assignment operati...
stackexchange_codegolf
Every number can be represented using an infinitely long remainder sequence. For example, if we take the number 7, and perform 7mod2, then 7mod3, then 7mod4, and so on, we get 1,1,3,2,1,0,7,7,7,7,..... However, we need the shortest possible remainder subsequence that can still be used to distinguish it from all lower ...
stackexchange_codegolf
Compare if three string variables with the same content, return true if they are or false if they are not without using conditional operators and bitwise operators. e.g. in C# without && || ?: return (string1==string2)==(string1==string3)==true; PS: initial idea came from these question
stackexchange_codegolf
Challenge Given an image of the sky, you must output the cloud cover in oktas. The image supplied will be an image file (the type is up to you) and the output should be to STDOUT. Oktas In meteorology, an okta is a unit of measurement used to describe the amount of cloud cover at any given location such as a weather st...
stackexchange_codegolf
Inspired by and drawns from Is this number Loeschian? A positive integer \$k\$ is a Loeschian number if \$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers. For example, the first positive Loeschian numbers are: \$1\$ (\$i=1, j=0\$); \$3\$ (\$i=j=1\$); \$4\$ (\$i=2, j=0\$); \$7\$ (\$i=2, j=...
stackexchange_codegolf
A positive integer \$x\$ is an \$n\$-perfect number if \$\sigma(x) = nx\$, where \$\sigma(x)\$ is the divisor sum function. For example, \$120\$ is a \$3\$-perfect number because its divisors sum to \$360\$: $$360 = 3\times120 = 1+2+3+4+5+6+8+10+12+15+20+24+30+40+60+120$$ and $$926073336514623897600 = 6\times1543455560...
stackexchange_codegolf
\$BB\$ is the busy beaver function, an uncomputable function. Write a program which when given an integer \$n\$ as input, will output \$BB(n)\$, with at least \$\frac 2 3\$ probability. You can do whatever (return something wrong, infinite loop, explode, etc.) in other cases. To help you compute it, you're given a func...
stackexchange_codegolf
Your goal is to write a program that will print out the Laplace transform of a polynomial function with integer coefficients \$f(x)\$. The Laplace transform of \$f(x)\$ is defined as \$\int_0^\infty f(x) e^{-sx} dx\$. The standard input for the polynomial function will be a+bx+cx^2+dx^3+... If the coefficient is zero,...
stackexchange_codegolf
Task FizzBuzz, but instead of 3 and 5, you'll take the numbers and corresponding strings as input. You can assume all inputted numbers are coprime (and \$\ge 2\$). You'll receive one or more numbers, and a string to print with each of them. The normal FizzBuzz would be something like [[3, "Fizz"], [5, "Buzz"]], but you...
stackexchange_codegolf
The purpose of this challenge is to solve the original first Project Euler problem, but as the title suggests in constant time (with respect to the size of the interval). Find the sum of all the multiples from a list of numbers in some defined range, in such a way that the running time of your program runs in constant...
stackexchange_codegolf
Background You are working for some board-game manufacturer and need to produce wooden tiles with the numbers from 0 to n engraved on them for some game. However, without further ado, some tiles would become indistinguishable, e.g., 6 and 9. To avoid this, you have to equip numbers that can be confused with others (and...
stackexchange_codegolf
I need to construct a functor that iterates over the linear representation of a sub-lattice of size \$d_x,d_y,d_z,d_q\$ embedded in a lattice of size \$n_x,n_y,n_z,n_q\$. The sub-lattice corner is shifted by \$(l_x,l_y,l_z,l_q)\$. Since the functor can be called million of times, the goal is to produce the most effici...
stackexchange_codegolf
This is a rip-off of a rip-off of a rip-off of a rip-off of a rip-off. Go upvote those! Your task, if you accept it, is to write a program/function that outputs/returns its input/args. The tricky part is that if I make your source code palindrome via duplicating reversed source code after the original code, the output...
stackexchange_codegolf
My colleague recently sent me the following piece of JavaScript as a joke: let butScript = (nrOfButs) => { for(var i = 0; i < nrOfButs; i++){ if(i % 3 == 0){ console.log("Yeah") } if(i % 2 == 0){ console.log("But") } if(i % 3 == 1){ console...
stackexchange_codegolf
You wake up and find out that your computer has been stolen! You have a few sensors and scanners, but unfortunately, the footage is incomplete, so you want to find and rank your suspects for further investigation. Your computer is a rectangle, and your camera caught a bunch of people walking around with packages; howev...
stackexchange_codegolf
Consider a sorted array of positive floating point numbers such as: input = [0.22, 2.88, 6.35, 7.17, 9.15] For each integer \$i\$ from 1 up to the last value in input rounded up, output the mean of all values less than \$i\$. In this case the output should be: [0.22 0.22 1.55 1.55 1.55 1.55 3.15 4.155 4.155 5.154 ] I...
stackexchange_codegolf
You are on an advanced intergalactic space station. A friend of yours who is minoring in the Study of Gravity just created a game that involves using microgravity as a way to move a ball around. She hands you a small controller with four directional arrows on it and a maze like structure with a ball sitting to the lef...
stackexchange_codegolf
This idea came to me when I saw my little brother playing with my calculator :D The task Taking a integer as an input, print that many graphical square roots under each other, like this: n = 1 ___ \/ 1 n = 3 _______ / _____ / / ___ \/\/\/ 3 n = 5 ___________ / _________ / / _______ / ...
stackexchange_codegolf
Input A non-empty shuffled string consisting of ASCII characters in the range \$[32..126]\$. Output The output is obtained by applying successive rotations to the input string. For each letter ([a-zA-Z]) in the input string, going from left to right: if the letter is in upper case, rotate all characters before it by o...
stackexchange_codegolf
Leonardo da Pisano a.k.a Fibonacci was instrumental in bringing the Hindu-Arabic numeral system into Europe. Before that, mathematicians there worked in base sixty with Roman numerals. For example, the square root of two might be approximated as: one and twenty-four parts of sixty and fifty-one parts of three-thousand-...
stackexchange_codegolf
The bus driver picks up the children from their homes every morning for school. All the homes are positioned around a circular street and the bus driver has to stop at every home exactly once. One monday morning the bus driver decided to only pick up every second child he encountered along his way. However, he still ha...
stackexchange_codegolf
Introduction The perimeter density matrix is an infinite binary matrix M defined as follows. Consider a (1-based) index (x, y), and denote by M[x, y] the rectangular sub-matrix spanned by the corner (1, 1) and (x, y). Suppose that all values of M[x, y] except Mx, y, the value at index (x, y), have already been determin...
stackexchange_codegolf
Background Flow Free is a series of puzzle games whose objective is to connect all the same-colored pairs of dots on the grid. In this challenge, we consider the original game on a rectangular grid (no variations like bridges, warps, or hexagonal grids). A puzzle in Flow Free might look like this: Puzzle Solution ......
stackexchange_codegolf
I noticed a certain game had a peculiar life counter, which instead of stopping at 999, gained a new digit – the next number was crown hundred or 00. After 99 came crown hundred crownty (0) and the last number, after 9, was crown hundred crownty crown or , which would be 1110 in decimal. Your task is to write a program...
stackexchange_codegolf
Given the Dowker notation of a knot and its crossing signs, calculate its bracket polynomial. Although there are more technical definitions, for this challenge it is enough to think of a knot as something made physically by attaching the two ends of a string together. Since knots exist in three dimensions, when we draw...
stackexchange_codegolf
Prime Wednesdays Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates. Input The input to your program/function will be a year (eg 2016) and is flexible. The year wi...
stackexchange_codegolf
Related: Multiply Quaternions Challenge Given a string made of ijk, interpret it as the product of imaginary units of quaternion and simplify it into one of the eight possible values 1, -1, i, -i, j, -j, k, -k. The evaluation rules are as follows: $$ ii = jj = kk = -1 \\ ij = k, \quad jk = i, \quad ki = j \\ ji = -k, \...
stackexchange_codegolf
The task In this challenge, your task is to write a program in a programming language L that takes a positive integer n, and outputs the sum of the proper divisors of n (sequence A001065 on OEIS). It should return the correct output for any 1 ≤ n ≤ 10 000. Here are the first 10 outputs: 0, 1, 1, 3, 1, 6, 1, 7, 4, 8 Fu...
stackexchange_codegolf
You have to take a base-10 number (e.g. 735) and another number for the base to convert to, and convert the base-10 number into the equivalent number in the other base. Rules: You aren't allowed to use any conversion functions built into your language This is code-golf, the shortest answer in bytes wins!
stackexchange_codegolf
You and your friend want to send each other secret messages. However, because you are conspiracy theorists and think that the government has a quantum computer that can crack any standard encryption. Therefore, you are inventing one of your own. The first step of this is as follows: taking an input string, you check...
stackexchange_codegolf
Given some raw HTML, sanitize it by formatting the spaces, as defined below. Output rules: Like many challenges, this one is inspired by XKCD. First, "untag" all tags with nothing but spaces in them. (<i>te<b> </b>xt</i> becomes <i>te xt</i>). If a tag has nothing in it (like <b></b>, simply delete it and move o...
stackexchange_codegolf
The goal of this challenge is to compare how well different programming languages support functional programming, by seeing how much code it takes to implement BLC8, the simplest functional programming language BLC8 is the bytewise variant of Binary Lambda Calculus, as described in my 2012 IOCCC entry at https://www.io...
stackexchange_codegolf
This is the robbers' thread to a cops-and-robbers challenge. Click the link to find the cops' thread. In the cops' thread of this challenge, answerers will be writing programs which output two numbers, \$x\$ and \$y\$. As robbers, your goal will be to crack their submissions. To do this, you find a program in the ...
stackexchange_codegolf
Challenge: Get the JavaScript string value containing only the "-" character using code only containing the following three symbols: +[]. Note: I'm not sure if this is possible. Scoring criterion: The number of bytes of code used. Why? I've set myself a challenge to be able to write code using only the above three char...
stackexchange_codegolf
What general tips do you have for golfing in TypeScript's type system? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to TypeScript's type system (e.g. "remove comments" is not an answer). Please post one tip per answer. If you're not familiar with program...
stackexchange_codegolf
Task Given two positive integers a, b and a Unicode mathematical inequality symbol c, determine if a c b is true. You many take the character or its Unicode codepoint for the input c. You may output your language's truthy/falsy values, or two distinct values for true and false respectively. Standard code-golf rules app...
stackexchange_codegolf
Input: A string Output: The rarity of the string, as described below. To find the rarity of a string, follow the steps below. Start with 0. Subtract 3 for each E, A, T, or O in the string. Subtract 2 for each I, N, S, or H in the string. Subtract 1 for each R, D, L, or C in the string. Add 1 for each W, F, G, or Y in ...
stackexchange_codegolf
Create a Tic-Tac-Toe game that allows two human players to play against each other using two networked devices. Requirements: Network play. Program must let both players know whose turn it is. Program must show who won and how (like drawing a line through the three in a row). Graphical game board displayed for both...
stackexchange_codegolf
Challenge Design a compression algorithm specialized for compressing ASCII mazes. You will need to create both a compression algorithm and a decompression algorithm. Your score will be based on the size of your compressed mazes. Mazes These mazes are made primarily of the characters (floors), +, -, |, and # (walls), a...
stackexchange_codegolf
We're getting markdown tables! I assume this is what they look like: data data data data --------------------- | | | | | | | | Your task is to make a program or function to generate one of these tables. You'll be given input (string, list of ...
stackexchange_codegolf
One of my favorite algorithms was posted on Stack Overflow as an answer to What is the fastest way to generate prime number recursively?. In pseudocode: Nathan's algorithm bool isPrime(int n): if (n < 2) return false for p in 2..n-1: if (isPrime(p) && n%p == 0) return false return true This program...
stackexchange_codegolf
The goal of this challenge is to write a program that will simulate a single round of Conway's Game of Life on an existing grid. Input format: Input will be read from stdin. The input will consist of a line containing two numbers, r and c, separated by a single space. These will be the number of rows and columns of the...
stackexchange_codegolf
The London Underground A.K.A. The Tube is the oldest underground railway in the world, it currently consists of eleven lines* servicing 267 named stations (strictly 269** stations since "Edgware Road" and "Hammersmith" each occupy two locations) The challenge Output the names of the lines servicing a station given by n...
stackexchange_codegolf
Surprised that we don't have a symmetric difference challenge yet. Given two lists only containing positive integers, return all items among these two lists that aren't contained in both of the lists. Rules From the set definition: A set is a collection of definite distinct items. So you can assume the items in the ...
stackexchange_codegolf
The following data contains the (approximate) population of each UTC timezone in the world (source): UTC;Population (in thousands) -11;57 -10;1853 -9.5;8 -9;639 -8;66121 -7;41542 -6;272974 -5;332101 -4.5;31923 -4;77707 -3.5;499 -3;248013 -2;4855 -1;3285 0;285534 +1;857443 +2;609921 +3;496279 +3.5;81889 +4;129089 +4.5;3...
stackexchange_codegolf
Given the measures of two of the interior angles of a triangle (x and y; the other angle can be easily calculated with 180 - x - y), draw a line segment that cuts this triangle into two isosceles triangles. You need to output the angle measures of both of your triangles. However, because the base angles are the same, y...
stackexchange_codegolf
A twin of this. FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with "FizzBuzz". For example, FizzBuzz from 1 to 10 is 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz. Your challenge is to, given a list of Fizzes, B...
stackexchange_codegolf
Introduction In a general election, one would like to calculate a constant price per parliament seat. This means that for N >= 0 seats to be distributed and a list ns of votes per party, we would like to find a number d such that sum(floor(n/d) for n in ns) == N To make things interesting (and more like the real worl...
stackexchange_codegolf
The below pattern will form the basis of this challenge. /\ \/ /\ / \ / \ /\/ \/\ \/\ /\/ \ / \ / \/ /\ \/ Given an input width and height, each >=1, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamond...
stackexchange_codegolf
Your task is to write a program or function that takes a string as input, and prints Hello (input), I'm (language name). Examples Python: Input: Oliver Output: Hello Oliver, I'm Python C++: Input: Jacob Output: Hello Jacob, I'm C++ etc. Remember, this is code-golf, so the code with the lowest number of bytes wins. Lead...
stackexchange_codegolf
A binary eye is an odd set of digits, with all of its digits except the center one set to 1 or 0, and the center one set to the opposite of the others. Thus, there are two binary eyes for a given odd number of digits: x eyes 1 1,0 3 101,010 5 11011,00100 7 1110111,0001000 9 111101111,000010000 Make ...
stackexchange_codegolf