All Questions

Filter by
Sorted by
Tagged with
6
votes
5answers
940 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
3k 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 ...
9
votes
4answers
832 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
864 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
543 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
402 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
590 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
1k 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
620 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
6answers
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 ...
74
votes
178answers
15k 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 ...
52
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! ...
24
votes
7answers
3k 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 ...
19
votes
11answers
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, ...
19
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/...
13
votes
5answers
524 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 ...
18
votes
5answers
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 ...
13
votes
11answers
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"
6
votes
6answers
409 views

Minimum of last k

Write a function that takes two arguments: a number k and a list l, and that returns another list ...
2
votes
1answer
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 ...
25
votes
10answers
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 ...
7
votes
0answers
765 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 ...
6
votes
11answers
559 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 ...
8
votes
10answers
604 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
15
votes
31answers
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. ...
6
votes
8answers
421 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. ...
13
votes
5answers
4k 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 ...
22
votes
18answers
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 ...
12
votes
3answers
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, ...
35
votes
8answers
3k 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 ...
15
votes
12answers
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: ? ...
16
votes
4answers
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: ...
11
votes
7answers
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 ...
41
votes
12answers
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 ...
25
votes
33answers
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 ...
12
votes
6answers
590 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 ...
9
votes
9answers
821 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 ...
13
votes
10answers
991 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 ...
28
votes
37answers
2k 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 ...
20
votes
13answers
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. ...
9
votes
1answer
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 ...
17
votes
46answers
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 ...
62
votes
50answers
18k 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 ...
27
votes
2answers
3k views

Implement a Non-Guessing Sudoku Solver

Implement the shortest Sudoku solver. Sudoku Puzzle: ...

15 30 50 per page