All Questions

43
votes
74answers
7k views

Answer to life, the universe, and everything

Task Given a String as input, your task is to output 42 only if the input String happens to be exactly the following : ...
11
votes
6answers
1k views

Code-Golf: Quine Challenge I

Challenge In this task you have to write a program that will take input an integer N (-1e9 <= N < 0 && 0 < N <= +1e9), then compute T = (abs(N) % M+1),if N is positive ...
7
votes
2answers
617 views

GolfScript - The missing function

The GolfScript language has one serious lack, no float or fixed point handling. Remedy this by creating a function F for converting an integer number, given as a string, to a string representing 1 / ...
18
votes
41answers
2k views

Detect rotated strings

Read two strings from stdin. Output Yes if one string is a rotated version of the other. Otherwise output ...
12
votes
1answer
3k views

Solve the 8 Puzzle

The 8 Puzzle is the smaller variant of the 15Puzzle (or the Sliding puzzle). You have a 3x3 grid which is filled with numbers from 0-8 (0 denotes the blank tile) ...
7
votes
4answers
551 views

Obtain a number from 4 numbers using any combination of mathematical operations [closed]

Given 4 numbers n1, n2, n3, n4, and a goal n5, obtain n5 using n1 through n4 combined with any operations. Eg. Given four numbers 2,3,4,5 and the goal as 8, output (one of many) is ...
5
votes
8answers
792 views

Code Golf: Number of paths!

Challenge Consider a square matrix of order N(N rows and N columns). At each step you can move one step to the right or one step to the top. How many possibilities are to reach (N,N) from ...
8
votes
2answers
567 views

Turn 2D boolean array into (rectilinear) polygons

Challenge Write a program which, given a 2-dimensional boolean array (equivalently, a monochromatic bitmap), outputs a series of polygons that describe the outline of the region that is “true” (1). ...
83
votes
131answers
11k views

Determine whether strings are anagrams

Challenge Given two strings, work out if they both have exactly the same characters in them. Example Input word, wrdo This returns true because they are the ...
9
votes
27answers
2k views

Chessboard pattern

Input: a positive number, smaller then 80, from stdin or as a command-line argument. Output: A square chessboard pattern, the size of the input number. The dark fields are represented by the letter '...
3
votes
1answer
352 views

Check printer - Convert to English text from the input value.

Check printer function (or subroutine) - Convert to English text from the input value. 12.34 -> "twelve dollars and thirty four cents". For the range .01 to 9999.99 assuming valid input.
6
votes
3answers
570 views

Break the broken hash [closed]

Some time ago, I found this unused hash function (written in Java) in our codebase: ...
16
votes
4answers
2k views

ASCII art Bresenham line drawing

