Code-golf is a competition to solve a particular problem in the fewest characters or bytes of source code. If source code length is not the primary scoring criterion, consider using another tag instead.

learn more… | top users | synonyms

0
votes
1answer
26 views

Quoting Big Brother

Task: Randomly choose one of the following two quotes and print that one quote, exactly as shown. 1: Under the spreading chestnut tree I sold you and you sold me. There lie they, and here lie we ...
-1
votes
3answers
36 views

Simplify a fraction

Your program must accept input from a fraction that can be simplified, then simplify it. Rules: If the fraction is already in its most simplified form, you must inform the user No built-in ...
1
vote
0answers
33 views

Write a book writer

Here is a fairly simple ASCII depiction of an open book: |\ | \ | \ | \ | \__________ | || | | || Lorem i | \ || psum do | \ || lor sit | \ || amet, | \ || consect | ...
6
votes
3answers
111 views

Kakuro Combinations

Kakuro Combinations Because I can't do mental arithmetic, I often struggle with the Kakuro Puzzle, which requires the victim to repeatedly work out which distinct numbers in the range 1 to 9 ...
6
votes
14answers
401 views

Rank a list of scores with “skips”

Given a list of scores (non-negative integers) pre-sorted from greatest to least: [ 10, 10, 6, 6, 4, 0] Assign each score an integer rank, beginning with 1 and ascending, such that equal scores ...
11
votes
24answers
2k views

The Real Slim Shady

Echo the following in as few bytes as possible: I'm Slim Shady. Yes, I'm the real Shady. All you other Slim Shadys are just imitating. So, won't the real Slim Shady please stand up? Please stand up. ...
5
votes
0answers
215 views

Trap the mouse!

Write the shortest program possible that traps the mouse cursor inside an upward pointing equilateral triangle with a side length of 274 pixels and a centroid at the exact middle of the screen. ...
1
vote
5answers
200 views

Modular exponentiation using only addition and subtraction

The challenge In the least number of source code characters, in a language of your choosing, devise a function which raises base a to power b, modulo m, using purely integer arithmetic, where a, b, ...
0
votes
5answers
246 views

Implement atoi function [duplicate]

You already know that the atoi function of stdlib.h converts a string to an integer. atoi (copied from here) int atoi (const char * str); Convert string to integer Parses the C-string ...
16
votes
0answers
375 views

Don't. Even. Blink

Your life could depend on this. Don't blink. Don't even blink. Blink and you're dead. They are fast. Faster than you can believe. Don't turn your back, don't look away, and don't blink! Good ...
5
votes
3answers
411 views

Create a FizzBuzz compiler

Welcome to the world of compiler golf. Your task is to write a program that generates another program to play a variant of FizzBuzz on spec. Your compiler Write a compiler that generates variants of ...
4
votes
3answers
276 views

When is my piversary?

Since I want to celebrate this definitely not nerdy event, your job is to calculate the piversary (pi-anniversary) of a given date. Input Your code has to have a possibilty to input a date in the ...
11
votes
8answers
753 views

Spell out numbers in French

There was a challenge to convert a number to its numeral in English, but that was too straightforward. Given a number 0–100, your task is to output the corresponding numeral in French. The French ...
20
votes
21answers
3k views

When was the last time the date was divisible by n?

A date can be represented by an unsigned integer as such: YYYYMMDD. What you need to do, is write the shortest program or function that figures out the most recent date whose number was divisible by a ...
2
votes
2answers
314 views

Find the closest pair of integers which will be neighbors when sorting an array

An integer V lies strictly between integers U and W if U < V < W or if U > V > W. A non-empty zero-indexed array A consisting of N integers is given. A pair of indices (P, Q), where 0 <= P ...
29
votes
11answers
4k views

Make a code square with your favorite word

Pick your favorite 6 letter common English word that has no repeated letters, such as wombat. Write a program in an N×N grid of characters without comments such that each row and column contains all ...
42
votes
12answers
3k views

