All Questions

Filter by
Sorted by
Tagged with
15
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 ...
12
votes
5answers
898 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
217 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
907 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
366 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: ...
5
votes
10answers
1k views

How many switches are ON

A class has N student and the class room has N switches (all turned OFF and numbered 1 to N). Each student has an enrollment number assigned from 1 to N. Each student serially (by number) toggles the ...
9
votes
3answers
451 views

Physics golf: inclined shooting

"And now for something, completely different." An angry bird is shot at an angle β to the horizontal at a speed u. The ground is steep, inclined at an angle α. Find the horizontal distance q that the ...
5
votes
3answers
4k views

Carmichael Numbers

EDIT: I am changing the challenge. Write a program to print Carmichael numbers. The challenge is to print the maximum number of them in less than 5 secs. The numbers should be in increasing order. ...
7
votes
9answers
3k views

Square free Numbers

Given a number N, write the shortest complete program to find the number of square-free integers below N. Sample Input 100000 Sample Output 60794 Constraints: ...
8
votes
4answers
930 views

Crossword grid verification

Validate a proposed crossword grid. Entries should be full programs that simply test a proposed grid to determine if it meets a set of conditions for making crossword solvers happy. Input The input ...
13
votes
6answers
887 views

Comparing powers.

Compare two numbers N1 = abc, N2 = def by constructing a function f(a,b,c,d,e,f) that: returns 1 if N1 > N2 returns -1 if N1 < N2 Note: You are not required to return any value for any other ...
5
votes
8answers
279 views

Power modulo golf. [closed]

Write a function f(a,b,c) that calculates a^b (mod c) in less than 10 seconds. a, b < 10^100 c < 10000. examples: ...
5
votes
7answers
861 views

Modulo code golf

Write a function f(a,b) that returns a mod b given the constraints: you can't use division in any way ...
3
votes
3answers
918 views

Finding “sub-palindromes” 2: subsequences.

The same task as Finding "sub-palindromes" but instead of finding substrings you must find subsequences that are not substrings. eg1: ...
19
votes
5answers
5k views

Print a Binary Tree

Inspired by a recent question on SO... Write a function to print a binary tree in the following format: 3 / \ 1 5 \ / \ 2 4 6 The output should ...
4
votes
3answers
654 views

Implement BCD Arithmetic

Write the shortest function you can that takes two binary-coded decimal integers and a character indicating an arithmetic operation to perform and return the result. Input Specification You will be ...
12
votes
4answers
2k views

Polynomial Long Division

Implement polynomial long division, an algorithm that divides two polynomials and gets the quotient and remainder: (12x^3 - 5x^2 + 3x - 1) / (x^2 - 5) = 12x - 5 R 63x - 26 In your programs, you will ...
11
votes
15answers
977 views

Holiday Gift Exchange

Another problem from our internal golfing...this one around the holidays last year. PROBLEM Andy, Barb, Carl, Didi, Earl, and Fran are buying gifts for each other. Draw names for a gift exchange. ...
6
votes
7answers
671 views

How many squares are guarded by chess queens?

Today marks the 15th anniversary of Garry Kasparov's defeat against Deep Blue. Speaking of chess... Input is a string that represents an 8x8 chess board containing only empty squares (...
5
votes
4answers
4k views

Fair outcome using unfair coin [closed]

