Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
12
votes
6answers
610 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
846 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
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 ...
29
votes
40answers
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 ...
20
votes
13answers
5k 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 ...
67
votes
51answers
20k 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 ...
28
votes
2answers
3k views

Implement a Non-Guessing Sudoku Solver

Implement the shortest Sudoku solver. Sudoku Puzzle: ...
30
votes
47answers
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 ...
8
votes
4answers
529 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 ...
9
votes
10answers
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 ...
125
votes
125answers
38k 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 ...
7
votes
29answers
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 ...
45
votes
13answers
14k 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 ...
27
votes
15answers
11k 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 ...
58
votes
100answers
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 ...
44
votes
43answers
8k 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 ...
17
votes
10answers
728 views

Compute modular inverse

Given two positive numbers x and n with x<2^n, write the shortest possible function to ...
17
votes
2answers
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 ...
14
votes
4answers
819 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++?
46
votes
43answers
5k 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. "...
32
votes
13answers
13k 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. ...
6
votes
33answers
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 ...
24
votes
31answers
2k 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 ...
65
votes
54answers
15k 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 ...
35
votes
46answers
3k 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. ...
12
votes
1answer
952 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: ...
6
votes
3answers
379 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. ...
11
votes
1answer
674 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 ...
53
votes
27answers
14k 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 ...
33
votes
25answers
26k 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.
-1
votes
1answer
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)? ...
14
votes
2answers
3k views

Test if a given number is a Vampire Number

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 ...
7
votes
5answers
822 views

Tree traversal.

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.
27
votes
42answers
4k views

Sum of primes between given range

Write the shortest code for finding the sum of primes between a and b (inclusive). Input a ...
50
votes
41answers
16k 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 "...
118
votes
248answers
28k 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 ...
115
votes
54answers
17k views

Interpret brainf***

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 ...
24
votes
38answers
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.
206
votes
342answers
47k 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 ...
269
votes
146answers
87k 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 ...
36
votes
21answers
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 ...
54
votes
46answers
6k 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 ...
21
votes
9answers
4k views

Hamming numbers

Given a positive integer, print that many hamming numbers, in order. Rules: Input will be a positive integer \$n \le 1,000,000 \$ Output should be the first n terms of https://oeis.org/A051037 ...
35
votes
53answers
5k views

ROT-13 transform standard input

The challenge: To read an input of arbitrary length and produce the ROT13 of the input. All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible. ...
96
votes
109answers
15k views

Code Golf Christmas Edition: How to print out a Christmas tree of height N

Given a number N, how can I print out a Christmas tree of height N using the least number of code characters? ...

1
190 191 192 193
194