All Questions

Filter by
Sorted by
Tagged with
8 votes
4 answers
589 views

Binary search ("bisect") tool

Implement the binary search algorithm as used to identify the source code revision that breaks a computer software program. Your tool should take two arguments specifying the earliest and latest ...
PleaseStand's user avatar
  • 5,617
9 votes
10 answers
3k views

Crossword numbering

Produce a program to correctly number a crossword grid. Input The input will be the name of a file representing the crossword grid. The input filename may be passed as an argument, on the standard ...
dmckee --- ex-moderator kitten's user avatar
137 votes
145 answers
44k views

Obfuscated Hello World

Create the shortest possible obfuscated program that displays the text "Hello World". In order to be considered an obfuscated program, it must meet at least two of the following requirements: Does ...
Kevin Brown-Silva's user avatar
10 votes
3 answers
909 views

Project Euler Problem 12: optimize memory usage

I am referring to Project Euler #12. Write the solution in any language you want, but consume the least amount of memory while executing. Running time is not measure in this case. The sequence of ...
cbrulak's user avatar
  • 301
18 votes
2 answers
813 views

Quine that takes as input the name of a language and outputs the same thing implemented in the input language

From Quine central: Write a quine that takes as input the name of a language and outputs the same thing implemented in the input language. The source article has something you can work from, but as ...
moinudin's user avatar
  • 12.7k
17 votes
44 answers
6k views

Shortest Floor Function

Your task is to implement a floor function in as few bytes as possible. A floor function is a function that takes a real number and returns the largest integer less than or equal to the input. Your ...
Daniel Standage's user avatar
52 votes
11 answers
16k views

Write an interpreter for the untyped lambda calculus

The challenge is to write an interpreter for the untyped lambda calculus in as few characters as possible. We define the untyped lambda calculus as follows: Syntax There are the following three ...
sepp2k's user avatar
  • 1,869
33 votes
20 answers
14k views

Twinkle Twinkle Little Star

Write a program to play the popular English nursery rhyme. (This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. Attribution: Helix84 at the English language ...
PleaseStand's user avatar
  • 5,617
6 votes
1 answer
2k views

Nokia mystery puzzle [closed]

A friend sent me this puzzle. I'm pretty sure solving it will require some programming. Can anyone crack it? The original is here in case of encoding issues in the past below. ...
moinudin's user avatar
  • 12.7k
11 votes
2 answers
5k views

Decryption by pattern analysis

You are given an encrypted string, encrypted using a very simple substitution cipher. Problem You do not know what the cipher is but you do know the ciphertext is English and that the most frequent ...
Thomas O's user avatar
  • 3,348
27 votes
19 answers
9k views

Print 1 to 1000 in C++ without semi-colons

Following this popular question, present your solution which prints the numbers 1 to 1000 (all of them, not the string "1 to 1000" verbatim or something funny) in C++ without using any semi-colons. ...
moinudin's user avatar
  • 12.7k
19 votes
5 answers
5k views

Print a random maze

Write a program that generates and prints a random maze using the algorithm of your choice. The maze should be different for multiple runs of the program. Height and width are given as command line ...
Alexandru's user avatar
  • 6,154
67 votes
140 answers
12k views

Reverse stdin and place on stdout

Requirements: Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.) Output the reverse ...
Thomas O's user avatar
  • 3,348
50 votes
48 answers
10k views

Reverse Polish notation

You must evaluate a string written in Reverse Polish notation and output the result. The program must accept an input and return the output. For programming languages that do not have functions to ...
user avatar
19 votes
12 answers
890 views

Compute modular inverse

Given two positive numbers \$x\$ and \$n\$ with \$x<2^n\$, write the shortest possible function to compute \$x^{-1} \mod 2^n\$. In other words, find \$y\$ such that \$xy=1 \mod 2^n\$. Your ...
Keith Randall's user avatar
18 votes
2 answers
1k views

Slot Machine Hacker

Problem: Slot Machine Hacker from Facebook Hacker Cup 2011 Round 1B Goal: Shortest code in your favourite language using stdin/stdout. You cannot assume ...
moinudin's user avatar
  • 12.7k
