instruction
stringlengths
34
53.1k
Let n be the number of times your program has been executed. If n is a power of 2, then print 2^x where n = 2^x; otherwise, simply output the number. Example run: [1st time] 2^0 [2nd time] 2^1 [3rd time] 3 [4th time] 2^2 [5th time] 5 and so on. This is a popularity contest, so the answer with the most upvotes wins..
You have to make a game Too-low --- Too-high (TLTH) in shortest code (in bytes) Game rules: Computer will choose a random number out of integer range (-32768..32767). Now you will think of a number and input it. The computer will tell if your number is lower (TOO LOW) or higher (TOO HIGH) than the chosen number. W...
I challenge you to write a code to make an (extended) ASCII-art logic gate diagram for the sum of products form of an equation. Use the following notation to represent gates: AND INPUT───|&& |&&───OUTPUT INPUT───|&& OR INPUT───|OR |OR───OUTPUT INPUT───|OR Gates with more...
A rhyming program you write Attempting to win the fight For winning the contest and vote It must compute "Hello World" Then print it very polite The most popular poem will win. The requirements are: The poem should be of 5 lines with rhymes AABBA It can print whatever you want, but the output should contain "hello wo...
Inspired by the Google Code Challenge: The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below....
Undefined Behavior Killed My Cat It's well known that undefined behavior can kill your cat [citation needed]. But can it? Your Task Write a program that invokes undefined behavior. Describe a scenario that starts with the above program being run, resulting in a Felis catus ending its life while in your ownership, as a...
Task: I know we can all add two numbers the short way, using +. Your task is to create the longest code you can to add two input numbers. Rules: All of the code must be on topic (don't fill it with non-addition code to add length) The count is in characters, but do not count tabs, spaces, or newlines. Do not use extra...
In a chatroom with a few people, a topic came up between me and them about how many possible strings a regex could match. Your task is to build a program that can answer that question. Your program will accept, as input, any regular expression as defined in this document as an "extended regular expression", such as: ^[...
In 1946 Erdos and Copeland proved that a certain number is a normal number, i.e. the digits in its decimal expansion are uniformly distributed. Users will input a sequence of digits and you will find the smallest prime that contains that string in base 10. Example: input -> output "10" -> 101 "03" -> 103 "222" ...
This is a really neat short challenge. Write a function or a procedure that takes two parameters, x and y and returns the result of xy WITHOUT using loops, or built in power functions. The winner is the most creative solution, and will be chosen based on the highest number of votes after 3 days.
Provided a digit between 0 and 9 (inclusive), your function/subroutine should print all numbers between -100 and 100 (inclusive) that contain the given digit. For example: Input: 9 Output: -99 -98 -97 -96 -95 -94 -93 -92 -91 -90 -89 -79 -69 -59 -49 -39 -29 -19 -9 9 19 29 39 49 59 69 79 89 90 91 92 93 94 95 96 97 98 99 ...
Your goal is to write "Hello, World!" (minus the quotes). This is a popularity-contest, so most up votes wins. Code length will be used to break ties. Anything goes, as long as it is within the following rules: All characters must be either letters or numbers, so you may only use characters in the string "abcdefghijk...
Your challenge today is to cheat at badges! You will build a bot that will connect to a Stack Exchange site, log in as you, visit the /questions page, visit a question, and then visit 9 other questions in the "related" sidebar (because that seems sufficient to count as "activity," and I need to standardize on something...
The challenge is: generate an audio file made of white noise. Requirements and instructions: Your program must generate an audio file containing only white noise, meaning its intensity is the same for all (reasonable) frequencies and nonzero [see an example plot]; One must be able to play the audio file on the latest ...
Write the shortest code that will take any real number greater than 1 as input and will output its positive inverse factorial. In other words, it answers the question "what number factorial is equal to this number?". Use the Gamma function to extend the definition for factorial to any real number as described here. For...
We all know that programmers tend to be lazy. In order to maximize your free time, you decide to write a program that outputs a minimal number of keystrokes for text fed into it. Input: Text that has to be converted into keystrokes. You may decide on how to input the text (STDIN / reading from a file provided in the a...
You have to create a code which prints :) a random number of times from 1 to 255 inclusive. Your output may not contain any whitespace. Your score : The count in bytes EDIT : Also show 3 outputs of your code
Challenge Recognize ASCII art numbers. To make things interesting, three random points in the image might be flipped. For example: ***** * ** ** ** ** ** Input A 7x7 ASCII art number generated by the below Python script. Output A digit. Testing script Here's a Python script (2.6+) to generate...
Code golf: Print an image of the source code. Requirements Must output the image of the source code itself, not a version stored elsewhere and retrieved at run time. Code must be legible enough to copy out by hand and reproduce the results. Any image format is applicable. Bonuses -10% of your score if you allow mor...
Write the shortest POSIX-form regular expression that matches only non-negative integers divisible by 9. The non-negative integer should be given in base 10.
In Twitch Plays Pokémon, one of the most annoying obstacles one can face is an ice puzzle, where you must travel from one place to another by sliding all the way in one direction until you either hit a wall or a boulder. Your task is to build a program that will generate a random difficult ice puzzle. Your program will...
Your task is simple. Write a program that should obviously produce an error on first glance either when compiled or run, but either doesn't or produces some other unrelated error. This is a popularity contest, so be creative.
The Problem A doomsday scenario is described by three numbers on a single line, n, m, and p. Following that line are n lines with m values per line. Each value represents the total units of water each cell can hold. The following p lines describe the weather for the next p days. 1 unit of rain falls on a single cell ea...
Write a program that takes two lines of input and uses the first as a key phrase to encrypt the second according to the Playfair encryption technique. Wikipedia describes Playfair encryption in some detail, but to avoid any ambiguity, here's a brief summary: 1. Generate a key table: Replace all occurrences of J in the ...
Ever programmer knows, that programs need to be predictable. Any code that is not predictable will do something undefined and therefore most likely crash or worse. But when I tried to figure out what Java's lazySet() method does, I came up with the idea Is it possible to write a program that is unpredictable, yet works...
Write a quine... from which every other character can be removed it still be a valid quine. You can specify whether to start removing characters at the first or second character. Scoring criteria (add bonuses/penatly percentages together for total percentage): Answers must be at least 4 characters long Program must co...
…without using any operator/function besides addition (+), subtraction (-), multiplication (*), division (/), modulo (%), exponent/power pow() or any of the standard C bitwise operators (<<, >>, ~, &, |, ^) or unary operators (—, ++) or assignment/comparison operators (=, ==). If these symbols represent a different ope...
Your goal is to output an ASCII art pie chart. This is code-golf, so the shortest program (counting the bytes of the source code, not the characters) wins. No external softwares or APIs are allowed. Only the native ones of each language. The starting angle and the direction (clockwise/anticlockwise) of the circle are n...
Your program must take as input a line of characters, like this: @+.0 And output the characters sorted by how dark they are, like this: .+0@ Requirements: You must use a monospaced font for darkness detection. You must find out how many pixels each character takes up. You must actually draw the character and count p...
Write an object-oriented program that, when ran, outputs one complete example from each reserved-word-vise unique signature combination available to that language. Reserved words for primitive types are excluded. Each example should start from a new line. This implies that for all signatures any changes in parameters, ...
Imagine an ordered file set : file1, file2, ... fileN. Each file is a textual file that is made of lines that have the same format : A concatenation of a fixed-size key (the same among all the file set) and a variable length value. The merging algorithm is very similar to UPSERT : To merge 2 files: Iterate on all li...
Code Golfed Tetris Inspired by a popularity-question (Re)Implementing Tetris and a challenge on SO 3 years ago when PCG did not yet exist, the classy tetris has yet to live again in the art-work of PCG's golfers. So here are the features: Required: Game must be playable. Playfield or blocks are 10 in width and 20 in h...
Introduction Knowledgeable code golfers prepared us for the doomsday flood. Areas at risk were evacuated, and the population moved to high ground. We underestimated the flood (or perhaps there was a bug in @user12345's code). Some high-ground areas are rapidly approaching sea level. Walls must be erected in order to en...
Most of you have probably heard of the famous Turtle Graphics program, initially made popular by Logo. This challenge is to implement a Turtle Graphics program in your language of choice. Rules: The floor must be a diagonal with dimensions input by the user through std-in in the form x/y, representing the x and y len...
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 files disallowed) Render a square image or graph. The size at least 128 and at most 640 across* The...
In the Pokemon video games, the player is sent out into the world to force wild animals into tiny balls and train them to fight. Of course, everyone knows that no one plays Pokemon for the battling. The real draw the series has is the pokemon catching itself! Your job is to simulate the pokeball during a capture attemp...
Well, when I buy gifts for my two wives, I want them to feel equally important to me, but it's hard to go shopping with fixed budgets. Instead, I buy a bunch of stuff and divide them into two groups with as equal value as possible. Then I buy a bunch of chocolates to fix the rest. But I don't want do all the hard lifti...
Your task is to write the shortest possible Pong game without human interaction, so AI plays vs AI. I assume all of you know Pong, just to make sure, this is the target (just as running code):http://www.youtube.com/watch?v=xeEFMhdnR6c The following game rules apply: No ASCII "graphics". You must actually have code to ...
Yesterday at work, the Google Doodle convinced me to share my rather long gender swap script here, but the code-golf criteria of the question i asked were not clear. As my question still got downvoted after giving examples, i changed the tag to popularity-contest, as suggested before i clarified it. Here's a more golfy...
To solve the Halting Problem you are given a description of a program, and must determine whether or not it will ever finish. You can never do this for all programs. Yet for programs like (in brainf***): > It obviously will halt, and for programs like: +[] It obviously will not. Your challenge is to "solve" the halti...
Implement a program or function which simulates common dice for role playing games. It should handle at least the d6 and d20, the two most common dice. However, it should work as stereotypical gamers expect them to work, and not as real dice work. It is an in-joke between gamers, that one can have a specially lucky die...
Write a series of programs in the same language that print “Hello, world!” using n distinct source characters, where n is in [1..10] inclusive (“distinct” meaning that duplicate characters are ignored from character count). The winner is the solution with the most programs, each with distinct n. I suggest making one so...
The results are in, the contest is over. The winner is arshajii's EvilBot with 14 wins ahead of Neo-Bot with 13 wins and CentreBot and LastStand with 11 wins each. Scores from the final run Results: java Rifter: 9 match wins (45 total bout wins) java EvadeBot: 10 match wins (44 total bo...
What is some of the coolest/best/worse abuses of CSS? For example, these shapes, or using multiple box-shadows to make pixel art. popularity-contest ending on 16/04/14.
This challenge asks you to draw the Eiffel Tower in 3D using different ASCII characters to represent the different sides, similar to this cube: @@@ @@@@@@@@@ @@@@@@@@@@@@@@@ x@@@@@@@@@@@@&& xxx@@@@@@@@&&&& xxxxx@@@&&&&&&& xxxxxx&&&&&&&&& xxxxx&&&&&&& xxx&&&& x&& Here is a picture of the Eiffel Tower ...
The task is to make a function which returns random number, no build in functions allowed, returned value should be random or pseudo-random and no sequence allowed, no matter what the formula is and how scattered values are. To simplify task, returned value should be 32-bit integer or float from range [0; 1) It is code...
Context: We are working on a complex image drawing program to produce mugs, t-shirts, and so on. Here is an example of such function However, we are facing the following problem: Random generated functions are mostly white and black (where black is close to zero and white close to infinity). The idea of this contest i...
It's time for some quines! Well, sort of. This challenge is to create the smallest program that could move around in memory, i.e. if a program is resident in 2000:0100, the program should move to say, memory address be7a:3470. Rules The memory address to move in should be pseudorandom. It's still valid if it's a mov...
Syntax ~ not /\ and \/ or t true f false P, Q, FISH, etc: variables (Operators are given in order of precedence) Introduction Some boolean formulae can be changed to different forms to make them shorter. For example, the formula ~(~P /\ ~Q) can be changed to the shorter form P\/Q while the formula P \/ ~P can be cha...
A troll has captured you and is forcing you to write malware (defined as a program that damages the computer that runs it). The troll can read and understand code, but is not so good at spotting bugs. Your goal is to write a program that: Looks like malware; i.e., a beginning programmer reading the code will be convin...
Introduction The rain finally subsided. Most of humanity drowned due to a bug in @user12345's code. Survivors are scattered across a worldwide archipelago. Radio communication is up, and humanity is poised to thrive once more. For no reason whatsoever, zombie pirates have gathered at the Prime Meridian, and are sweepin...
public int UndocumentedCode(int a, int b) { while (true) { a -= b; b += a; a = b - a; if (b < a) { return b; } else { b += 1; } } } First figur...
Write a program in language A which outputs a program in language B where: Language A != Language B The output is itself a solution to this question. This is a popularity contest. If you want to define your own BNFs/grammars for this, feel free, but try not to make it too boring by doing so. EDIT: The more languages...
You know that your language's clock/time API's are broken and they are not reliable at all. So you are not allowed to use any built-in API to access system time/date. But you also know that your language's ability to perform date math, and retaining a date/time value in a variable are correct. Write a program that prin...
My robot has short circuited somehow and randomly run off somewhere from my lab! Luckily, whenever he does this, his shut-down sequence initiates, giving him enough time to randomly turn and run in the direction its facing for five rounds before he switches off. His gyro and accelerometer functions are still relaying t...
The Challenge: In this question: Name the poker hand you had to take a five card poker hand and identify it. This question is similar, with two twists: First, the output will be in all lower case. This allows for more golfing, as you don't have to worry about the capitalization of flush and straight high card one pair ...
Write a plain TeX program that lists the first two hundred primes (in base-10 notation). Including external files/resources is not permitted. The output may be to the terminal, the log file, or the actual dvi/pdf file, at your option, but should be easily readable to a human; in particular, there must be some delimiter...
In project management there's a method, called the critical path method, that is used for scheduling activities and for determining which activities' timings are crucial (i.e. critical) and for which activities the schedule offers a timing tolerance. Your program's task is to order a set of activities chronologically a...
Introduction You are alone on an island. The remainder of humanity is dead (probably due to the bug in user12345's code). The Zombie Pirate Horde has reached your island, and they are endless. It's time to kick ass or chew bubble gum, and you're all outta bubble gum. Problem Our doomsday scenario is described by 2 inte...
Imagine you are working on a 3D adaptation of the classical video game Asteroids. Your task is to write an algorithm that can create a random 3D asteroid. This is a popularity contest, not code golf. Write nice code and create interesting results. Add other cool features if you want. Rules: Your algorithm must actuall...
You are too make a program that take an integer as the input and outputs the first what ever that number was of the look and say sequence. For example: $ ./LAS 8 [1,11,21,1211,111221,312211,13112221,1113213211] The exact way you output the list is unimportant, as long as users can distinctly see the different numbers ...
4, 8, 15, 16, 23, 42 Write a program that outputs this sequence of numbers infinitely. However, The Numbers must not appear in your source code anywhere. The following is not a valid Java program to output The Numbers because The Numbers appear in its source code: class TheNumbers { public static void main(String[]...
You and a friend walk into a bar. The bartender treats you well, so you decide to tip him. So you pull out your trusty pocket computer and write a quick program to calculate a tip for you since it has no built in calculator. But wait! Your operator keys are broken! Your task is to calculate a 20% tip for any given inpu...
Finding primes is a programming rite of passage and very frequently the first serious program someone creates (usually with trial division). But primes alone are already worn out. A next far more interesting thing is to get the prime gaps: the so-far-longest gaps between consecutive primes. These are quite rare and "pr...
Your task is simple. Determine if one string equals the other (not address, the value) without the use of equality operators (such as ==, ===, or .equal()) or inequality (!=, !==) anything similar for other languages. This means anywhere! You may not use these operators anywhere in the code. You may however, you use to...
Input will be one or more space separated characters followed by a long string on STDIN or as an argument when called from the shell. a C WAtcIaElCpVqDRavOUejlgumcRCpfIWlaRFZpIoPYsWjsBSdlYfitfAPHpemiLpjaHheUGpFVQoZCnSCFgvpVzcoibdffoPRoJJwLIjVicPCdcvITXaQDjtMgrxQMZCkZNFmNqwGQYaSyPpdLOkAVHGVoVBiIksZCQHEaIxcRGwpIAmlChuhGE...
Introduction You belong to a council which oversees the destruction of corrupted worlds. When the council assembles, a single vote is taken. The ballot lists all nominated worlds. One is ultimately destroyed each time the council meets. Due to a bug in user12345's code, the council recently flooded and then sent pirate...
All these functional languages that return the same value every time a function is called give me a headache. Your task is to write a function that returns something different every time it is called. Here are the rules: Your function must continue to return something different every time it is run It must return a d...
You are to write a program that does one of the following. Only displays "Hello World" does nothing else Quits and nothing else (no output, no errors.) Takes one line of input, parses it as an integer, displays the first that many primes (or gives a nice error if it is given input that can't be parsed as an integer, o...
Your goal is to calculate the sum of Fibonacci series from n th term to m th term (including both terms). No use of / * % or mathematically what they are in your language of choice. No use of special functions or code language specialized in doing so ! You have to produce the series yourself and not by any special fun...
So I'd like you to attempt to generate Rorschach images like the below image: Here is a link to further inspiration. This is a popularity contest, but I will say that colours are likely to be more popular than black and white, as well as textures. Rorschach images are created by folding paper with ink on so one criter...
Your goal is to write a program / script which "converts" real images into ascii art. General: Your program will get a path to a image file over stdin or as parameter (whatever you prefer). The format will be jpeg. It should "convert" it to ascii art and save it to the harddrive. The image will be in grayscale. You don...
The Setup Jim the student who attempts to use Stack Overflow to do his homework has asked how to get his program to say "Hello World" in under 100 lines of code, you decide mere mortal trolling is not enough... The Challenge You need to provide Jim with a program less than 100 lines long that outputs a satisfactory ans...
We already generated Minesweeper fields, but someone really has to sweep those generated mines before PCG blows up! Your task is to write a Minesweeper Solver that is compatible with a slightly modified version of the accepted solution of “Working Minesweeper” (actions are separated by spaces to allow for larger fields...
2048 is an incredibly fun and addictive game in which the goal is to create a tile with 2048 on it. Here's a short description of the game: Pressing an arrow key will slide all the blocks in the stage in that direction. For example, if x represents a block, and you pressed the up arrow in this case: ...x .x.. ..x. xx....
Happy π Day. The goal of this question is to calculate the area for a circle of radius 3, where A = πr². The catch is that you have to use the constant π that is defined in a different language than the one you are programming in. For example, you can write a C program that uses Fortran's MATH::PI, or a Python program...
Write the shortest code that traverses a directory tree and outputs a flat list of all files. It should traverse the whole directory tree The order in which it enters sub-directories doesn't matter The directories should not be output The output should be a plain list — the definition is flexible, but it shouldn't con...
Explanation ¡Hola! For those of you who don't take Spanish, a verb is conjugated based on the person who does the action. Here's a chart: English Spanish I Yo You Tú He Él She Ella You (formal) Uste...
Write a program which gets a string as its input, and counts the number of alphanumeric and non-alphanumeric characters in it. It has to display its result like this: input: http://stackexchange.com output: 20 + 4 = 24 The catch is, your source code has to have the same number of alphanumeric characters as non-alphanum...
[Latest update: benchmark program and preliminary resuls available, see below] So I want to test the speed/complexity tradeoff with a classic application: sorting. Write an ANSI C function that sorts an array of floating point numbers in increasing order. You can't use any libraries, system calls, multithreading or inl...
You are to make a program that given a number, such as 22009, will go for example to Pi Calculation Code Golf. Then it will, for each answer, try to figure out what the code is, and count its characters. It will then output, for each answer, its number of characters, and a link to it. It should be sorted with fewest ch...
Definition A positive integer n is a practical number (OEIS sequence A005153) iff all smaller positive integers can be represented as sums of distinct divisors of n. For example, 18 is a practical number: its divisors are 1, 2, 3, 6, 9, and 18, and the other positive integers smaller than 18 can be formed as follows: ...
You have to make a golf game with the following specification :- The field is 10 X 10 characters without spaces. Free ground is represented by . A hole generated at random(not at 0,0) is shown by O (its alphabet and not zero). The ball starts at 0,0 represented by X. You can hit the ball with input d 4 (meaning di...
There are programs that will output its source code to standard output and do nothing else. They also access no external output. This type of program is known as a quine, and is a common code challenge. There are poems that have the rhyme scheme a-b-a-b, c-d-c-d, e-f-e-f, g-g. They have 14 lines. They are usually recit...
Since no one has posted a "good quality question" recently, i feel it is my duty to... Task: You work at an electronics company in the design department. The designers that work with you have asked you to make a program that will calculate the optimum configuration of pins on a microchip they are designing. With your ...
Your task: To write a program that should obviously terminate, but it never (to the extent of a computer crash) does. Make it look like it should perform a simple task: adding numbers, printing something,... But it just gets caught in an infinite loop. Try to make your program very clear and simple, while it actually ...
I once needed to write a function that calculates the block entropy of a given symbol series for a given block size and was surprised how short the result was. Thus I am challenging you to codegolf such a function. I am not telling you what I did for now (and in which language), but I will in a week or so, if nobody ca...
Our closest star, the sun, is quite fidgety. The times it rises and sets depend on where you are, and whether it is winter or not. We would like to be able to deduce if the sun is shining outside without having to leave the comforts of our basements - which is why we need an up-to-date sun map (a.k.a. daylight map). Yo...
Given a POSIX Extended Regular Expression as input, output its complement (also a POSIX ERE). If the given regular expression matches a string, its complement should not match it, and the regex: (regex given)|(complement) should match any string. In other words, negate the regex. The regex for format input and for outp...
Task: Your task is to create two programs in different languages that can communicate one-way to each other. Your sending (tx) program will take input, for either stdin or a query, and send it along to the receiving (rx) program. Your rx program will then print out the data that it receives. Rules: The two programs mu...
What general tips do you have for golfing in Lua? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Lua (e.g. "remove comments" is not an answer). Please post one tip per answer.
SAT is the problem of determining whether a boolean expression can be made true. For example, (A) can be made true by setting A=TRUE, but (A && !A) can never be true. This problem is known to be NP-complete. See Boolean Satisfiability. Your task is to write a program for SAT that executes in polynomial time, but may no...
What general tips do you have for golfing in Julia? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Julia (e.g. "remove comments" is not an answer).
Seeing as its St. Patrick's day, I thought I would have a little challenge Your task is to write a program draws a clover in any way possible. Each leaf has to be symmetrical, and the user has to input the number of leaves that they want on the clover. It then must be drawn. This has to be generated. You cannot just lo...
The goal is to animate a star exploding in ASCII art, starting from a single star character * to a supernovae and finally to the space void. Rules : You have to display only 80 characters per line on 24 lines (this is the default terminal size on Linux) Only these 95 printable characters from ASCII are allowed Steps: ...
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
Chomp is a two-player game with a setup of a rectangle of pieces. Each player takes a turn removing any piece, along with all pieces above it and to its right. Whoever takes the bottom-left piece loses. It can be proven fairly easily that the first player always has a winning move (except with a 1-by-1 rectangle); find...
Your task is to create a memory leak. This is a program that uses loads of memory, until the computer runs out and has to do some swapping to save itself from running out. The only way that the memory can be released is by killing the program in the task manager or using a command line kill such as taskkill /im yourpro...
Prove anti-virus software is paranoid by making a program that simply opens and alphabetically sorts a CSV file, that will get flagged as a virus (or malware/spyware/any threat really) when run. You will be assessed by the following criteria: Does the cross-platform anti-virus package ClamAV detect it as a threat? You...
You must generate an text stereogram according to an input string containing a paragraph of text, an empty line then the hidden message. The result will be displayed as a pair of paragraphs, one with different spacing causing the effect of it being raised up when viewed stereographically (An explanation can be found he...