instruction
stringlengths
34
53.1k
This comes from http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/ "Given that Pi can be estimated using the function \$4 \times (1 - 1/3 + 1/5 - 1/7 + \cdots)\$ with more terms giving greater accuracy, write a function that calculates Pi to an accuracy of 5 decimal places." Note, the e...
Warning: this is a complex challenge. Overview A lightbox, in the context of computing, is a visual effect used in image sites. A list of thumbnail images is displayed; each image can be selected and will be displayed on top of the contents of the page either at full size or to fill the screen. The task is to generate ...
Scenario Little Johnny wants to play with his friends today. But his babysitter won't let him go! After a lot of begging, the heartless nanny gives him her brand new electronic puzzle and says: "If you solve the puzzle then you are free to go". Not being aware of Little Johnny's IT skills, the nanny leaves the kid alon...
Alice is a kindergarden teacher. She wants to give some candies to the children in her class. All the children sit in a line and each of them has a rating score according to his or her usual performance. Alice wants to give at least 1 candy for each child.Children get jealous of their immediate neighbors, so if two...
I am trying my hand at writing super small programs. I wrote a simple "tree" display program for showing a graphical representation of a folder hierarchy. I have made it small in all the ways I can think of. I was just wondering if you guys had more creative ways to "minify" it further. Here is the small version as wel...
I'm building a giant lego robot and I need to generate some particular gear ratios using a set of gears. I have lots of gears with the common lego gear sizes: 8, 16, 24, or 40 teeth. Write a program I can use where I input a gearing ratio and the program tells me what combination of gears I should use to get the requ...
Seem like GolfScript wins all of these. So you can't beat them, join them. Write an Self-Contained Golfscript Interpreter I'm using the definition of self-contained to mean, a single program:- So no passing the buck to some external program to do the work for you. Test Cases: Strings and blocks are represented as li...
It is easy to generate a fair coin using a unfair coin, but the reverse is harder to accomplish. Your program will receive one number X (between 0 and 1, inclusive) as input. The input must not simply be hard-coded as a number in the middle of the source code. It must then return a single digit: a 1 with a probability ...
The challenge: Define x in such a way that the expression (x == x+2) would evaluate to true. I tagged the question with C, but answers in other languages are welcome, as long as they're creative or highlight an interesting aspect of the language. I intend to accept a C solution, but other languages can get my vote. Co...
On a road trip, N people pay for fuel. Each pays a different amount. At the end of the trip, calculate the minimum number of transactions so that each person has paid the same amount. e.g. on the road trip, these people pay for fuel Dave - $50 John - $25 George - $5 Barry - $0 After the road trip: Barry pays Dave $2...
A favorite puzzle of mine. Not massively difficult but a tad interesting. The Objective Using a low level language (C/C++/similar level) - create a doubly linked list of elements that only stores a single pointer instead of storing both a previous and next element pointer as you normally would. You must be able to find...
You are given the functions: h1(f,*args) and h2(f,*args) Both are methods which are already defined for you (here the asterisk indicates a variable number of arguments) f is a function, *args is a list of parameters to be passed to that function h1 returns a boolean value: True if the function f ever halts when called ...
Write a perfectly legal code in a decent language of your choice whose compiling will either crash the compiler or send it into an infinite loop (infinite compile time). Restrictions: Use a standard language that is used in real world. Use a standard, well-developed compiler (no answers like "I wrote my C compiler tha...
For a given n list prime factorization of all natural numbers between 1 and n in ascending order. For example, for n = 10 the output would be: 1: 2: 2^1 3: 3^1 4: 2^2 5: 5^1 6: 2^1 3^1 7: 7^1 8: 2^3 9: 3^2 10: 2^1 5^1 Requirements: You cannot just iterate over the numbers and factor each of them. (Unless you know how...
This is a variant of List prime-factorized natural numbers up to N in ascending order, but the solutions can be very different. Write a program that outputs prime factorizations of all natural numbers in any order. For example, the output could look like: 1: 4: 2^2 8: 2^3 2: 2^1 3: 3^1 5: 5^1 6: 2^1 3^1 21: 3^1 7^1 9: ...
WARNING: this is a fairly complex problem, in a king-of-the-hill combat style, with an added randomness to it, the best code may not always win. Please read all rules in full, as it is quite complex! Flavor text Bill and Steve decided to have a "friendly" duel, however being so rich and smart, decided to let their best...
Background As described here http://www.ericharshbarger.org/dice/#gofirst_4d12, "Go First" Dice is a set of four dice, each with unique numbering, so that: There will never be a tie. Each die has a unique set of numbers. Regardless of what subset of dice are rolled against one another, each player will always have an...
The challenge is to create the classic Snake game using as few bytes as possible. Here are the requirements: The game must be implemented in a typical 2-dimensional layout. The snake should be able to grow significantly within the bounds of the map (this really means, don't make your map too small, use your discretion...
Your task is to write a program that executes in as many languages as possible, with as few characters as you can. To avoid trivial solutions, the program must print the name of the language it was run in. Scoring Your program has to work in at least 5 languages. A program's score is given as: $$\frac {\text{(number of...
Write a program that, given a context free grammar and a string, returns whether the string is a word of the language defined by the grammar. Input Your program should read a context free grammar and an input string in an implementation defined way during runtime. Hardcoding the input is acceptable as long as it is tri...
Starting from an array of sub-arrays, each sub-array is a 2 elements key|value pair. Example input = [["A", 5], ["B", 2], ["A", 12], ["B", -2], ["C", 7]] Convert this into a hash that has distinct keys from above, with values summed up, so the above would be: output = {"A" => 17, "B" => 0, "C" => 7}
I would like to see the shortest expression to calculate the days (or the last day) of a month in any language. Considering y as the number of year and m as month. Basic rules without date / time functions. considering leap years. there is not other rule.
The program Given a number, program must return the alphabet letter correspondent. Rules The challenge here is to make it as short as possible, everyone knows it is a very easy program to do. The number is not zero-based, it means 1 is A, 2 is B, 3 is C and so it goes... Any language will be accepted.
Shorten (or not) text using run length encoding Input: heeeello woooorld Output: 1h4e2l1o 1w4o1r1l1d Read lines from stdin. Print to stdout. Stderr is of course discarded. Assume there are hidden testcases (no embedding of the output) Input/Output as ASCII Any language is accepted
The challenge Write a program that takes two integers from standard input, separated by a comma, and then prints a visualisation of long multiplication of those two integers to standard output. Eg: Input 14, 11 Program output 14 x11 _____ 14 14 ______ 154 Input -7, 20 Program output ...
You can count 0, 1, 2, 3, 4. But to get from 3 to 4 you have to change 3 bits at once. Given a number of bits, how can you go through all numbers once, but change at each step only 1! bit. Here is an example for 3 bits: 000 100 110 010 011 111 101 001 so the output is: 0 1 3 2 6 7 5 4 Rules: given a number of bits n...
Challenge Create a GUI Keyboard with as few characters as possible. Example Because this was an assignment in one of my courses, I can't show the source code. However, here is a screen shot of my keyboard. In this example, my keys were of type JButton and I used a Midi Synthesizer to produce the sound (with the defau...
The challenge The program must return a valid sequence of numbers into some rules Rules x is the size of the sequence; x cannot be less than 4 or greater than 9 (Thanks David Carraher); Digits of the sentence can't repeat, each one must appear once; All digits between 1 to x must be in the sequence; A valid sequence n...
Definition1 A Kolakoski sequence is a self-describing infinite sequence {kn} of alternating blocks of 1's and 2's, given by the following rules: k0 = 1 kn = the length of the (n+1)'th block The Task Given a positive integer n, generate the first n elements of the Kolakoski sequence. Details Input will be provided ...
Inspired by the previous question. Golomb's self-describing sequence g(n) is a sequence where any natural number n is repeated within the sequence g(n) times. The first few numbers in the sequence are: n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 g(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 ...
Calculate the determinant of an n x n matrix. Rules read matrix from standard input write to standard output do not use ready solutions from library or language input: columns separated by any space char input: lines separated by cr and/or lf Winner The shortest code :)
(Adapted from Problem C of the first qualifier of the ACM Programming Contest of 2012/2013) You have several arrays, named \$A_1, A_2, ... , A_n\$, each sorted in ascending order. Every item in the array will be a 32-bit integer. A sandwich is a set of indices \$j_1, j_2, ... , j_n\$ such that \$A_1[j_1] ≤ A_2[j_2] ≤ ....
You are required to generate a random 18-hole golf course. Example output: [3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4] Rules: Your program must output a list of hole lengths for exactly 18 holes Each hole must have a length of 3, 4 or 5 The hole lengths must add up to 72 for the entire course Your program must be able to p...
The look and say sequence is an example of a run length encoding sequence. To get the next term of the sequence one groups the sequence into runs of the same number, each group in the next term then becomes two digits, first the number of terms in the group, followed by the value in the group. The first term is 1. He...
An interesting puzzle came to me looking at the elevator buttons this morning. You are required to generate a list of all Braille patterns that fit in a 2x3 grid. Use a hash # to denote a bump and a hyphen - to denote a flat area. Expected output sample: #- -- -- ## -- -- #- #- -- (and so on...) Rules: Your progr...
For each of the 13 rows of a Yahtzee scoresheet you are given (from stdin) a space separated list of 5 numbers (dice). Your task is to calculate the score for each line and output the Grand Total of the game. Example Input and how to interpret it: Input Box Score 6 1 4 1 3 Aces 2 3 2 2...
Given prime factors of a number, what is the fastest way to calculate divisors? clc; clear; sms=0; count = 1; x=0; for i=11:28123 fac = factor(i); sm = 1; for j = 1:length(fac)-1 sm = sm + sum(prod(unique(combntns(fac,j), 'rows'),2)); end if sm>i x(count) = i; count = count +...
You are given a Bingo board and a list of calls. You must print BINGO! as soon as your board wins the game. Bingo boards look like this: They will be specified like this: 14 29 38 52 74 4 18 33 46 62 7 16 * 60 71 9 27 44 51 67 12 23 35 47 73 Immediately following the board will be calls, like this: B7 I29 G60 G51 O7...
This is the first of a series of C++ puzzles for you. Hope you will enjoy. So, puzzle no.1: Given the following program: #include <iostream> int main() { const int a=1; const int b=2; const float c=0.5; std::cout << a/b-a*c; } Insert some code on a single new line anywhere inside the program so that the o...
Given a list of chords label them as either 'Major' or ' Minor'. Input Input will be a list of chords, one per line, made up of 3 notes separated by a space. Each note will consist of the note name in uppercase (A-G) and an optional accidental (# or b). Chords may be in any inversion (i.e. the notes may be in any order...
I am back with a brand new puzzle for C/C++ addicts. Following the feedback received on the 1st puzzle, this time I will try to make the requirements crystal clear and to provide a perfectly valid code. Here is the problem. Given the following code: #include <iostream> char message[6]="hello"; void print_hello_messag...
The "ascending matrix" is an infinite matrix of whole numbers (0 included) in which any element is the smallest available element which has not been previously used on the respective row and column: | 1 2 3 4 5 6 ... --+---------------- 1 | 0 1 2 3 4 5 ... 2 | 1 0 3 2 5 4 ... 3 | 2 3 0 1 6 7 ... 4 | 3 2 1 0 7 6 ... 5...
Introduction You are given a random integer generator with the following implementation The first invocation always returns 1. The second invocation returns a random integer between 1 and 2. The third invocation returns a random integer between 1 and 3. The nth invocation returns a random integer between 1 and n, incl...
This is the 3rd of my series of C/C++ puzzles; in case you missed the first 2 they are here: (1) m3ph1st0s's programming puzzle 1 (C++) (2) m3ph1st0s's programming puzzle 2 (C++): "Call hard!" I must say that my puzzles are 100% original. If not, I will always state so in the text. My 3rd puzzle has 2 parts as follows...
Lately there have been quite a number of questions regarding the recreation of xkcd-style graphs like the following one (1064) in various languages. Your goal is to recreate any existing xkcd comic as close to the original as possible. The comic has to have at least one simple graph or pie chart or similar element. Th...
Write a code using HTML, JavaScript, jQuery to make the page go into infinite loop. Restrictions: No looping or control structures of javascript and jQuery allowed. You can only use alert, events, etc.
Given the number of goods N positive weight of each good weight[N] positive profit of each good profit[N] and a positive number W which is the knapsack capacity. This problem is called “the zero-one knapsack” for choosing the most beneficial goods for the knapsack of limited capacity. Example: The number of goods ...
The challenge The program must return all numbers included into a group (comma and hyphen separated sequence) of numbers. Rules s is the sequence string; all numbers included in s are positive; numbers will always increase; numbers will never repeat when you answer, show the output for s="1,3-5,9,16,18-23" Examples ...
My last puzzle has generated some confusion and controversy so I decided to give up, for now, on those "replace one character"-type puzzles. Hope this 4th puzzle will redeem myself after all the edits in puzzle 3 and will put your brains at work once more. I've really put up all the effort to make this one as clear as ...
Possible Duplicate: Integer to string with given radix This question is inspired by Pythons builtin int function. int is used to convert other numbers or strings into integers. If you are converting a string you can provide the additional parameter base, that contains the base that your number is represented in with...
The task is simple: your program reads an integer as an input, and prints whether it is a prime or not. You can print "yes/no", "true/false" or anything what unambiguously identifies the result. The challenge is, the code has to work with its rows and columns transposed. To exclude the obvious solution (shortest "simpl...
Last week we had a programming contest in my university and I am very curious about one of the problems , one which only one team (but from another city) was able to solve. Maybe its not that hard, but I cant find any solutions that will take less than a second of execution time. The problem is the following: Problem Y...
Write a program to factorize a semi-prime number in the shortest amount of time. For testing purposes, use this: \$38!+1\$ (\$523022617466601111760007224100074291200000001\$) It is equal to: \$14029308060317546154181 × 37280713718589679646221\$
Your task is to sum up and output one player's score in a game of 10-pin bowling after up to 21 rolls. The rolls are represented as a sequence of integers in your preferred method of input. Each integer corresponds to the number of pins that were knocked down in that roll. Scoring After each round the number of pins kn...
One of my colleagues proposed us a challenge: to write the shortest C/C++ program to determine if a number is even or odd. These are the requirements: Get a number from keyboard, at run-time (not from command line) Output the string pari if the number is even Output the string dispari if the number is odd We can assum...
You are given a graph represented through an adjacency list. For example, the input 1-2 2-3 3-4 4-1 would correspond to the graph with nodes 1, 2, 3 and 4, where 1 is connected to 2, 2 is connected to 3, 3 is connected to 4, and 4 is connected to 1 (forming a square). The task is to determine the number of of connecte...
This is how I checkout to see if a number is in a range (in between two other numbers): var a = 10, b = 30, x = 15, y = 35; x < Math.max(a,b) && x > Math.min(a,b) // -> true y < Math.max(a,b) && y > Math.min(a,b) // -> false I have to do this math in my code a lot and I'm looking for shorter equivalent co...
Task Given a list of space-delimited integers as input, output all unique non-empty subsets of these numbers that each subset sums to 0. Test Case Input: 8 −7 5 −3 −2 Output: -3 -2 5 Winning Criterion This is code-golf, so the shortest code in bytes wins!
I came upon this question, because it seems to be very common use-case to find unique characters in string. But what if we want to get rid of them? Input contains only lower case alphabets. Only letters from a to z are used. Input length may be from 1 to 1000 characters. Example: input: helloworld output: llool Objecti...
The answer to this question is much too long Your challenge is to write a partitioning function in the smallest number of characters. Input example ['a', 'b', 'c'] Output example [(('a'),('b'),('c')), (('a', 'b'), ('c')), (('a', 'c'), ('b')), (('b', 'c'), ('a')), (('a', 'b', 'c'))] The input can be a list/array/s...
This question has been spreading like a virus in my office. There are quite a variety of approaches: Print the following: 1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 123456787654321 1234567654321 12345654321 123454321 12343...
Given a regular N-gon with all diagonals drawn, how many regions do the diagonals form? For example, a regular triangle has exactly 1, a square has exactly 4, pentagon has exactly 11, and a hexagon has 24. score is inversely proportional to number of bytes in solution small fudge factors may be added to scores based o...
Your code has to provide the following functions: read(x) Reads a complex number from the standard input. It has to accept and evaluate something in the form of for example 1.42 + 3i. print(x) Prints the complex number in the form of, for example 1.23 - 4.32i add(x,y) sub(x,y) mult(x,y) div(x,y) Adds, subtracts...
A limit in math determines the value that a function f(x) approaches as x gets closer and closer to a certain value. Let me use the equation f(x)=x^2/x as an example. Obviously, f(x) is undefined if x is 0 (x=0, x2=0, 0/0 is undefined). But, what happens when we calculate f(x) as x approaches 0? x=0.1, f(x)=0.01/0.1 = ...
Me and some other students were at a bar discussing programming languages, in particular the C programming language. At some point a first year student said he didn't need no damn pointers. Another student said that he couldn't use arrays either since "they're basically pointers". This led to a programming challenge: ...
Bernd is a high school student who has some problems in chemistry. In class he has to design chemical equations for some experiments they are doing, such as the combustion of heptane C7H16: C7H16 + 11O2 → 7CO2 + 8H2O Since mathematics isn't exactly Bernd's strongest subject, he often has a hard time finding the exact...
What is the most compact way to encode/save DNS names in memory? For example, storing "www.google.com" as a string in .NET will result in the object being encoded as UTF-16, and it will consume twice as much memory as plain ASCII... but for the purpose of storing DNS names, ASCII is overkill. The only characters that a...
The Fibonacci sequence is a well know sequence in which each entry is the sum of the previous two and the first two entries are 1. If we take the modulo of each term by a constant the sequence will become periodic. For example if we took decided to compute the sequence mod 7 we would get the following: 1 1 2 3 5 1 6 ...
A three-color traffic light must switch lights in the following order: red, green, yellow, red. To indicate when crossing slowly without a stop is permitted, the yellow signal may be flashed. To indicate when crossing immediately after a full stop is permitted, the red signal may be flashed. Either flash sequence may ...
Write a Turing machine simulator. For simplicity we can assume statuses as integer, symbols as char, blank symbol equals whitespace 5-tuple in the form of current state, input symbol, next state, output symbol, direction (left or right) the order is not mandatory but specify if you swap it The machine must stop when an...
I'm very lazy so I try to always program my microwave with the fewest possible button presses. My microwave has the following buttons: A "minute plus" button which may only be pressed first and implies "start". It may be pressed multiple times for multiple minutes, but it will not add a minute to a manually entered ...
Write a program which accepts a sentence into stdin, and writes that sentence to stdout in pig latin. Here are some test cases which your program should handle: Input: Read your script Output: ead-Ray our-yay ipt-scray Hyphenation is mandatory. Note that multiple consonants at the start of the word must all be...
Good Evening Golfers! Your challenge is to completely unsort a series of numbers. Input Exactly 100 integers will be fed to your program. Your program may accept the input either as a file, or via stdin. Each integer will be separated by a newline character. Those 100 integers will range from the minimal to the maximal...
Given a string, find the 10 least common alpha-numeric characters within that string. Output should be formatted with numbers left-padded with spaces so they look like this: e: 1 t: 16 c: 42 b: 400 z: 50000 a: 100000 Use this to test your program: here Output for test case: j: 2 x: 3 q: 9 k: 32 v: ...
Write a program that will determine the original sequence given five variations. The original sequence will be contain n unique elements in any order. A variation is made by making a copy of the original sequence and choosing a random item from the copy and inserting it at any random location in the sequence (this coul...
As one of the less popular languages, it's difficult to find literature on the avant garde of postscript hackery. So what discoveries have the golfers here made to exploit the stack model (or other features) to overcome Postscript's inherent verbosity?
It is possible to compress some kinds of data, such as human text or source code, with straight-line grammars. You basically create a grammar whose language has exactly one word – the uncompressed data. In this task, you have to write a program that implements this method of data compession. Input The input is a string...
In exactly 1024 characters, no more, no less: Must print Hello World. Must not use unnecessary whitespace. Must not use comments. Judging should favor creativity and/or humor over simple obfuscation when voting up answers. The earliest I will select an answer is the 11th (Sunday) of November (2012). I'm seeing s...
Input/Output: Input: A uniformly random, infinitely long, string of '0's and '1's, taken from stdin. The string is assumed to be truly random, not pseudo-random. It is uniform in that each character is equally likely to be a '0' or '1'. Careful! The input is infinitely long, so you can't store it all in memory using ...
Create a short C program that takes an absurdly long time to compile with gcc. Entries will be scored by timing the compilation then subtracting the reference program's compile time. Rules Any C language feature or gcc extension gcc 4.2.1
Input: Either one or two strings consisting of '0's and '1's. If there are 2, they are separated by a space. All strings are of length at least 1. Output: If a single input was given as input, 2 are output. If 2 were input, 1 is output. The output strings can be whatever you like, but if running your program with i...
Write a program, which, upon gazing at a chess table, can say whether there is a check or a checkmate. Input: a chess table in text form, the last line of the input being the first rank (the starting line of White) The starting position in this input would look like this (space is an empty square, capital letters are W...
In particular, use each of these symbols at least once in your source code: ! " # $ % & ' () * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count). The program should not perf...
It's well known that Brainf*ck is very bad at Kolmogorov-complexity problems, for example, it requires around 100 characters just to print "Hello world". However, there might be texts where Brainf*ck is just very good at. Your task is now to write a program that takes no input, and it displays the following: ☺ That is...
Create a program that prints the MD5 sum of its source in the form: MD5 sum of my source is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx No cheating - you can't just read the source file and compute its sum. The program must not read any external information. Of course you can use a MD5 library available for your language.
Thinking about various quine puzzles here, I got an idea for another one: Compose a program that outputs its own compiled code to a file (or multiple files, if the compiled code is). (This means that only compiled languages are eligible.) Rules Standard quine rules - no cheating allowed. In particular: The program can...
There are two objects: Object1, Object2 You can easily swap them by: Object3 = Object1 Object1 = Object2 Object2 = Object3 However, you must solve this problem by using no temporary object and Object1 should be changed to Object 2. (and vice versa)
Challenge Given an array of single digit number, work out if any 2 of them add up to 10 and print them out Example Input (1,2,3,4,5,5,6,7) This returns ((4,6),(5,5),(3,7)) Input (1,2,3,4,5) This returns (). as there is only one 5 Input (5,5,5,5,5) This returns ((5,5),(5,5)) as there is odd number of 5s and each 5...
Challenge Your challenge is simply to write a program in the language of your choosing that when run, determines the highest possible score for a board of Scrabble - For the sake of this challenge, a few rules have been modified. Notably, bonus squares are counted for every single word on the board, rather than only th...
I wanted to make a challenge to do the full DES encryption algorithm, but that may be a bit too involved to get a ton of participation. This challenge is to simply generate the 16 48-bit subkeys used to encrypt data: The algorithm is described well enough on wikipedia, and all relevant shift tables and such data are o...
Your program has to make the computer produce a sound, any sound. Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins. The program should run on a reasonable, not too uncommon personal computer. Opening a pop-up, message box, etc. (for example, on...
Most of you probably know the C major scale: C D E F G A B C The major scale is characterised by the intervals between adjacent notes, which measured in semitones are: 2 2 1 2 2 2 1 From these intervales, we can construct any major scale starting in any note (the key of the scale). The 12 notes in our 12-tone equal t...
Given a file named hello_world that contains 2-100 bytes of printable ASCII, create a Turing-complete language in which hello_world is a valid program that prints "Hello World!". The output should be two files: a compiler or interpreter, and a text file with the language spec. Rules Shortest code wins. Length of (an...
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 ...
Your goal is to write a super-secret program which launches another (independent) program. You don't have to provide the payload in your answer, it can be any program name your program will launch. However, the challenge is to keep this behavior a secret. Upon casual inspection of the code, it should be impossible or v...
Input: an integer N between 1 and 151 Output: the Nth Pokemon. Rules You may use one data file. You may not use any already made data decompression algorithms. This includes libraries and other programs. Your program may not access files other than itself and your data file. Scoring Your score is the sum of the leng...
Problem definition Print out the powerset of a given set. For example: [1, 2, 3] => [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] Each element is to be printed on a separate line, so the above example would be printed as: [] [1] [2] ... [1, 2, 3] Example code (in D, python example here): import std.stdio; s...
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...
Write the shortest program possible which outputs a table of Normal distribution values phi(z) = Integral[t from -infty to z of e^(-t^2/2) /sqrt(2 pi) dt] for z from 0.00 to 3.99, giving values accurate to 4 decimal places. The canonical format for such a table appears to be: 0.00 0.01 0.02 0.03 0.04 ...
Given a floating point x (x<100), return e^x and ln(x). The first 6 decimal places of the number have to be right, but any others after do not have to be correct. You cannot have any "magic" constants explicitly stated (e.x. a=1.35914 since 1.35914*2 ~= e), but you can calculate them. Only use +, -, *, and / for arithm...