15 votes
4 answers
1k views

Freely available books for code golfing? [closed]

Can you recommend any freely available books about code golfing in general and especially in Java and C++?
53 votes
50 answers
8k views

Tips for golfing in PowerShell

What general tips do you have for golfing in Windows PowerShell? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to PowerShell (e.g. "...
Joey's user avatar
  • 13k
36 votes
16 answers
25k views

Drawing a cube in ASCII art

Task description: Draw a cube in ASCII art in roughly a cabinet projection. Monospaced fonts often have characters that are about twice as high as they are wide. ...
Joey's user avatar
  • 13k
6 votes
33 answers
3k views

Print largest integer you can with the fewest characters [closed]

Find a way to output a large integer with few characters. Solutions will be scored based on the magnitude of the number and shortness of code. EDIT: Let's impose a time limit of a minute on sensible ...
moinudin's user avatar
  • 12.7k
28 votes
37 answers
3k views

Finding "sub-palindromes".

The shortest code that finds all unique "sub-palindromes" of a string, that is: any substring with length > 1 that is a palindrome. eg.1 ...
Eelvex's user avatar
  • 5,512
76 votes
59 answers
20k views

Tips for code-golfing in C#

What general tips do you have for golfing in C#? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C# (e.g. "remove comments" is not an ...
jcolebrand's user avatar
  • 1,873
40 votes
55 answers
4k views

196 algorithm code golf

Write a short program for 196-algorithm. The algorithm starts from an integer, then adds its reverse to it until a palindrome is reached. e.g. ...
Eelvex's user avatar
  • 5,512
14 votes
1 answer
1k views

Shortest path in a graph

Write a program to take a graph (from either standard input or a file, your choice) and find a shortest path in the graph. Graphs are specified using the following format: ...
Keith Randall's user avatar
7 votes
3 answers
436 views

Compress programs

Write a program/script that decompresses and passes any compressed data appended at the end of the binary/file as standard input to a program specified as arguments. ...
Alexandru's user avatar
  • 6,154
11 votes
1 answer
740 views

Write a compressing util for gzip files

The task of this challenge is as following: Write a program that reads a file of reasonable size (let's say <16 MB) from stdin or anywhere else (however you like, but must not be hardcoded), and ...
FUZxxl's user avatar
  • 10.1k
63 votes
30 answers
20k views

Tips for golfing in C++

What general tips do you have for golfing in C++? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C++ (e.g. "remove comments" is not ...
moinudin's user avatar
  • 12.7k
38 votes
26 answers
33k views

Morse code translator

Write the shortest program to transform the standard input into Morse code. Characters not in the table should be printed as they are.
Alexandru's user avatar
  • 6,154
-3 votes
1 answer
5k views

Poisson random number generator [closed]

What is the shortest function (implemented in C) that will return a random draw from a Poisson distribution (given the mean or λ parameter)? ...
Daniel Standage's user avatar
11 votes
2 answers
4k views

Test if a given number is a Vampire Number [duplicate]

EDIT: In the interest of increasing the complexity, i've added more to the challenge. In mathematics, a vampire number (or true vampire number) is a composite natural number v, with an even ...
st0le's user avatar
  • 2,228
4 votes
5 answers
944 views

Tree traversal. [closed]

Write the shortest code that traverses a tree, breadth-first. Input any way you like Output a list of "names" of the nodes in correct order.
Eelvex's user avatar
  • 5,512
37 votes
61 answers
5k views

Sum of primes between given range

Write the shortest code for finding the sum of primes between \$a\$ and \$b\$ (inclusive). Input \$a\$ and \$b\$ can be taken from command line or stdin (space seperated) Assume \$1 \le a \le b \le ...
st0le's user avatar
  • 2,228
3 votes
3 answers
266 views

Sharing Inherited Land [closed]

You and your brother have inherited a rectanglar block of land. This block of land's corners are read in from stdio as TLX,TLY,TRX,TRY,BLX,BLY,BRX,BRY (all decimal ...
Dan McGrath's user avatar
  • 1,017
48 votes
41 answers
18k views

Obfuscated FizzBuzz Golf [closed]

Create the shortest possible obfuscated FizzBuzz implementation. To be considered obfuscated, it should satisfy at least one of the following: Does not contain any of the words "Fizz", "Buzz", or "...
mootinator's user avatar
  • 1,209
150 votes
335 answers
44k views

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...
C. K. Young's user avatar
  • 4,947
151 votes
79 answers
25k views

Interpret brainfuck

Write the shortest program in your favourite language to interpret a brainfuck program. The program is read from a file. Input and output are standard input and standard output. Cell size: 8bit ...
Alexandru's user avatar
  • 6,154
24 votes
38 answers
4k views

Reimplementing square root [duplicate]

Define a function, s, which takes a number and returns the square root. No use of library functions, such as Java's Math.sqrt() or PHP's built in sqrt(), allowed.
jtjacques's user avatar
  • 1,155
245 votes
455 answers
64k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
Rafe Kettler's user avatar
  • 2,727
330 votes
179 answers
142k views

Tips for golfing in Python

What general tips do you have for golfing in Python? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Python (e.g. "remove comments" is ...
moinudin's user avatar
  • 12.7k
14 votes
5 answers
768 views

Fast Topswops calculation [closed]

From AZSPCS: Suppose you have a deck containing n cards. Each card contains a number from 1 to n, and each number appears on exactly one card. You look at the number on the top card -- let's says it'...
Alexandru's user avatar
  • 6,154
12 votes
4 answers
2k views

Fast line drawing algorithm

The task is to find a way to draw a horizontal line in an array of 16-bit integers. We're assuming a 256x192 pixel array with 16 pixels per word. A line is a contiguous run of set (1) bits. Lines ...
Thomas O's user avatar
  • 3,348
40 votes
21 answers
7k views

Angle between the hands on a clock [duplicate]

Given the time in 24 hour format (2359 = 11:59pm) return the angle between the minute and hour hands on a standard clock (on the ...
Dan McGrath's user avatar
  • 1,017
5 votes
7 answers
916 views

Find an unknown very large number [closed]

Let's suppose there is a finite unknown number n (n can be very large, does not necessarily fit 64-bits; think of ...
Alexandru's user avatar
  • 6,154
12 votes
4 answers
1k views

fizz buzz in TMP [closed]

The Fizz Buzz problem is a very basic problem to solve that is used by some to weed out interviewees that don't know how to program. The problem is: ...
user avatar
64 votes
64 answers
9k views

The Luhn algorithm for verifying credit card numbers, etc

Challenge Write the shortest program or function to calculate the Luhn Algorithm for verifying (credit card) numbers. Luhn algorithm explained From RosettaCode, this algorithm for the purposes of ...
Chris Laplante's user avatar
32 votes
31 answers
16k views

Rand5() to Rand7() [closed]

You are provided with a function Rand5(). This function returns perfectly random (equal distribution) integers between 1 and 5. Provide the function Rand7(), which uses Rand5() to produce perfectly ...
Dan McGrath's user avatar
  • 1,017
9 votes
4 answers
2k views

N-Queens problem [closed]

In chess, a queen can move as far as as the board extends horizontally, vertically, or diagonally. Given a NxN sized chessboard, print out how many possible positions N queens can be placed on the ...
Dan McGrath's user avatar
  • 1,017
26 votes
14 answers
5k views

Hamming numbers

Hamming numbers are numbers which evenly divide a power of 60. Equivalently, their prime factors are all \$ \le 5 \$. Given a positive integer, print that many Hamming numbers, in order. Rules: Input ...
grokus's user avatar
  • 1,287
45 votes
69 answers
7k views

ROT-13 transform standard input

Task Read a string of characters and produce the ROT13 of it. All characters besides [a-zA-Z] should be output verbatim. Each letter in the output may be in any ...
MiffTheFox's user avatar
63 votes
117 answers
23k views

99 Bottles Of Beer [closed]

Recreate '99 bottles of beers on the wall'. The desired output is this: ...
Nick Berardi's user avatar

15 30 50 per page