# All Questions

11,085 questions
Filter by
Sorted by
Tagged with
4k 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, ...
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/...
532 views

### Perfect powers in more than one way?

Challenge Your task is to write a program or function which, given a positive integer N, finds all positive integers less than or equal to N that can be expressed as a perfect power in more than one ...
1k views

### Fix a broken random function

A friend has an add-on card in their computer which generates a perfectly random number from 1 to 5 inclusive. Unfortunately, they spilt cola on it somehow, and it now generates only 2's for all ...
459 views

### Integer to string with given radix

Write the shortest function to convert an integer into a numeric representation given a radix between 2 and 62. e.g.: to_string(351837066319, 31) => "codegolf"
411 views

### Minimum of last k

Write a function that takes two arguments: a number k and a list l, and that returns another list ...
113 views

### Five aligned points and some of the pairwise distances. Infer the relative positions! [closed]

Given five points on a straight line such that their pairwise distances are 1,2,4, ..., 14,18,20 (after ordering), find the respective positions of the five points (relative to the furthest point on ...
3k views

### Calculate 500 digits of pi

Write a program to calculate the first 500 digits of pi, meeting the rules below: It must be less than 500 characters in length. It cannot include "pi", "math.pi" or similar pi constants, nor may it ...
767 views

### Stable positive/negative separation [closed]

From SO. You are given an array with positive and negative integers. Write a function to change the elements order in the array such that negative integers are at the beginning, the positive integers ...
565 views

### Find the largest value of power.

Some numbers can be represented as perfect powers of other numbers. A number x can be represented as x = base^power for some integer base and power. Given an integer x you have to find the largest ...
605 views

### Find the number of x-digit numbers whose product of digits is N

Given two numbers N and x, find the number of x-digit numbers whose product of digits is N limits: N(<10^6) and x(<12) Sample Input: 8 3 Sample Output: 10
2k views

### Implement division

Implement a division algorithm in your favourite language which handles integer division. It need only handle positive numbers - but bonus points if it handles negative and mixed-sign division, too. ...
423 views

### Remainder When N divided by 2^M

Write the shortest code to find the remainder when an input number N is divided by 2^M. You cannot use /,* and % operator. ...
5k views

### Free a Binary Tree

So before you read some basic computer science concepts. A binary tree is a dynamically allocated structure (usually used for ordered storage). Because of its nature traversal of binary trees is ...
2k views

### Chris Pine's “Deaf Grandma”

I'm a mentor at RubyLearning and one of the exercises we give to our students is the "Deaf Grandma" exercise from Chris Pine's book "Learn to Program". Here's the description: Write a Deaf Grandma ...
3k views

### Write a JSON validator

Write a program that determines whether its input is valid JSON. Input: ASCII text: [\x00-\x7F]* Note: if ASCII is problematic, feel free to use another encoding, ...
4k views

### Self-compiling compiler [closed]

This is based on a talk on compilers I listened to a while back, but I, unfortunately, can't remember when or where. Create the shortest compiler in any language that can compile itself. Target any ...
1k views

### Implement glob Matcher

Implement a function of pattern and string to be matched, return true if the pattern matches the WHOLE string, otherwise false. Our glob pattern syntax is: ? ...
27k views

### Shortest URL regex match in JavaScript

Create the shortest regular expression that will roughly match a URL in text when run in JavaScript Example: ...
1k views

### Build a nine-level word guessing game

The basics: You'll need to provide a nine-level word guessing game in the fewest characters possible (in your language of choice). The metrics: Provide a word-list (one word per line, seperated by ...
6k views

### Drawing a gradient in ASCII art

Task description: Write a program as short as possible to draw a radial gradient in ASCII art. The size of the output grid is predefined. The center point and the characters to be used for the ...
7k views

### Sort a list of numbers [closed]

About Code-Bowling: In golf, you try to get the lowest score (smallest application, most elegant, etc). In Bowling, you try to get the highest score. So if you follow, the goal of a Code-Bowling ...
592 views

### Calculating areas.

The smallest code that gives the area between the curve p(x) = a0 + a1*x + a2*x2 + ..., the line y = 0, the line x = 0 and the line x = C (i.e. something like this: ) You can assume that p(x) >= 0 ...
826 views

### Split a word into parts with equal scores

Assuming A=1, B=2... Z=26, and the value of a word is the sum of these letter values, it is possible to split some words into two pieces such that they have equal values. For example, "wordsplit" can ...
1k views

### Forecast the weather

Write the shortest program to forecast the weather for the next 7 days The input (from stdin) is the weekday and the season The output (to stdout) is seven lines weekday and the temperature in ...
3k views

### Implement Bogosort

Is solving Sudoku too hard? Even the brute force version? Here's a coding exercise that's a little easier. I hope. :-P Write the shortest function to implement bogosort. In specific, your function ...
4k views

### Implement a Brute Force Sudoku Solver

Implement the shortest Sudoku solver using guessing. Since I have received a few request I have added this as an alternative question for those wishing to implement a brute force sudoku solver. ...
2k views

### Build an engine for a maze game

This is a follow up of Print a maze question. If you like this question, please add more maze generation algorithms ;). For this task you'll have to implement a game engine for one player who must ...
2k views

### IPv4 Integer Conversion Function

Write the shortest function to convert an IP address into it's integer representation and output it as an integer. To change an IPv4 address to it's integer representation, the following calculation ...
19k views

### Tips for golfing in Ruby

What general tips can you give for golfing in Ruby? I'm looking for ideas that can be applied to code golf problems in general that are specific to Ruby. (For example, "Remove comments" would not be ...
3k views

### Implement a Non-Guessing Sudoku Solver

Implement the shortest Sudoku solver. Sudoku Puzzle: ...
5k views

### Calculate ISBN-13 check digit

Write a function which, given the first 12 digits of an ISBN-13 code, will calculate the entire ISBN via calculating and appending an appropriate check digit. Your function's input is a string ...
6k views

### Binary tree encoding

Let's suppose you have a complete binary tree (i.e. each internal node has exactly two non empty descendants). Each node contains a nonzero integer. You are given the task of encoding and decoding the ...
519 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 ...
2k 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 ...
37k 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 ...
799 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 ...
696 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 ...
3k 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 ...
13k 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 ...
11k views

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. ...
4k 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 ...
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. ...
4k 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 ...
8k 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 ...
7k 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 ...
629 views

### Compute modular inverse

Given two positive numbers x and n with x<2^n, write the shortest possible function to ...