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

learn more… | top users | synonyms

4
votes
1answer
20 views

Convert to and from the factorial number system

The Factorial Number System, also called factoradic, is a mixed radix numeral system. The factorials determine the place value of a number. In this system, the right most digit can be either 0 or 1, ...
3
votes
8answers
133 views

Evaluate the primorial of a number

The primorial of a number is the product of all the primes till that number, itself included. Input a number from STDIN and evaluate its primorial. Don't use libraries. Shortest code wins.
2
votes
4answers
160 views

Generate Pascal's Pyramid

Pascal's Pyramid is an extension of Pascal's Triangle to the third dimension. Starting with a 1 as the apex, the elements of each successive layer can be determined by summing the three numbers that ...
2
votes
3answers
116 views

Evaluate the binomial theorem!

Your mission, even if you don't accept it, is to input three numbers from STDIN or file: 5 0.5 6 What you must do is evaluate this: (5a + 0.5b)^6 This basically means that the first two ...
0
votes
2answers
118 views

How to shorten this J code? (Or write shorter code in another language)

I decided to learn J so that I could better take part in code golfing. Starting it off relatively simple, I tried writing a solution to this problem: Find the sum of all the multiples of 3 or 5 ...
7
votes
0answers
121 views

Find real roots of a polynomial

Write a self-contained program which when given a polynomial and a bound will find all real roots of that polynomial to an absolute error not exceeding the bound. Constraints I know that Mathematica ...
4
votes
3answers
237 views

ASCII-visualize a graph

Your mission, should you choose to accept it, is to input a series of point pairs that form a graph, like this: A,B C,A B,A A,D A,E F,G C,G You must then output an ASCII visualization of the ...
-5
votes
3answers
82 views

Write 'hello world' to standard output without using certain common words - C# only

The challenge is to write the string hello world to your processes standard output, using as few characters of code as possible. The following restrictions apply: The following words may not appear ...
8
votes
14answers
609 views

Print an arch of ascending / descending numbers

I figured an "arch" was the best way to describe this pattern of numbers: 1234567887654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 ...
16
votes
5answers
400 views

Shortest common superstring

