instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Many of you may have interacted with people from Russia on the internet at some point, and a subset of you may have noticed the slightly odd method they have of expressing themselves. e.g. удали игру нуб))) where the ))) are added for emphasis on the previous statement, I have been working on a theory that the ratio of...
stackexchange_codegolf
This is a bit similar to this dust covered entry but I'm hoping my spin on it makes it unique enough. Not been able to find anything dissuading me from posting this but there is quite the sea out there. Anyway! The challenge: Your code receives a string of characters; It converts this into an ASCII-art style version of...
stackexchange_codegolf
Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For example, let $$A = \left[ \begin{matrix} -3 & 2 \\ 0 & -1 \end{matrix} \right]$$ Therefore, $$\begin{align} A^2 & = \left...
stackexchange_codegolf
If a positive integer \$N > 2\$ has (strictly) less prime factors (without counting multiplicities) than its successor and its predecessor, we will call it a factor-poor number. In other words, \$\omega(N) < \omega(N - 1)\$ and \$\omega(N) < \omega(N + 1)\$, where \$\omega(N)\$ is the number of unique prime factors of...
stackexchange_codegolf
Write a function or program that takes two words as input and outputs variants of the popular English tongue-twister "How much wood would a woodchuck chuck if a woodchuck could chuck wood?". The output will use the first word four times How much wood would a woodchuck chuck if a woodchuck could chuck wood? and the se...
stackexchange_codegolf
Given a positive integer, output a truthy/falsy value as to whether the number can eat itself. Rules Leftmost is the head, rightmost is the tail If the head is greater than or equal to the tail, the head eats the tail and the new head becomes their sum. If \$sum \ge 10 \$ then the head is replaced by \$sum \mod 10\$. \...
stackexchange_codegolf
Your challenge is to print x digits of pi where x is your code length. Examples: Source code (length) -> output foo! (4) 3.141 foobar (6) 3.14159 kinda long (10) 3.141592653 +++++ (5) 3.1415 123456789 (9) 3.14159265 You can use floor(π/10 * 10code_length) / 1...
stackexchange_codegolf
The cardinality of the set \$\mathbb Q\$ of rational numbers is known to be exactly the same as that of the set \$\mathbb Z\$ of integers. This means that it is possible to construct a bijection between these sets—a mapping such that each integer corresponds to exactly one rational number, and vice versa. Provide such ...
stackexchange_codegolf
Given an array of integers A, the task is to output another array B of the same length so that B[i] is the maximum over A for every index that is not i. That is \$B[i] = \max_{i' \ne i} A[i']\$. Examples: A = [1, 5, -3, 4, 2]. B = [5, 4, 5, 5, 5] A = [1, 2, 3]. B = [3, 3, 2] A = [-1, -2, -3, -1]. B = [-1, -1, -1, -1] ...
stackexchange_codegolf
Problem Consider a square 3 by 3 grid of non-negative integers. For each row i the sum of the integers is set to be r_i. Similarly for each column j the sum of integers in that column is set to be c_j. The task is to write code to enumerate all possible different assignments of integers to the grid given the row a...
stackexchange_codegolf
Cops thread Robbers, Write a program in the cop's language using the cop's P string and your own S string, and the amount of each of them specified in the cop's post. Your S string may not exceed the cop's S string in bytes. The program Using only strings P and S, write a program which takes a list of 5 or more non-rep...
stackexchange_codegolf
Given three non-negative integers y, m, and d (of which at least one must be positive) and a valid date with a positive year (in any reasonable format that includes the year, month, and day, and no additional information), output the date that is y years, m months, and d days after the original date. The Gregorian cale...
stackexchange_codegolf
Given a string of printable ASCII, output the frequency of each character in that string. The Challenge Input is given as a string of printable ASCII characters (decimal [32-126] inclusive). Output the frequency of each character, in ASCII order. The output must have a format similar to [character][separator][count]. ...
stackexchange_codegolf
Background Quaternion is a number system that extends complex numbers. A quaternion has the following form $$ a + bi + cj + dk $$ where \$ a,b,c,d \$ are real numbers and \$ i,j,k \$ are three fundamental quaternion units. The units have the following properties: $$ i^2 = j^2 = k^2 = -1 $$ $$ ij = k, jk = i, ki = j $$ ...
stackexchange_codegolf
Oreoorererereoo Given an input string that is similar to the word "oreo", give an ASCII representation of the cookie that is as wide as the input string (to ensure cookie stability). Rules The input is lowercase, a non-empty string with no whitespace containing any combination of the strings "o" and "re", and contain...
stackexchange_codegolf
This is an exact inverse of the question Convert to Spoken Binary. This introduction is copied from there. Introduction In the video the best way to count, binary is proposed as the best system of counting numbers. Along with this argument is a proposal on how to say numbers in this system. First, we give names to eac...
stackexchange_codegolf
Given positive integer n and e, knowing that e<n and that n is the product of two different odd primes(but the primes are not directly given to you), find such a positive integer d smaller than n that, for each integer m, (me)d ≡ m (mod n). Your program should handle n up to 24096 in 1TB space, but not necessary reaso...
stackexchange_codegolf
Suppose you have a set of sets of integers. It's possible that some of the sets will overlap (i.e. sharing elements). You could get rid of the overlaps by deleting elements from the sets, but then some of them might end up empty; that would be a shame. Can we make all the sets disjoint without emptying any of them? Not...
stackexchange_codegolf
Description Output the rhyme scheme for a very long Terza Rima. Input None. Output ABA BCB CDC DED EFE FGF GHG HIH IJI JKJ KLK LML MNM NON OPO PQP QRQ RSR STS TUT UVU VWV WXW XYX YZY Rules You can pick between separating stanzas with whitespace or newlines, so either: ABA BCB... OR ABA BCB ... A single trailing whit...
stackexchange_codegolf
Task Given 2 positive integers n and k, where n > k, output the number of surjections from a set of n distinguishable elements to a set of k distinguishable elements. Definition A function f: S → T is called a surjection if for every t∈T there is s∈S such that f(s) = t. Example When n=3 and k=2, the output is 6, since ...
stackexchange_codegolf
​Your task is to write a program or function that outputs the first character of its source code, then the second, then the third... each time it is run. For example, if your program was foo in language bar in file baz.bar, then you should get output similar to this: λ bar baz.bar f λ bar baz.bar o λ bar baz.bar o You...
stackexchange_codegolf
Given a list of activities and their start time/date, output an ASCII-art calendar showing the activities on the appropriate days. All activities are guaranteed to be in the same month, no two activities will be on the same day, and all activities are guaranteed to fit within the calendar box. The calendar has the date...
stackexchange_codegolf
No, not that thing in powerpoint You will be given a string, and a 2D array of boolean values. The 2D array will represent a picture. You will be creating art out of it. Let me show you how. The steps to art First, you create a square which fits the 2d array, with the string. Like if the string is 'PPCG', and the pic...
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
Write a program which plays Russian Roulette! If the program is started, there should be a 5 in 6 chance of it ending normally after printing "I survived!" there should be a 1 in 6 chance of the program crashing. (segmentation fault, etc.) No input, and no other outputs are allowed. The randomness must be fair: it m...
stackexchange_codegolf
Problem A fact you may have noticed about factorials is that as \$n\$ gets larger \$n!\$ will have an increasing number of \$0\$s at the end of it's base \$10\$ representation. In fact this is true for any base. In this challenge you will be given a base \$b > 1\$ and an integer \$n > 0\$ and you will determine the sm...
stackexchange_codegolf
(I'm not a chemist! I might be wrong at some stuff, I'm writing what I've learned in high-school) Carbon atoms have a special attribute: They can bind to 4 other atoms (which is not that special) and they stay stable even in long chains, which is very unique. Because they can be chained and combined in a lot of differe...
stackexchange_codegolf
You will need to evaluate the definite integral (bounded by \$a\$ and \$b\$) of a certain polynomial function that takes the form of: $$\int_a^b \left( k_n x^n + k_{n-1} x^{n-1} + \cdots + k_2x^2 + k_1x + k_0 \: \right) dx$$ Normally, this can be done using the fundamental theorem of calculus and power rules. For examp...
stackexchange_codegolf
A narcissist program is simple. It is related to a quine. If the input is equal to it's source code, it prints a truthy value, if not it prints a falsy one. That is it. Rules: It can't read it's own file. This is code-golf, so the shortest answer wins. Hash functions are not allowed. This trivializes it into just s...
stackexchange_codegolf
Derived from this, now deleted, post. Given a string, answer (truthy/falsy or two consistent values) if it constitutes a good Bishop password, which is when all the following conditions are met: it has at least 10 characters it has at least 3 digits ([0-9]) it is not a palindrome (identical to itself when reversed) Y...
stackexchange_codegolf
Project Euler Problem 387 states: A Harshad or Niven number is a number that is divisible by the sum of its digits. 201 is a Harshad number because it is divisible by 3 (the sum of its digits.) When we truncate the last digit from 201, we get 20, which is a Harshad number. When we truncate the last digit from...
stackexchange_codegolf
Inspired by this chat message Your task will be to take a word and find the average position of its letters on the keyboard as a letter. Keyboard Layout Since layouts vary from keyboard to keyboard, we will be using a standard based of of my own keyboard in this question. The keyboard has 3 rows, the top row from lef...
stackexchange_codegolf
The knight is a chess piece that, when placed on the o-marked square, can move to any of the x-marked squares (as long as they are inside the board): .x.x. x...x ..o.. x...x .x.x. Eight knights, numbered from 1 to 8, have been placed on a 3×3 board, leaving one single square empty .. They can neither attack each other...
stackexchange_codegolf
TASK print integers n, where 12 <= n <= 123456789, and all pairs of consecutive digits in n have the same positive difference between them (e.g. 2468 but not 2469). NO INPUT. Output: 12 13 14 15 16 17 18 19 23 24 25 26 27 28 29 34 35 36 37 38 39 45 46 47 48 49 56 57 58 59 67 68 69 78 79 89 123 135 147 159 234 246 258 3...
stackexchange_codegolf
Conways' Game of Life is a well known cellular automaton "played" on an infinite grid, filled with cells that are either alive or dead. Once given an initial state, the board evolves according to rules indefinitely. Those rules are: Any live cell with 2 or 3 living neighbours (the 8 cells immediately around it) lives ...
stackexchange_codegolf
Given a non‑empty string containing only printable ASCII (codepoints 0x20 to 0x7E), write the shortest program or function that swaps the cases of A-Z and a-z. If a character is in [A-Z], convert it to its lowercase version. If a character is in [a-z], convert it to its uppercase version. Otherwise, leave the characte...
stackexchange_codegolf
Make a program that takes a length and list of intervals and outputs a ruler of that length with longer ticks for each interval using the line drawing characters ┌ ┬ ┐ │ ╵ The first row of the output should begin with the tick for 0 with ┌ and end with a tick for the length with ┐, with a ┬ being used for every charac...
stackexchange_codegolf
The Fabius function is an example of a function that is infinitely differentiable everywhere, yet nowhere analytic. One way to define the function is in terms of an infinite number of random variables. Specifically, given a sequence of independent random variables \$\{U_n\}\$, where each \$U_n\$ is uniform on the inter...
stackexchange_codegolf
In atomic physics and quantum chemistry, the electron configuration is the distribution of electrons of an atom in atomic orbitals. For example, the electron configuration of the neon atom is 1s2 2s2 2p6 (From Wikipedia) Challenge Your challenge is to take a number representing the atomic number of an element and out...
stackexchange_codegolf
Curry is the Language of the Month this month and some users are starting to get into it, so let's get some tips together. Haskell and Curry are similar in a lot of ways and a lot of tips for Haskell work well in Curry and vice versa. So I'd like in this question to gather tips for code-golf in Curry, that would be use...
stackexchange_codegolf
Your goal is to write a program that prints the string abc in two languages. However, while the full code will print abc in one language (we'll call it Language 1), the other one (Language 2) must print abc if (and only if) every other character is skipped starting from the second character. If the full code is run in ...
stackexchange_codegolf
Imagine this short function to clamp a number between 0 and 255: c = n => n > 0 ? n < 255 ? n : 255 : 0 Is this the shortest possible version of a clamp function with JavaScript (without ES.Next features)? P.S: Not sure if it's relevant but, the 0 and 255 are not random, the idea is to clamp a number as an 8-bit unsig...
stackexchange_codegolf
Your goal is to write a program that takes no input and outputs the following text: ca e na ŋa va o sa; þa ša ra la ła. ma a pa fa ga ta ča; în ja i da ða. ar ħo ên ôn ân uħo; carþ taŋ neŋ es nem. elo cenvos. But there's a catch: for each letter (any character whose general category in Unicode starts with L) in your s...
stackexchange_codegolf
Power Grid Resource Costs Introduction In the board game Power Grid, an integral part of the game is the act of buying resources to fuel your power stations. There are four types of resource used in the game (five, if you include renewable energy, but obviously you can't buy resources for that). These are Coal, Oil, Ga...
stackexchange_codegolf
A special case of Ramsey's theorem says the following: whenever we color the edges of the complete graph on 18 vertices red and blue, there is a monochromatic clique of size 4. In language that avoids graph theory: suppose we place 18 points around a circle and draw all possible line segments connecting them in one of...
stackexchange_codegolf
Consider a binary operator \$*\$ that operates on a set \$S\$. For simplicity's sake, we'll assume that \$*\$ is closed, meaning that its inputs and outputs are always members of \$S\$. This means that \$(*, S)\$ is a magma Let's define some basic terms describing the properties of \$*\$. We can say that \$*\$ can have...
stackexchange_codegolf
Challenge: Given an NxN matrix where \$N\geq2\$ and one of eight distinct 'folding options', output a 2D array/list with the subtracted values. The eight folding options are: left-to-right; right-to-left; top-to-bottom; bottom-to-top; topleft-to-bottomright; topright-to-bottomleft; bottomleft-to-topright; bottomright-t...
stackexchange_codegolf
Description a typeracer is an apps where user could type and evaluate their typing speed and accuracy. Criteria User could type "A quick brown fox jumps over the lazy dog." A visual indicator of each wrong character typed. A visual indicator of what characters to type. A visual indicator of what has been typed A visua...
stackexchange_codegolf
Edit (Jan 24/2021): The original specification for the challenge had a few problems. Underneath the original text, I have added alternate conditions that were suggested by @caird-coinheringaahing (thanks for the tips). There is a gameshow in the UK called "Countdown", and a parody called "8 out of 10 Cats does Countdow...
stackexchange_codegolf
Inspired by this building (United States Air Force Academy Cadet Chapel, Colorado) Your task is simple, given a positive integer n, output the spiked building to size n Testcases 1 -> ^ /|\ /.|.\ /..|..\ _______ 2 -> ^ ^ /|\/|\ /.|..|.\ /..|..|..\ __________ 7 -> ^ ^ ^ ^ ^ ^ ^ /|\/|\/|\/|\/...
stackexchange_codegolf
This construction is a way of representing the Natural Numbers. In this representation, 0 is defined as the empty set and for all other numbers, n is the union of {0} and {n-1}. For example to construct 3 we can follow the algorithm: 3 = {ø, 2} = {ø, {ø, 1}} = {ø, {ø, {ø}}} Task As you may have guessed your task is t...
stackexchange_codegolf
Given a position with a row of rooks and/or empty spaces, output how many different rook moves are possible. A rook can move left or right to an empty space, but not to one that requires passing over another rook. When a rook moves, the other rooks remain in place. For example, from this position, 6 moves are possible:...
stackexchange_codegolf
Let's say I have a condition expression x and that I want to check if it is TRUE or FALSE depending on the value of a boolean y: y ? x : !x Is there a way to express it without repeating x expression? Something like how we can get a number or its opposite depending on a bool, without repeating the number in the expres...
stackexchange_codegolf
Here's an example IRC log (this will be your program's input): [01:00] == User [*****] has joined #Channel [01:00] == ChanServ [ChanServ@services.] has left #Channel [] [01:00] == mode/#Channel [+o User] by ChanServ [01:00] <Bot> Welcome, User! [01:01] <User> Hello bot [01:02] <Bot> Hi there [01:38] <OtherUser> I like ...
stackexchange_codegolf
Introduction An abstract syntax tree (AST) is a tree of tokens that shows their connection to each other and syntactical meaning. They are commonly used in compilers and static analysis tools, as parsing a language into an AST helps remove any ambiguity and can be helpful for optimizations. Many ASTs are large and comp...
stackexchange_codegolf
Introduction Super Mario 64 has a heavily overcomplicated RNG, ably explained here by Pannenkoek. I thought it might be interesting to implement it. Challenge Implement the RNG function, except for the two special cases. (Not part of the below description; everything below is what you should implement.) Input and outp...
stackexchange_codegolf
Given infinite different integers, order them into a sequence \$a_1, a_2, a_3, ...\$ such that \$a_i>a_{i+1}\$ iff \$i\$ is even(or odd, as long as it's constant for all possible inputs and all \$i\$). In other word, make the sequence go alternately up and down (or down first, as long as it's constant). Examples: ℤ => ...
stackexchange_codegolf
Background In Scrabble, players take turns placing tiles on a grid so that each contiguous set of (more than one) tiles in every row and column makes a word. In one play, tiles can be placed anywhere in a single row or column as long as there is a contiguous set of tiles that includes all of the ones placed.1 A word is...
stackexchange_codegolf
Your challenge is to read a "password" from the keyboard / standard input. Challenge: Read a string s invisibly. For each of the characters in s, print a character c. In realtime. Rules: You must print c in realtime. As soon as the user enters a character you must display c. c must be constant, i.e. it must be the s...
stackexchange_codegolf
421 is a rather popular dice game in France and some other European countries. It is mostly played in bars and pubs to determine who's going to buy the next round of drinks. The full game is usually played in two rounds, with tokens that each player tries to get rid of, but this is irrelevant here. (Wikipedia page in F...
stackexchange_codegolf
Inspired by http://meta.codegolf.stackexchange.com/questions/547/write-a-code-golf-problem-in-which-script-languages-are-at-a-major-disadvantage question on meta, I've decided to make a question which could be problematic for scripting languages. The goal is to calculate fast inverse square root, just like it was done ...
stackexchange_codegolf
Intro You like cats. Naturally, you like cat’s games in tic-tac-toe. So, you’ve come up with a little party trick. You ask someone what square on the board they want you to make a move in. And you ask someone else on which turn they want you to make that move. You also let that person decide whether you play Xs or Os. ...
stackexchange_codegolf
Given a string as input find the longest contiguous substring that does not have any character twice or more. If there are multiple such substrings you may output either. You may assume that the input is on the printable ASCII range if you wish. Scoring Answers will first be ranked by the length of their own longest ...
stackexchange_codegolf
Squares looks symmetric, and so are the required codes. Objective: Write a program whose source code is a solid square (N lines with N printable, non-whitespace characters each line) and prints a square of equal size. A program (or output) with inconsistent width and height is invalid. (e.g. 6x5) Example (HQ9+) QAA AAA...
stackexchange_codegolf
(Inspired by last week's Riddler on FiveThirtyEight.com. Sandbox post.) Given a year between 2001 and 2099, calculate and return the number of days during that calendar year where mm * dd = yy (where yy is the 2-digit year). 2018, for example, has 5: January 18th (1 * 18 = 18) February 9th (2 * 9 = 18) March 6th (3 *...
stackexchange_codegolf
Your challenge is to create the longest run of characters with incrementing Unicode codepoints in a pristine program as you can. To keep things simple, I'll abridge the definition for this challenge to be "any program which produces no errors but will error if any one character is removed". Let's define a codepoint run...
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
Given integers 0<x<10106 and 0<n<106, work out x(1/n) under 15 seconds(TIO or your computer), 1GB memory. You can assume the result is integer smaller than 50000. Shortest code in bytes in each language win. Sample: x n result 121 2 11 123 1 123 1024 10 2 A larger sample can be seen here
stackexchange_codegolf
Introduction Many old chess books use descriptive notation to notate squares on a chessboard, naming the file (column) of the square based on the starting piece positions of White or Black, depending on whose move it is. The ranks (rows) are numbered 1 through 8, with 1 being closest to the player. For example, from Wh...
stackexchange_codegolf
This is the cops' thread. See the robbers' thread here. In this cops and robbers challenge, the cops will be tasked with writing an algorithm that computes some function of their choice, while the robbers will try to come up with their algorithm. The catch is, the 'algorithm' must be a single closed-form mathematical e...
stackexchange_codegolf
Inspired by this question on AskUbuntu. Your job is extremely simple. Take the PATH environment variable (echo $PATH) and export it such that each entry (separated by the : character) is on its own line. For example, if the PATH is /bin:/usr/bin:/usr/local/bin, your program should output: /bin /usr/bin /usr/local/bin ...
stackexchange_codegolf
I enjoy participating in math competitions run by Mu Alpha Theta, a mathematics honor society in the United States. At competitions, I take a 30-question multiple choice test. There are five choices per question, labeled A through E. My score on a test is four points for each correct answer, zero points for a question ...
stackexchange_codegolf
Question: Print out all the coordinates of a NxN grid. Preferably in C, however other languages also accepted Input: N (integer) Output: for N=3, a 3x3 grid: 0,0 1,0 2,0 0,1 1,1 2,1 0,2 1,2 2,2
stackexchange_codegolf
The question uses C to formulate the problem, but solutions in any language can be accepted. At the end of the question you can find a pythonic version. As part of a bigger software, we have a C function: void wrapper(void* p); Which is a wrapper function around the C function: void handler(void* p); wrapper() is tri...
stackexchange_codegolf
Given an input integer n >= 10, output the average of all deduplicated rotations of the integer. For example, for input 123, the rotations are 123 (no rotation), 231 (one rotation) and 312 (two rotations). The average of those is (123 + 231 + 312) / 3 or 222. As another example, take 4928. The rotations are 4928, 9284,...
stackexchange_codegolf
Challenge Display Inky the ghost from Pac-Man using only ANSI escape codes. Here's a text representation of the image B B B B B C C C C B B B B B B B B C C C C C C C C B B B B B C C C C C C C C C C B B B C W W C C C C W W C C C B B W W W W C C W W W W C C B B E E W W C C E E W W C C B C E E W W C C E E W W C C C C C W...
stackexchange_codegolf
Definition From the description on OEIS A006345: To find a(n), consider either a 1 or a 2. For each, find the longest repeated suffix, that is, for each of a(n)=1,2, find the longest sequence s with the property that the sequence a(1),...,a(n) ends with ss. Use the digit that results in the shorter such suffix. a(1) =...
stackexchange_codegolf
Special thanks to Bubbler and AdmBorkBork for supplying feedback about this challenge Keta (Keyboard tacit — clever naming, I know!) is a golfing language I’ve been working on recently. One of it’s features is it’s most probably unique bracket autocompletion system, which will hopefully allow for shorter programs. The...
stackexchange_codegolf
This is a successor to a previous challenge. Input An integer \$1 \leq n \leq 5\$. Task Your code should produce all strings that satisfy the following properties: Your string should contain exactly two each of the first \$n\$ letters of the alphabet. It should not contain the same letter twice in a row It must start ...
stackexchange_codegolf
Ah, Tinder . . . the app that takes the code golf approach to online dating. With just a few well-chosen right swipes and a bit of luck (or a cute puppy pic), you too could have more matches than /(?!)/. This code-golf challenge involves Tinder dates of a very different kind. Given a Tinder version number as input, hoo...
stackexchange_codegolf
As a terrible Latin student for several years I have learned to hate many things about Latin. However there is one thing I love. Latin scansion. Scansion is the act of determining the meter of a particular line of poetry. For Latin this means demarcating each syllable in the line as "light" or "heavy". In Latin scans...
stackexchange_codegolf
Sometimes, when writing a program, you need to use a prime number for some reason or other (e.g. cryptography). I assume that sometimes, you need to use a composite number, too. Sometimes, at least here on PPCG, your program has to be able to deal with arbitrary changes. And in circumstances conveniently contrived to m...
stackexchange_codegolf
The task Write a program or function whose input is a list/array X of integers, and whose output is a list of sets of integers Y, such that for each element e in each set Y[i], X[e] = i, and such that the total number of elements in the sets in Y equals the number of elements in X. (This is basically the same operation...
stackexchange_codegolf
Consider a n x n multiplication table and replace each item with its remainder of division by n. For example, here is a 6x6 table and its "modulo 6" structure: (The last column and row are ignored since both are null) 1 2 3 4 5 6 | 1 2 3 4 5 2 4 6 8 10 12 | 2 4 0 2 4 3 6 9 12 15 18 | 3 0 3 0 3...
stackexchange_codegolf
this is the follow-up question to Perfect Hangman in reverse golfers are now asked to develop a program that uses all rules in Perfect Hangman in reverse, instead, playing the player. the program shall ask how many letters you want the word to be, a single required letter, then pick what word is LEAST LIKELY to be gues...
stackexchange_codegolf
Getting the area covered by a rectangle is really easy; just multiply its height by its width. However in this challenge we will be getting the area covered by multiple rectangles. This is equally easy ... so long as the rectangles don't overlap. If the rectangles don't overlap the total area covered is the sum of th...
stackexchange_codegolf
Fermat's last theorem says that there there are no positive, integral solutions to the equation a^n + b^n = c^n for any n>2. This was proven to be true by Andrew Wiles in 1994. However, there are many "near misses" that almost satisfy the diophantine equation but miss it by one. Precisely, they are all the greater than...
stackexchange_codegolf
Input: A list of integers Output: Put each digit (and the minus sign) in its own lane, in the order -0123456789, ignoring any duplicated digits. Example: Input: [1,729,4728510,-3832,748129321,89842,-938744,0,11111] Output: -0123456789 <- Added as clarification only, it's not part of the output 1 2 7 ...
stackexchange_codegolf
What general tips do you have for golfing in Smalltalk? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Smalltalk (e.g. "remove comments" is not an answer). Smalltalk is a purely object-oriented language created by Alan Kay. The two links are GNU Small...
stackexchange_codegolf
Description While support is getting better and better for people to write in various scripts around the world using unicode, and now you can even write in emojis as well, unfortunately most fonts[citation needed] are still missing Latin characters based on the double acute accent, which is required to write properly i...
stackexchange_codegolf
Back-story After typing up your essay on your new Macbook, you look up at the screen and realize that you typed in ten pages of gibberish! Or is it? On further inspection, you come to find that your Option key was stuck this whole time and these special Option-key characters correspond to the ASCII keys on your keyboar...
stackexchange_codegolf
Concept In what ways can you scramble the English alphabet so that it can still be sung to the tune Twinkle Twinkle Little Star without ruining the tune? Rules Swapping Let's just assume the letters contained in each of the following sets can be swapped freely by default without ruining the tune: { A, J, K } { B, C, ...
stackexchange_codegolf
In this challenge, your task is to take an anion and a cation, and output the chemical formula of the compound. Input rules Take in 2 strings (in any order) representing the anion and cation, e.g. F, NH_4, or Al. To take in the charge of each ion, you can either have it as part of the string separated by a caret (e.g...
stackexchange_codegolf
A redox reaction is a chemical reaction in which elements transfer electrons. One element loses electrons, while another gains electrons. Oxidation is the process where an element loses electrons, and reduction is the process where an element gains electrons. Since electrons have a negative charge, the oxidation number...
stackexchange_codegolf
Given an integer greater than 1, output the number of ways it can be expressed as the sum of one or more consecutive primes. Order of summands doesn't matter. A sum can consist of a single number (so the output for any prime will be at least 1.) This is code-golf. Standard rules apply. See this OEIS wiki for related i...
stackexchange_codegolf
The Challenge In as few characters as possible, find the value of \$i^n\$, given \$n\$, a positive integer greater than 0. This should be outputted as a String. For those that don't know, \$i\$ is defined such that \$i^2=-1\$. So: \$i^1=i\$ \$i^2=-1\$ \$i^3=-i\$ \$i^4=1\$ This then repeats.. Rules If your language s...
stackexchange_codegolf
Your task is, given x, output 2*x. Easy right!? But there's a catch: x will be given as a (possibly infinite) continued fraction, and the output must be a continued fraction. The input is guaranteed to be a real algebraic number whose degree is at most 2. Input: The continued fraction of x. This is split into 3 parts: ...
stackexchange_codegolf
Write an \$n\$-bytes program \$AB\$ such that: it outputs an integer \$x,\ 0\lt x\lt n\$; both its \$x\$-byte prefix \$A\$ and \$(n-x)\$-byte suffix \$B\$, when run as programs, output \$AB\$. \$A, B\$ and \$AB\$ should: run in the same language not take any input use the same output method This is code-golf, so th...
stackexchange_codegolf
Introduction On the 26th of August, 2017, Floyd Mayweather, Jr. will face up to Conor McGregor in a boxing match. Both participants will receive the phenomenal amount of 100 million dollars! Unfortunately, we do not have the money yet, but we can already prepare the big briefcase that will contain all the banknotes. ...
stackexchange_codegolf
Challenge There are many numbers which can be expressed as the difference of two squares, or as the difference of two cubes, or maybe even higher powers. Talking about squares, there are various ways of writing a number, say 75, as the difference of 2 squares. You can write: 75 = (10)^2 - (5)^2 = (14)^2 - (11)^2 ...
stackexchange_codegolf