Introduction: When saying numbers out loud, the order is slightly different in Dutch than in English. For a number like \$1234\$: in English you'd say: one thousand, two hundred and thirty-four in Dutch you'd say: duizend-tweehonderdenvierendertig, or more readable with spaces: duizend twee honderd en vier en dertig [literally translated to: thousand two hundred and four and thirty] Note two things in this example: How in English we have 'thirty-four', yet the order in Dutch is 'four and thir...| Recent Questions - Code Golf Stack Exchange
Given the truth table of a non-trivial symmetric 2-input logic gate, output its name. The 6 possible input/output pairs are: 0001 -> AND 1110 -> NAND 0111 -> OR 1000 -> NOR 0110 -> XOR 1001 -> XNOR (where the 4 symbols represent the outputs of the gate for inputs 00,01,10,11 respectively). Input You can take the input format to be a single sequence "0001" or [0,0,0,1], or a 2-dimensional array [[0,0],[0,1]] or a function g with g(0,1)=0 etc. You do not need to handle input other than the 6 ca...| Recent Questions - Code Golf Stack Exchange
Goal You have to print the ASCII printable characters' code page (0x20-0x7E). The output should look like this: !"#$%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~ Rules The output should be exactly like shown above, but trailing whitespace is OK. No builtins that trivialize the question(e.g. the ones that print the ASCII table)! They can be posted for documentation purposes, but will not be in the leaderboards. Standard rules for I/O and loopho...| Recent Questions - Code Golf Stack Exchange
Given an input value \$n\$, construct an array of \$n\$ random 128 bit (unsigned) integers. The integers should be uniformly random. Your code can use any in built random number generation function it has or you can implement your own. Clearly this challenge is harder (and more fun) in lower level languages.| Recent Questions - Code Golf Stack Exchange
Challenge Write a program or function that converts a 32 bit binary number to its quad-dotted decimal notation (often used for representing IPv4) Quad-dotted decimal A quad-dotted decimal is formed like so: Split the binary representation into its 4 individual bytes Convert each byte into denary place "." between each number Example: input: 10001011111100010111110001111110 step 1: 10001011 11110001 01111100 01111110 step 2: 139 241 124 126 step 3: 139.241.124.126 I/O examples input --> output...| Recent Questions - Code Golf Stack Exchange
Challenge You have one string of input bytes, output only the last byte in it. Rules Your submission may be a program or function outputting the last byte in the input which is either a string, stdin or command-line arguments, and is non-empty. I was trying to solve this with brainfuck, however all languages are allowed to participate. This is code-golf. Examples "?" -> "?" "29845812674" -> "4"| Recent Questions - Code Golf Stack Exchange
Given a positive integer as input, your task is to output a truthy value if the number is divisible by the double of the sum of its digits, and a falsy value otherwise (OEIS A134516). In other words: (sum_of_digits)*2 | number Instead of truthy / falsy values for the true and false cases, you may instead specify any finite set of values for the true/false case, and their complement the other values. For a simple example, you may use 0 for the true case and all other numbers for the false case...| Recent Questions - Code Golf Stack Exchange
For any positive 32-bit integer (1 ≤ n ≤ 0xFFFFFFFF) output the number of bits needed to represent that integer. Test cases | n | n in binary | bits needed | |----------------------------------| | 1 | 1 | 1 | | 2 | 10 | 2 | | 3 | 11 | 2 | | 4 | 100 | 3 | | 7 | 111 | 3 | | 8 | 1000 | 4 | | 15 | 1111 | 4 | | 16 | 10000 | 5 | | 128 | 10000000 | 8 | | 341 | 101010101 | 9 | 4294967295 => 11111111111111111111111111111111 => 32 So f(16) would print or return 5 This is code-golf. Shortest code in...| Recent Questions - Code Golf Stack Exchange
Inspired by this question: Make a function (or a full program) that receives a list of numbers and outputs the list rearranged, so that even-indexed numbers appear first, and odd-indexed numbers follow. The values of the numbers themselves don't affect ordering - only their indices do. All indices are zero-based. For example: Input: [0, 1, 2, 3, 4] Output: [0, 2, 4, 1, 3] Another example: Input: [110, 22, 3330, 4444, 55555, 6] Output: [110, 3330, 55555, 22, 4444, 6] Use most natural represent...| Recent Questions - Code Golf Stack Exchange
Challenge Write a program that, given a string x which is 10 characters long and a character y, outputs the number of times character y occurs in string x. The shortest program in bytes to do so wins. Example Input: tttggloyoi, t Output: 3 --- Input: onomatopoe, o Output: 4| Recent Questions - Code Golf Stack Exchange
This is a relatively quick one, but I'm sure you'll like it. Codegolf a program that will take input in the form of a sentence and then provide the output with the first letter capitalized in each word. Rules: Submissions may not be in the form of a function. So no: function x(y){z=some_kind_of_magic(y);return z;} as your final answer... Your code must show that it takes input, and provides output. The code must preserve any other capital letters the input has. So eCommerce and eBusiness are ...| Recent Questions - Code Golf Stack Exchange
Problem: In your choice of language, write the shortest function that returns the floor of the base-2 logarithm of an unsigned 64-bit integer, or –1 if passed a 0. (Note: This means the return type must be capable of expressing a negative value.) Test cases: Your function must work correctly for all inputs, but here are a few which help illustrate the idea: INPUT ⟶ OUTPUT 0 ⟶ -1 1 ⟶ 0 2 ⟶ 1 3 ⟶ 1 4 ⟶ 2 7 ⟶ 2 8 ⟶ 3 16 ⟶ 4 65535 ⟶ 15 65536 ⟶ 16 18446744073709551615 ⟶ 6...| Recent Questions - Code Golf Stack Exchange
The Gray Code is a sequence of binary numbers of bitwidth n where successive numbers differ only in one bit (see example output). Reference Example input: 3 Example output: 000 001 011 010 110 111 101 100 Notes: This question seems to have a dupe but it's not, for that question is not a code-golf, and it demands different output. It will help to check out it's answers, though. You may assume a variable n which contains the input.| Recent Questions - Code Golf Stack Exchange
I always used a Mandelbrot image as the 'graphical' version of Hello World in any graphical application I got my hands on. Now it's your guys' turn. Language must be capable of graphical output or drawing charts (saving image files disallowed) Render a square image or graph. The size at least 128 and at most 640 across* The fractal coordinates range from approximately -2-2i to 2+2i The pixels outside of the Mandelbrot set should be colored according to the number of iterations before the magn...| Recent Questions - Code Golf Stack Exchange
So, you were sitting at your desk, golfing a program to calculate the first 20 digits of pi, and along comes your boss and throws your apple IIe out the window. You are now working on a new project...| Code Golf Stack Exchange
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
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 fo...| 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
Today Neil Sloane of the OEIS sent out an email asking for a confirmation of the current terms, and computation of some larger terms of the latest OEIS sequence A337663 with the keyword "nice". Here's how this sequence works: You label \$n\$ cells on the infinite square grid with \$1\$s, and then place the numbers \$2,3,4,\dots,m\$ in order, subject to the rule that when you place \$k\$, the sum of its [horizontal, vertical, and diagonal] neighbors must equal \$k\$. Then \$A337663(n)\$ is the...| 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
Enterprise Quality Code! TL;DR Answers will consist of a full program (of length < 30k) prints the the first N Prime numbers (as a base 10 representation without leading zeros unless the chosen language only supports unary or other based output) separated by newlines (optional trailing linefeed). You may post cracks at any time, but you must wait one hour after posting each initial bowled submission Leading or trailing whitespace is not acceptable (except for the trailing newline) An answer's...| 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
As of 13/03/2018 16:45 UTC, the winner is answer #345, by Khuldraeseth na'Barya. This means the contest is officially over, but feel free to continue posting answers, just so long as they follow the| 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
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