Given a list of strings s_0, s_1, ..., s_n find the shortest string S that contains each of s_0, s_1, ..., s_n as a substring. Examples: S('LOREM', 'DOLOR', 'SED', 'DO', 'MAGNA', 'AD', ...
0
votes
5answers
230 views

exp function to an arbitrary double precision

Write a function to find the solution of e^x given x, and a precision in the form 0.000001. sample input and output: e(4,0.00001) will return 54.5981494762146, and the precision is +/- .00001. The ...
-3
votes
0answers
137 views

Given a string, what will the next items be? [closed]

Given a string that goes on for an unknown length, predict the next three elements in the stream. There will only be two different characters in the string, A and B, and the stream will end with an ...
-1
votes
1answer
216 views

Smallest C code to Crash an Operating System? [duplicate]

A shortest C program, that can crash the Operating system, either on a Windows or a Linux PC... Rules: The code is to be developed in C language, but it may use other api, specific to linux or ...
2
votes
7answers
296 views

letter combinations to make words

Find the combination of N number of letters that make up the most words of length N. For example: n r u -> run, urn dstu -> dust, stud (these are just examples, not the best combination of ...
-4
votes
6answers
129 views

Return the number of digits in any given number

Objective Given any terminating, rational number, return the number of digits the number contains. Do not count zeros if they're the last digits. Examples 0 returns 1 -1 returns 1 6.23 returns 3 ...
1
vote
0answers
172 views

Write a Polish notation interpreter, then change it to RPN in shortest number of chars

Write a program to convert Polish prefix notation to infix notation, then change it to an RPN-to-infix converter in the shortest number of chars. Your score is 100 minus the number of characters ...
0
votes
1answer
87 views

Tips for golfing in Tcl

What general tips do you have for golfing in Tcl? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Tcl (e.g. "remove comments" is not ...
4
votes
7answers
362 views

Evaluate the nth hyperoperation

I do realise that this is a bit math-y, but - here goes. In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the ...
2
votes
11answers
384 views

minigolf - display anything 3d [closed]

The goal is to write the smallest program in any language which displays any three dimensional output. It might be graphics, it might be ASCII art, but any reasonable person should immediately and ...
12
votes
4answers
570 views

Mozart golf - mini “Rondo”

Output "Mozart - Alla Turca" to stdout (see the sample for "reference implementation") Try to find how to pack both synthesizer and the music into minimal size. Requirements: Format suitable for ...
12
votes
11answers
509 views

Write the shortest self-identifying program (a quine variant)

Write a program that will generate a "true" output iff the input matches the source code of the program, and which generates a "false" output iff the input does not match the source code of the ...
5
votes
14answers
443 views

Meta Length Logarithms

Good Evening Golfers, Your challenge, this evening, is logarithmic, and (as Abed would put it) "Meta" Your goal is to write a program that takes an input from stdin or the command line, and returns ...
7
votes
4answers
311 views

Generate a golfed program to evaluate an arithmetic expression

Your task is to write a program that will take input like this: a + b * c + a / 2 and will generate the source code for a program that takes user input and then evaluates the expression. The ...
3
votes
6answers
489 views

Alex the Truck Driver

Alex is a Truck Driver who wants to find the quickest way to deliver goods to multiple cities. He knows the distances between his destinations, but you need to write a program to help him find the ...
2
votes
22answers
556 views

print this multiplication_table

Write shortest code to print the following multiplication_table: 1×1=1 1×2=2 2×2=4 1×3=3 2×3=6 3×3=9 1×4=4 2×4=8 3×4=12 4×4=16 1×5=5 2×5=10 3×5=15 4×5=20 5×5=25 1×6=6 2×6=12 3×6=18 4×6=24 ...
9
votes
4answers
481 views

Lawnmower Patterns

Taken from Google Code Jam 2013 Qualification Round Problem B: Alice and Bob have a lawn in front of their house, shaped like an N metre by M metre rectangle. Each year, they try to cut the lawn ...
0
votes
3answers
164 views

Hello World socket server

Write the shortest program that answers "Hello, World" to a network connection. Conditions: Program shall listen on port 12345 When a client connects, program shall write "Hello, World" to the ...
7
votes
3answers
257 views

Rosetta Stone Challenge: Draw a Box Plot

The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism! The Challenge Your challenge is to implement a program that ...
10
votes
5answers
361 views

“Cowsay” in short

Simulate cowsay in the default mode. $ cowsay <<< Hello _______ < Hello > ------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | ...
14
votes
24answers
1k views

Guess my Number - Code Golf [duplicate]

The puzzle is as follows: Create the traditional 'Guess my Number' game in as little keystrokes as possible. The player should input a guess between and including 1 and 100, and the computer should ...
-3
votes
7answers
447 views

Alien Name Generator

Task Write a function to generate names of aliens and their worlds, so that the output is of the form: Greetings Earthfolk, I am ____ of the planet _____. "Rules" Best space-sounding-ness to code ...
1
vote
2answers
129 views

Find the generating function of a sequence [duplicate]

Given a set of space-delimited integers, you've gotta either return a function that can generate that sequence, or return "There isn't any such function". Sample input: "1 11 41 79" - x^3+x^2-1 ...
8
votes
24answers
1k views

Rock Paper Scissors

Implement the classic rock paper scissors. Conditions: user will input 'r', 'p' or 's' program will output 'r', 'p' or 's' and the result program choice ('r', 'p' or 's') has to be pseudo random ...
2
votes
2answers
119 views

Zebra stripe command output

I have a script: $ cat ~/zebra.pl #!/bin/perl use Term::ANSIColor; $Term::ANSIColor::EACHLINE = "\n"; my $zebra = 1; # Are zebras black with white stripes, or white with black stripes?! my $black ...
19
votes
21answers
2k views

Shortest code to determine if a string is a palindrome

A palindrome is some string that is spelled the same way both backwards and forwards. For instance, 'Eva, can I stab bats in a cave?' is a palindrome (EVACANISTAB | BATSINACAVE) For this code golf, ...
7
votes
2answers
174 views

Write the shortest text getter/setter on an element for the DOM

Just like jQuery's $.fn.text, write one or two functions that can get and set the text on an element. You can't use textContent or innerText, and even less innerHTML. Plain javascript. No DOM ...
10
votes
5answers
268 views

Reverse each word in a line of text while keeping the order of the words, and capital letters/punctuation must remain in the same place

Create a program with the lowest amount of characters to reverse each word in a string while keeping the order of the words, as well as punctuation and capital letters, in their initial place. EDIT: ...
9
votes
6answers
385 views

Calculate the date of Easter

Your function or program should take a year as input and return (or print) the date (in the Gregorian calendar) of that years Easter (not the Eastern Orthodox Easter). The date returned should be ...
7
votes
3answers
218 views

Advanced Code Golf - Disk Operations, and File Allocation

Good Afternoon Golfgeneers. This is reasonably long and detailed question. Given what it was asking, it needed to be. If you have any questions, please ask them. If there is anything that isn't ...
4
votes
9answers
223 views

Write a function that reduces compositions of linear operators

You are given two functions g(x) and h(x), each of which takes an integer x and returns the number ax + b (where a and b are integers defined in the function). Your task is to write a function f(g, ...
7
votes
7answers
334 views

Sibling Rivalry

Objective Requirements A main 'parent' file and a 'child' file. The parent file creates a new child file that contains code that must execute after creation. The child file that is created must ...
3
votes
4answers
188 views

Count characters in lo..ol and print a phrase [duplicate]

Assuming 'lol' with a variavle number of 'o's. Print a the following phrase: What does 1st, 2nd, 3rd, 4th ... 'o' stand for? Examples: lol -> What does 1st 'o' stand for? loooool -> What ...
12
votes
19answers
872 views

Give the smallest number that has N divisors

Your function takes a natural number and returns the smallest natural number that has exactly that amount of divisors, including itself. Exemples: f(1) = 1 [1] f(2) = 2 [1, 2] f(3) = 4 [1, 2, 4] ...
-1
votes
1answer
118 views

Filling slot based on limit [closed]

Duplicate of http://stackoverflow.com/questions/15726734/iterating-item-in-a-loop I have a List<int> with the values like 60,45,45,45,45,30,60,60,15 people Also i have two slots. 1st slot is ...
17
votes
12answers
619 views

Incrementing Numbers, Over Multiple Sessions

Good Evening Golf Agents, Your mission is on behalf of notorious entertainment giant Eviltronic Arts. As part of their nefarious plan for world enslavement and entertainment, they must sell as many ...
4
votes
7answers
358 views

Find all the numbers have this property, its double and its triple contain each digit from 1 to 9 exactly once

192 is such a number, together with its double (384) and triple (576) they contain each 1-9 digit exactly once. Find all the numbers have this property. No input. Output: 192 384 576 219 438 657 ...
1
vote
4answers
341 views

secret language hackerrank.com

I tried this contest: https://www.hackerrank.com/challenges/secret-language Well, the score in this contest said I made 30 out of 30 points. As the score is calculated with the formula ...
12
votes
4answers
307 views

Find the Convex Hull of a set of 2D points

When you hammer a set of nails into a wooden board and wrap a rubber band around them, you get a Convex Hull. Your mission, should you decide to accept it, is to find the Convex Hull of a given set ...
6
votes
15answers
502 views

Triangle Area Side Side Side

Given three sides of a triangle, print area of this triangle. Test cases: In: 2,3,4 Out: 2.90473750965556 In: 3,4,5 Out: 6 Assume the three side a,b,c always a>0,b>0,c>0,a+b>c,b+c>a,c+a>b.
1
vote
1answer
163 views

Implement DFA/NFA/epsilon-NFA

Write the shortest code that implements a: DFA NFA epsilon-NFA The program should accept as input: a string(that we want to see if is accepted or not) the delta function, represented in ...

1 2 3 4 5 15