I have been thinking a lot about the following puzzle, but could not arrive at a solution. Can someone explain to me how can you get a fair (equal probability) outcome using only an unfair coin (...
4
votes
9answers
3k views

Partition of a positive integer N [closed]

Find the number of partitions of a positive integer n. Hope someone uses the explicit finite formula for the partition function defined in Jan Hendrik Brunier and Ken Ono paper here. ...
8
votes
1answer
1k views

Random Sentence Generator

Write the shortest program you can in any language that reads a context-free grammar from and the number of sentences to produce from stdin, and generates that many ...
7
votes
8answers
506 views

Is this figure connected?

You are given a list of (x,y) grid coordinates. Your function should decide whether the figure obtained by coloring in the squares of the grid with the given ...
14
votes
2answers
3k views

Roman numeral converter function

Create the shortest function to convert a string of Roman numerals to an integer. The rules for each letter can be found at the Wikipedia page. Letters above 1,000 will have parentheses placed ...
12
votes
14answers
7k views

Print NxN spiral of ascending numbers [closed]

The numbers should be printed with leading zeroes in a field with length = (number of digits of N^2). Input (N): 4 Output: ...
12
votes
14answers
661 views

Finish a symmetrical map

You are given one-quarter of a map that is symmetrical over the x- and y-axes as input. The program should print the complete map. The map can contain the following characters: ...
14
votes
6answers
3k views

Calculate the last digits of Graham's Number

Graham's number ends in a 7. It is a massive number, in theory requiring more information to store than the size of the universe itself. However it is possible to calculate the last few digits of ...
18
votes
32answers
1k views

Sum of integers in string, separated by non-numericals such as 'a' and 'Y'

Create a program which sums all integers found in a string which is set as a variable in the program (thus, the program doesn't have to handle any input). The integer numbers are separated by non-...
6
votes
5answers
978 views

Calculate the number of trailing zeros in n! [duplicate]

Write a function which takes n as a parameter, and returns the number of trailing zeros in n!. Input Constraints 0 <= n <= 10^100 Output Constraints Should be return the result in less than ...
16
votes
25answers
5k views

Binary representation of a number is palindrome or not?

Write a full program to find whether the binary representation of a number is palindrome or not? Sample Input 5 Sample Output YES Print ...
5
votes
3answers
1k views

->The Tragedy of Macbeth<- [closed]

The Setup Here you can find the full text of The Tragedy of Macbeth. If you view the source, and save it as text, you will notice it comes out to 206,244 total characters (including the whitespace ...
22
votes
28answers
4k views

Last non-zero digit of n!

Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive). This is OEIS sequence A008904. Your ...
10
votes
4answers
867 views

Word Spinner Puzzle

This is a word puzzle. Your program should accept two words on the standard input. Word one is the start word. Word two is the end word. From the start word you have to reach the end word changing/...
12
votes
7answers
888 views

How much snow did you get?

My apologies for the wordiness. We had fun with it at work in our internal golfing, but it required a few emails for clarification, so I hope I captured most of that the first time. PROBLEM Given a “...
28
votes
17answers
4k views

Decipher a Vigenère ciphertext

The Vigenère cipher was a simple polyalphabetic cipher that basically applied one of several Caesar ciphers, according to a key. Bascially the letters in the key indicate which shifted alphabet to use....
10
votes
18answers
1k views

Find prime factors [duplicate]

A whole program to find the prime factors of a given number. The number will be given on standard input.
8
votes
17answers
3k views

Multiply without multiply [closed]

Write the fastest (best big-O) and smallest multiplication algorithm for positive integers, without using multiplication operators. You are only allowed addition, subtraction, logical functions (AND, ...
10
votes
6answers
576 views

Work out change [closed]

You are writing a program for an automatic cash register. The user needs change with the least number of coins used. Write a program which takes an amount (say $1.53) and gives change in US ...
7
votes
9answers
406 views

All Possible Matching Lists

Implement a function that takes a list that consists of 0, 1 or 2, the list is called "pattern". Your job is to return all possible lists that match the pattern. 0 matches 0 1 matches 1 2 matches 0 ...
6
votes
3answers
622 views

Word guessing game

A program should take an input on stdin, and guess what a word might be. It should run as a session. One example session is shown below. Characters are fed to it, with a * for a letter not revealed; ...
11
votes
3answers
2k views

Interpret Befunge-93

The program will be provided as the first argument, stdin should be used for all read requests by the program and stdout for all write requests. It can be assumed that the program is less than 80 ...
9
votes
15answers
656 views

Output nearby primes

Write a program which takes an input (which may or may not be prime), and lists the immediate prime following and preceding it. Example input: 1259 Example ...
28
votes
5answers
2k views

Advanced Calculator

You must write a program that evaluates a string that would be entered into an advanced calculator. The program must accept input using stdin and output the correct answer. For languages that do no ...
75
votes
184answers
16k views

Find the Factorial!

Create the shortest program or function that finds the factorial of a non-negative integer. The factorial, represented with ! is defined as such $$n!:=\begin{...
4
votes
5answers
1k views

Tree traversal: Depth-first search

Write the shortest code that traverses a tree, depth-first. Input Any programmatical structure found in your language of choice: lists, tuples, queues etc. Output A list of "names" of the nodes in ...
51
votes
7answers
4k views

Robot Finds Kitten

The challenge The shortest code by character count to help Robot find kitten in the fewest steps possible. Golfers, this is a time of crisis - Kitten gone missing and it's Robot's job to find it! ...
26
votes
7answers
4k views

Self-Interpreting Interpreter

Based on a comment by George Edison to this question, write the smallest self-interpreting interpreter. You may use the language of your choosing. Empty languages do not count. Your program must be ...
22
votes
12answers
5k views

Assembly Language Quine

Write the shortest possible assembly-language quine. Use any ISA you want, unless it has a print-quine instruction or equivalent. Examples include x86, MIPS, ...
20
votes
19answers
3k views

Basic Calculator

You must write a program to evaluate a string that would be entered into a calculator. The program must accept input and output the correct answer. For languages that do not have standard input/...

15 30 50 per page