Divide 1 by a sum/difference of square roots Input: An expression that is a sum/difference of square roots of positive integers. You can assme it will not equal 0. The general form is \$\pm\sqrt{a_1}\pm\sqrt{a_2}\pm\sqrt{a_3}\pm\cdots\pm\sqrt{a_n}\$ where each \$a_n\$ is a positive integer. There is no guarantee the input will be sorted or that the radicals are fully simiplfied. Duplicate \$a_k\$ are possible. Example: \$\sqrt2+\sqrt3+\sqrt7+\sqrt7-\sqrt9+\sqrt{12}\$ Output: the inverse of th...| Recent Questions - Code Golf Stack Exchange
I was looking for a simple sequence that's not yet referenced on the OEIS and came up with this one(*): \$a_1=2\$ \$a_2=3\$ For \$n>2\$, \$a_n\$ is the smallest number of the form \$a_i\times a_j+1\$ (with \$1\le i\le j<n\$) that is not yet included in the sequence. The first few terms are: 2 3 5 7 10 11 15 16 21 22 23 26 31 33 34 36 43 45 46 47 49 50 51 53 56 63 64 67 69 70 71 73 76 78 79 81 87 91 93 94 95 99 Your task is to output this sequence. This is code-golf and standard sequencerules ...| Recent Questions - Code Golf Stack Exchange
Given the anti-clockwise points of a properly formed, non-self-intersecting, not-necessarily-convex polygon, render it as a filled ASCII art polygon. Input A series of at least 3 (x,y) pairs representing the points. It's up to you whether the first point is repeated as the last point to close the loop. x coordinates are integers in the range 1-78. coordinates are integers in the range 1-38. Output An 80x40 text field representing the range 0-79 x 0-39 (0,0 at the top left), consisting of spac...| Recent Questions - Code Golf Stack Exchange
The \$\text{argwhere}\$ function takes a list of values and a predicate/boolean function as arguments and returns a list of indices where the predicate function returns true in the input list. For example, argwhere([1, 2, 3, -5, 5], x -> x > 2) would produce an output of [2, 4] because those are the (0-indexed) indices whose values are greater than two. Challenge Implement the \$\text{argwhere}\$ function in your language of choice. Format For the purposes of this challenge, we will deal with...| Recent Questions - Code Golf Stack Exchange
Print integers 0 to 100 (inclusive) without using characters 123456789 in your code. Separator of numbers can be comma or white space (by default <blank>, <horizontal tabulator>, <newline>, <carriage return>, <form feed> or <vertical tabulator>). Shortest code wins.| Recent Questions - Code Golf Stack Exchange
What happens when the CapsLock key on your keyboard doesn't have a notch in it? "This hPPENS." The goal of this program is to consistently emulate keyboard misses where each A press is replaced with CapsLock. Uppercase 'A's from the source should yield the same effect. When CapsLock is enabled, capitalization is reversed. Test Cases "The quick brown fox jumps over the lazy dog." -> "The quick brown fox jumps over the lZY DOG." "Compilation finished successfully." -> "CompilTION FINISHED SUCCE...| Recent Questions - Code Golf Stack Exchange
Given a string of ASCII characters, output the character that is in the middle. If there is no middle character (when the string has an even length), output the ASCII character whose ordinal is the floored average of the two center characters. If the string is empty, an empty string should be output. Test cases: 12345 => 3 Hello => l Hiya => q (empty input) => (empty output) Shortest program in characters wins. (Not bytes.) Leaderboard The Stack Snippet at the bottom of this post generates th...| Recent Questions - Code Golf Stack Exchange
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the m...| Code Golf Stack Exchange
Let us define the operation of rebasing a number as writing out its digits in decimal form, then interpreting them in the smallest base N possible (2 <= n <= 10). For example, rebasing the number 1234 gives 194, since the smallest base that "1234" can be interpreted in is base 5, and "1234" interpreted in base 5 is 194 in decimal. Challenge Given a positive integer n, output n rebased as a decimal integer. Expected output Below is a list of the results of rebasing each number from 1 to 200: 1...| Recent Questions - Code Golf Stack Exchange
This challenge, while probably trivial in most "standard" languages, is addressed to those languages which are so esoteric, low-level, and/or difficult to use that are very rarely seen on this site. It should provide an interesting problem to solve, so this is your occasion to try that weird language you've read about! The task Take two natural numbers a and b as input, and output two other numbers: the result of the integer division a/b, and the remainder of such division (a%b). This is code...| Recent Questions - Code Golf Stack Exchange
Goal The goal of this challenge is: given a string as input, remove duplicate pairs of letters, if the second item in the pair is of opposite capitalization. (i.e. uppercase becomes lowercase and vice-versa). Pairs should be replaced from left to right. For example, aAa should become aa and not aA. Inputs & outputs: Input: Output: bBaAdD bad NniIcCeE Nice Tt eE Ss tT T e S t sS Ee tT s E t 1!1!1sStT! 1!1!1st! nN00bB n00b (eE.gG.) (e.g.) Hh3lL|@! H3l|@! Aaa Aa aaaaa aaaaa aaAaa aaaa The input ...| Recent Questions - Code Golf Stack Exchange
Long-time lurker, first-time poster. So here goes. In the Wikipedia page for quine, it says that "a quine is considered to be 'cheating' if it looks at its own source code." Your task is to make one of these "cheating quines" that reads its own source code. This is code-golf, so the shortest code in bytes - in each language - wins. This means that a 5-byte Pyth script would not beat a 21-byte Python script - but a 15-byte Python script would. You must use file I/O to read the source code, so ...| Recent Questions - Code Golf Stack Exchange
Challenge Given a list of numbers, calculate the population standard deviation of the list. Use the following equation to calculate population standard deviation: Input The input will a list of integers in any format (list, string, etc.). Some examples: 56,54,89,87 67,54,86,67 The numbers will always be integers. Input will be to STDIN or function arguments. Output The output must be a floating point number. Rules You may use built in functions to find the standard deviation. Your answer can ...| Recent Questions - Code Golf Stack Exchange
Deleted questions on Stack Overflow sometimes make for great golf material. Write a function that takes a nonnegative integer as input, and returns true if all the digits in the base 10 representation of that number are unique. Example: 48778584 -> false 17308459 -> true Character count includes only the function. If you choose to answer in C or C++: no macros, no undefined behaviour; implementation-defined behaviour and compiler warnings are fine.| Recent Questions - Code Golf Stack Exchange
A redundantregular expression (regex) is defined here as a regex which has some amount of characters which can be removed while not affecting its functionality -- i.e. it matches the exact same set of strings. For example, code|codegolf is redundant since it can be reduced to code. You will be given a regular expression consisting only of lowercase letters and vertical bars (i.e. matching ^[a-z|]*$.) You should output a boolean (or equivalent) saying whether the regular expression is redundan...| Recent Questions - Code Golf Stack Exchange
Your challenge is to write a program that constantly prompts for input, and when input is given, output that five seconds* later. However, your program must continue prompting for input during that time. Since this is a bit confusing, here's a demo. <pre id=x></pre><input id=h onchange='var k=this;(()=>{let a=k.value;setTimeout(_=>document.getElementById("x").innerText+=a+"\n", 5000)})();this.value="";' > (Try typing multiple things into the box and pressing enter.) This is code-golf, shortes...| Recent Questions - Code Golf Stack Exchange
The Challenge Given an integer input x where 1 <= x <= 255, return the results of powers of two that when summed give x. Examples Given the input: 86 Your program should output: 64 16 4 2 Input: 240 Output: 128 64 32 16 Input: 1 Output: 1 Input: 64 Output: 64 The output may contain zeros if the certain power of two is not present in the sum. For example, input 65 may output 0 64 0 0 0 0 0 1. Scoring This is code-golf, so the shortest answer in each language wins.| Recent Questions - Code Golf Stack Exchange
Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index. In other words, if there are more than 1 duplicated numbers, return the number for which the second occurrence has a smaller index than the second occurrence of the other number does. If there are no such elements, your program / function may result in undefined behaviour. Example: For a = [2, 3, 3, 1, 5, 2], the output should be f...| Recent Questions - Code Golf Stack Exchange
Task - The title pretty much sums it up: raise an integer x to power x, where 0<x. Restrictions: Use of exponentiation, exp(), ln(), and any other powers-related language built-ins, like pow(), x^x, x**x is forbidden. You can assume that the given integer fits the limits of the programming language of your choice. Test cases: Input | Output --------------- 2 | 4 3 | 27 5 | 3125 6 | 46656 10 | 10000000000 --- This is code-golf, so the shortest program in bytes wins.| Recent Questions - Code Golf Stack Exchange
inspired by Count down from infinity Given a non-negative integer N, output the number of repetitions of the following steps it takes to reach 0: Convert N to binary (4812390 -> 10010010110111001100110) Flip each bit (10010010110111001100110 -> 01101101001000110011001) Trim leading zeroes (01101101001000110011001 -> 1101101001000110011001) Convert back to decimal (1101101001000110011001 -> 3576217) Rules Input and output may be in any unambiguous, consistent format The input will be within th...| Recent Questions - Code Golf Stack Exchange
For example, the gate A and B is a logic gate with 2 inputs and 1 output. There are exactly 16 of them, because: each logic gate takes two inputs, which can be truthy or falsey, giving us 4 possible inputs of the 4 possible inputs, each can have an output of truthy and falsey therefore, there are 2^4 possible logic gates, which is 16. Your task is to write 16 programs/functions which implement all of them separately. Your functions/programs must be independent. They are valid as long as they ...| Recent Questions - Code Golf Stack Exchange
Introduction In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other catalogue challenges, there is "Hello World!" and "Is this number a prime?". Challenge Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiple...| Recent Questions - Code Golf Stack Exchange
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 wh...| Code Golf Stack Exchange
Background Recently, I was installing updates on my pc with Pacman (I use arch btw) and noticed the order it downloaded files was like this Start with the largest 4 downloads When a download completes, start downloading the next biggest file. Since the biggest file takes the longest to download, you'll often see the second or third biggest actually complete first. Interesting. Challenge Given a list of download sizes, eg 50, 40, 30, 20, 11, and the amount of downloads that can be running simu...| Recent Questions - Code Golf Stack Exchange
Write the shortest code, in number of bytes, to display, return, or evaluate to the golden ratio (that is, the positive root of the quadratic equation: \$x^2-x-1=0\$, approximately 1.61803398874989...| Code Golf Stack Exchange
Write a program that takes a string and outputs all the characters in alphabetical order. Spaces and symbols can be ignored or deleted, but the upper‑ and lowercase letters must remain the same case.| Code Golf Stack Exchange
We are all familiar with the famous Fibonacci sequence, that starts with 0 and 1, and each element is the sum of the previous two. Here are the first few terms (OEIS A000045): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584 --- Given a positive integer, return the closest number of the Fibonacci sequence, under these rules: The closest Fibonacci number is defined as the Fibonacci number with the smallest absolute difference with the given integer. For example, 34 ...| Recent Questions - Code Golf Stack Exchange
Write the shortest function to convert an IP address into its integer representation and output it as an integer. To change an IPv4 address to its integer representation, the following calculation is| Code Golf Stack Exchange