Write the whole of the holed using the unholed

The ASCII characters from decimal code 33 to 126 are: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} Notice that in most fonts, 25 of these ...
30
votes
22answers
5k views

Draw the Sawtooth Alphabet

A simple one today. Write the shortest program that draws a "sawtooth alphabet" given a positive integer for the height. You must write the name of your programming language when you come to the ...
10
votes
1answer
515 views

How much time will I need to unlock my Android phone?

Scenario I am using pattern matching lockscreen and I sadly forgot my pattern. I would like to know how much time I will need to unlock it. Here are the specifications of Google's lock screen, that ...
-1
votes
0answers
121 views

Make a 'flashy' number squaring program [closed]

A flashy program is defined here as a program that does something simple in the most overblown way. Your task is to write a program that squares a number in a 'flashy' way: first, display a prompt ...
10
votes
23answers
2k views

Integer square root of integer

Problem: In your choice of language, write the shortest function that returns the floor of the square root of an unsigned 64-bit integer. Test cases: Your function must work correctly for all ...
3
votes
9answers
424 views

Base-2 integer logarithm of 64-bit unsigned integer

Problem: In your choice of language, write the shortest function that returns the floor of the base-2 logarithm of an unsigned 64-bit integer, or –1 if passed a 0. (Note: This means the return type ...
7
votes
11answers
534 views

Convert numbers to symbols without string or char literals

Read infinitely from stdin, and convert every number to the corresponding symbol on a US qwerty keyboard. No string or character literals anywhere are permitted. E.g. if the input is 117758326, the ...
7
votes
1answer
212 views

How many characters per character?

At http://shakespeare.mit.edu/ you can find the full text of each of Shakespeare's plays on one page (e.g. Hamlet). Write a script that takes in the url of a play from stdin, such as ...
15
votes
24answers
992 views

Convert a string of binary characters to the ASCII equivalents

Take a string of binary characters separated by a space, and convert it to an ASCII string. For example... 1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100 ...
8
votes
4answers
525 views

Weaving in ASCII

Imagine a rectangular grid of | characters represents the taut strings on a loom (the warp) that other threads (the weft), which we will represent as -, can be woven around. Here is the unwoven warp ...
4
votes
4answers
530 views

Efficient Way to solve this puzzle

A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic ...
4
votes
6answers
607 views

Mr. Moneybag's Money Piles

Mr. Moneybags is a very rich man. He has an assistant Mr. Perfect, who one day, got very mad, and shredded some of Mr. Moneybag’s $100 bills! Mr. Moneybags decided to punish Mr. Perfect. Mr. ...
15
votes
4answers
556 views

Three-pointer! But what kind?

From http://en.wikipedia.org/wiki/Triangle: Write a program that takes three 2d coordinate tuples (Cartesian), and classifies what shape these three points describe. In almost all cases these ...
10
votes
2answers
358 views

place vials in your centrifuge

This question originates in this reddit thread by reddit user taho_teg but it is expanded to a more general 'puzzle'. You have a centrifuge with 24 holes for the vials uniformly distributed in a ...
2
votes
1answer
243 views

Recursive Mathematical Puzzle from a high school contest

The problem appeared on the 2013 SJCNY High School Programming Contest. It was the last question in the set of problems and no team produced a correct answer during the 2.5 hours they had to work on ...
7
votes
8answers
882 views
+150

Write an IBAN validator

Write a program (the body of the function is enough) that accepts a string of alphanumeric characters and validates it according to ISO 13616:2007. The algorithm for validation is (source: wikipedia ...
1
vote
4answers
96 views

Generate the group table for Z_n

Groups are a widely used structure in Mathematics, and have applications in Computer Science. This code challenge is about the fewest # of characters to create a group table for the additive group ...
9
votes
8answers
878 views

What is your star-sign?

Write a program that takes a birth date (month and day-of-month) as input and outputs the corresponding sign, element and quality of the western zodiac. For the purposes of this challenge, these are ...
1
vote
0answers
97 views

Calculate the probability of seeing a landmark when starting at a given point and walking straight in a random direction

Input 5 integers: Landmark X & Y, Starting Point X & Y, and View Distance Radius D Output 1 double: % chance of coming within D of Landmark (X,Y) ("seeing") when walking straight in a random ...
11
votes
9answers
996 views

Write an interpreter for my esoteric language Jumper

I have thought up esoteric language Jumper. Later you will see why. It operates with random-access-memory with bytes as cells. RAM is zero indexed and initially filled with zeros. When trying access ...
6
votes
2answers
430 views

Solve the (Rubiks) Pocket Cube

Your task .. is to do what Brian Fantana apparently couldn't do, and solve the 2x2x2 Rubik's Cube. The Layout - - A B - - - - - - C D - - - - E F G H I J K L M N O P Q R ...
0
votes
0answers
135 views

Radical Operations [closed]

Scenario: Often times, it is useful to have a calculator that perform operations on radicals and keep then in simplified radical form. Your task is to create such a program that returns AN EXACT ...
1
vote
3answers
278 views

Solving Systems of Equations using Cramer's Rule

Create an algorithm that uses Cramer's Rule (with determinants of matrices) to solve for the solutions of a system of linear equations. The code should work for an "n" number of variables. You may ...
10
votes
3answers
884 views

Syllabify English words - kind of

You're tasked with writing a program that syllabifies words in a string of text, by separating them with a hyphen. That would be a lot of work, so you want to skip some parts, mainly because you don't ...
19
votes
5answers
590 views

Draw a Permutation Path

Imagine the following diagrams as sets of vertical criss-crossing tubes. 1 2 1 2 1 2 3 4 \ / \ / \ / \ / X | | | / \ / \ / \ / \ 2 1 1 2 | X | \ ...
7
votes
0answers
350 views

StackExchange Mustafa can't stand to be asked the same question three times

Austin: "Who sent you?" Mustafa: "You have to kill me!" Austin: "Who sent you?" Mustafa: "Kiss my ass, Powers!" Austin: "Who sent you?" Mustafa: "Dr. Evil." (...) ...
8
votes
3answers
530 views

Calculate to how many cubes one cube can be cut

Imagine some cube which we can cut into smaller cubes without remaining pieces. Find to how many cubes a cube can be cut. For example, a cube can be cut into 8, 27 (obviously 3rd powers of integers) ...
8
votes
2answers
722 views

Golfing for Domino Day

Given a setup of dominoes your task is to figure out which dominoes fall and which don't. Input Take a rectangular ASCII representation of a domino setup. The following characters are used for the ...
12
votes
3answers
685 views

Make me a window manager!

I hate code bloat! So I have decided to replace my Windows 7 system by a golfed version. However, I know that it is not easy, so let's build a prototype first. It will take a list of windows from the ...
11
votes
9answers
2k views

Write program which verifies Erdős–Straus conjecture

Write program, which verifies Erdős–Straus conjecture. Program should take as input one integern (3 <= n <= 1 000 000) and print triple of integers satisfying identity 4/n = 1/x + 1/y + 1/z, 0 ...
27
votes
5answers
2k views

Draw the Hilbert curve using slashes

The Hilbert curve is a space filling fractal that can be represented as a Lindenmayer system with successive generations that look like this: Thanks to ...
28
votes
5answers
2k views

Where does the laser go?

Take a 2-dimensional grid and draw a number of line segments on it to represent mirrors. Now pick a point to place a theoretical laser and an angle to define the direction it's pointing. The question ...
5
votes
5answers
329 views

Permutation Numbering

The Challenge For a given set of n integers, write a program which will output its lexicographic index. The Rules The input must only be a set of unique non-negative integers separated by spaces. ...
9
votes
24answers
3k views

Generate me some appropriate license plates!

The scenario: You are a software designer working for a gov't-run company that designs license plates for cars and other vehicles. You've been asked to develop software that generates license ...