Write the shortest possible program that draws a Bresenham line in ASCII art. Your program should take two integers x and y (...
12
votes
12answers
2k views

Hitting 495 (Kaprekar) [duplicate]

Input: A three digit number from stdin or as an argument not all digits are the same may start with one or two zero's Process Order the input-digits ascending and descending to form two new ...
4
votes
4answers
295 views

Rotate Cartesian coordinates.

Write a program rotates some Cartesian coordinates through an angle about the origin (0.0,0.0). The angle and coordinates will be read from a single line of stdin in the following format: ...
-3
votes
3answers
334 views

Shorten this code while fixing a major bug [closed]

I found the code below today after much hair pulling. Shorten it down (code golf) and fix the bug that I found (bonus). ...
10
votes
7answers
3k views

Implement Shamir's Secret Sharing reconstruction

Shamir's secret sharing scheme is a simple way of protecting a secret by splitting it into several parts needed to reconstruct it. Your task is to implement Shamir's Secret Sharing reconstruction ...
12
votes
1answer
757 views

Break the broken cipher

I have designed a simple random generator that cycles two numbers in a chaotic way using a multiply and modulus method. It works great for that. If I were to use it as a cipher generator it would ...
10
votes
20answers
836 views

Calculate probability of getting half as many heads as coin tosses.

Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads. For example, given 2 coins ...
10
votes
13answers
2k views

Draw a BCD Binary clock

Create a BCD binary clock in ASCII. As implied, it shall display time in six columns of dots: (source: Wikimedia Commons) Each column is a binary-coded digit, reading hours, minutes and seconds ...
8
votes
8answers
2k views

Output a playable crossword grid

Write a program to produce a file containing a crossword grid that the user can print out and work the puzzle on. Input A filename representing a crossword grid file and optionally a second ...
4
votes
6answers
663 views

Write a program to perform set operations.

Your task is to write a program to perform set operations. The operations and arguments are taken from command line in the format program operation [argument]. ...
14
votes
49answers
7k views

Sum of positive integers. [closed]

Problem: Given a set of integers, find the sum of all positive integers in it. Input: t – number of test cases [t < 1000] On each of next t lines, an integer N [-1000 ≤ N ≤ 1000] Output The ...
9
votes
14answers
1k views

Numbers, Sums, Products

Given a 20×20 grid of non-negative integers, find a 3×3 sub-grid where the product of the sums of the individual lines hits the maximum. Spoken in formulas: Given the 3×3 sub-grid the function to ...
10
votes
14answers
955 views

Percentage of work days in a month

Given a year and a month, find out the percentage of work days in said month. Work days are Monday through Friday with no regard to holidays or other special things. The Gregorian calendar is used. ...
12
votes
13answers
962 views

Make a number palindrome

Write a function that takes a number as an argument and makes it a palindrome by appending minimum number of digits. The number will be at max of 100 digits. ...
26
votes
19answers
4k views

My Word can beat up your Word

PROBLEM Given two words, find the winner in a digital root battle. Define the digital root of a word this way: Each letter of the alphabet is assigned a number: A = 1, B = 2, C = 3, ..., Z = 26 ...
13
votes
1answer
1k views

Implement PCRE in your language.

Note: After trying this myself, I soon realized what a mistake this was. Therfore, I am modifying the rules a bit. The minimum required functionality: Character classes (...
10
votes
14answers
2k views

Guess the number

Description Create a fully working "Guess the number" game. The game is played by two players as follows: player one chooses a number (A) between 1 and N player two tries to guess A choosing a ...
8
votes
7answers
387 views

Shortest Port Scanner

Write the shortest program that will attempt to connect to open ports on a remote computer and check if they are open. (It's called a Port Scanner) Take input from command line arguments. ...
40
votes
86answers
7k views

What's my name? Produce the name of the language indirectly [closed]

Produce only the name of a programming language using only the facilities of the language itself. The name of the language can only be invoked indirectly, i.e., from non custom environment variables, ...
55
votes
21answers
5k views

Add a feature to a programming language [closed]

Your task is to tack on a feature to a programming language, either by implementing a very clever library, or by processing the input text and/or tweaking the compilation process. Ideas: Add PHP-...
4
votes
2answers
379 views

Implement cdbmake

Write the shortest program to build a cdb database, using the following syntax for input: +klen,dlen:key->data followed by a newline. Example: ...
-3
votes
9answers
364 views

Mixed up output [duplicate]

Write a function or program that outputs the following lines <input> time: ...
17
votes
7answers
2k views

The Tic Tac Toe Dictionary

A TicTacToe game can be represented by a string denoting the sequence of positions as the players make their move. 0 1 2 3 4 5 6 7 8 Assume ...
9
votes
5answers
417 views

Golfed fixed point combinator

Write a fixed point combinator in as few characters as possible, in the language of your choice. free form (i.e., whatever's shortest): whole program, actual function, code snippet you may not use ...
4
votes
1answer
1k views

How would you count score in a Scrabble® game? [closed]

Let's say that we are programming a game that lets you play Scrabble®. We have a board with tiles placed on it, and empty cells are either normal or have multiplier properties (double or triple the ...
7
votes
4answers
2k views

Noughts and Crosses (aka Tic-Tac-Toe)

Write a Notes and Crosses application. User interface is optional. You can output the computers move in text: eg 1x1 (meaning ...
23
votes
61answers
5k views

Reinvent the For loop [closed]

For loops are used extensively in many languages, but what would you do if no languages supported them? Create a way to execute a basic ...
18
votes
19answers
2k views

Run-Length Encoding

Write a program uses run-length encoding to shorten a list of non-negative integers it has to read in. You can assume the non-negative integers can fit in 32bit signed integers. Input Format The ...
13
votes
12answers
1k views

Day of the week of the next Feb 29th

Write a function which takes a date and returns the day of the week of the next February 29th after that date. The input is a string in the ISO Extended format: YYYY-MM-DD (e.g. May 27th, 2010 would ...
28
votes
29answers
4k views

Render “Digital Clock Style” Numbers

Write the shortest program which will take a string of numbers (of up to at least 20 length) as input, and display the output using the standard digital clock style numbers. For instance for input 81,...
10
votes
5answers
773 views

Huffman golfing [duplicate]

Write a filter that converts text from standard input to a representation of its Huffman tree on standard output. In as few characters as possible. you're free to consider newlines or not output ...
21
votes
6answers
3k views

Koch Snowflake - codegolf

The Koch snowflake (also known as the Koch star and Koch island) is a mathematical curve and one of the earliest fractal curves to have been described. It is based on the Koch curve, which appeared in ...
14
votes
24answers
2k views

Next Friday the 13th

What is the shortest program that can predict the next time Friday will fall on the 13th day of the month? Must be an complete functioning program (not just a function/subroutine) Must print out date ...
10
votes
5answers
818 views

Dissociated Press

http://en.wikipedia.org/wiki/Dissociated_press Dissociated Press is an algorithm that generates random text from an existing text. The algorithm starts by printing any N consecutive words (or ...
3
votes
2answers
211 views

Directories required for creating a folder tree

Say that you have this folder structure on your coumputer: /a And you want to have these folders: /a/b /a/c /b/b You would ...
14
votes
20answers
1k views

Random dice tipping

In a standard dice (die) the numbers are arranged so that opposite faces add to seven. Write the shortest possible program in your preferred language which outputs a random throw followed by 9 random ...
14
votes
6answers
871 views

Print Triangle Wave of Numbers

Given the amplitude and period for a wave, print the wave. See sample output for more details. The total number of wave forms equals the period, and the height of each wave equals the amplitude. ...
3
votes
9answers
353 views

Count even steps of 196 algorithm

In the 196-algorithm one starts from an integer and then adds its reverse to it until a palindrome is reached, like this: ...

15 30 50 per page