All Questions
63
votes
42answers
8k views
Tips for golfing in Python
What general tips do you have for golfing in Python? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Python (e.g. "remove comments" is ...
64
votes
72answers
15k 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:
...
36
votes
66answers
5k views
Golf you a quine for great good!
Using your language of choice, golf a quine.
No cheating -- that means that you can't just read the source file and print it. Also, in many languages, an empty file is also a quine: that isn't ...
38
votes
19answers
3k 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 an ...
50
votes
31answers
7k views
Interpret Brainfuck
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 ...
13
votes
43answers
2k views
List of primes under a million
This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines.
The task is to print out, in ascending order, all of the ...
17
votes
11answers
1k views
Golf a mutual quine
Using two languages of your choice, write the smallest “mutual quine” you can.
That is, write a program P in language A that outputs the source code for a program Q in language B, such ...
318
votes
97answers
53k views
Most creative way to display 42
Douglas Adams was born on March 11, 1952, and died when he was just 49. In honor of this wonderful writer, I challenge you to display 42 in the most creative way possible. Now this can be printed in ...
10
votes
41answers
4k views
Sum of positive integers. (Spoj - SIZECON)
Problem:
Given a set of integers, find the sum of all positive integers in it.
Input:
t – number of test cases [t < 1000]
On each of next t lines, an integer N [-1000 ≤ N ≤ 1000]
Output
...
364
votes
134answers
141k views
Produce the number 2014 without any numbers in your source code
So, now that it's 2014, it's time for a code question involving the number 2014.
Your task is to make a program that prints the number 2014, without using any of the characters 0123456789 in your ...
134
votes
54answers
51k views
We're no strangers to code golf, you know the rules, and so do I
Write the shortest program that prints the entire lyrics of "Never Gonna Give You Up" by Rick Astley.
Rules:
Must output the lyrics exactly as they appear in the above pastebin. Here's the raw ...
18
votes
4answers
2k views
Build a random number generator that passes the Diehard tests
While there are many code golf questions on here involving randomness, I haven't seen one yet that actually asks for building an algorithmic pseudorandom number generator. There's this one that asks ...
13
votes
13answers
1k views
Tips for golfing in <all languages>
The aim of this post is to gather all the golfing tips that can be easily applied to <all languages> rather than a specific one.
Only post answers that its logic can be applied to the majority ...
19
votes
14answers
2k views
Tips for golfing in GolfScript
What, this post doesn't exist yet?
Of course, GolfScript is made for golfing, so you might think that no specific tips are really needed. But to make full use of GolfScript's features, you need to ...
11
votes
29answers
2k 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 ...
13
votes
29answers
3k views
Generate Pascal's triangle
Pascal's triangle is generated by starting with a 1 on the first row. On subsequent rows, the number is determined by the sum of the two numbers directly above it to the left and right.
To ...
38
votes
36answers
6k views
Tips for golfing in JavaScript
What general tips do you have for golfing in JavaScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to JavaScript (e.g. "remove ...
22
votes
15answers
2k views
Transform number into 7-segment display pattern
Given two arbitrary numbers A,B. Print number B as a Digital LED Pattern where A is the scale.
input:
1 2320451640799518
ouput:
_ _ _ _ _ _ _ _ _ _ _ _
_| _| _|| ||_||_ ...
36
votes
73answers
5k views
The alphabet in programming languages
Our task is to, for each letter of the (English) alphabet, write a program that prints the alphabet, in a language whose name starts with that letter.
Input: none
Output:
abcdefghijklmnopqrstuvwxyz
...
17
votes
8answers
2k 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 ...
21
votes
18answers
3k views
Olympic Games Logo - Free Style Edition
In a similar spirit as this question, your mission is to create the best-looking logo in at most 1K of code.
Rules:
At most 1K of code (inclusive), no external data.
The answer with the most ...
19
votes
12answers
5k 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 ...
37
votes
67answers
5k views
Fibonacci function or sequence
Write the shortest code that either:
Generates a Fibonacci sequence (either in standard output, or as a stream)
Calculates, given n, the nth Fibonacci number
(I gave both options in case one is ...
10
votes
9answers
7k views
List of first n prime numbers most efficiently and in shortest code
Rules are simple:
First n primes (not primes below n), should be printed to standard output separated by newlines (primes should be generated within the code)
primes cannot be generated by an ...
10
votes
22answers
822 views
Tips for golfing in Windows 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. ...
4
votes
4answers
783 views
Converting integers to English words
The goal of this code golf is to convert integers to English words.
The program prompts for input. If this input isn't an integer, print NaN. If it is an integer, convert it to English words and print ...
91
votes
10answers
13k views
Emulate an Intel 8086 CPU
Note: A couple of answers have arrived. Consider upvoting newer answers too.
C from user1662116
C++ from Darius Goad
Postscript from luser droog
C++ from
JoeFish
Javascript from entirelysubjective
...
50
votes
70answers
7k views
Hello World 0.0!
source: Dilbert, September 8, 1992
I'm hoping to add a new twist on the classic "Hello World!" program.
Code a program that outputs Hello World! without:
String/Charachter literals
Numbers ...
30
votes
19answers
7k views
Most complex “Hello world” program you can justify
Your boss asks you to write a "hello world" program. Since you get paid for lines of code, you want to make it as complex as possible. However if you just add nonsense lines, or obviously useless or ...
37
votes
91answers
7k views
Shortest code to produce infinite output
Write the shortest code you can that produces an infinite output.
That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code ...
36
votes
10answers
2k views
Write a polyglot that prints the language's name
The task is to write a code which compiles in as many languages as possible, in as few characters as possible. To avoid trivial solutions, the program must print the name of the language it is ...
24
votes
72answers
4k views
Find the Factorial
Create the shortest function that finds the factorial of a natural number.
The factorial is found by multiplying a number by each of the digits that lead up to it.
5! = 5 * 4 * 3 * 2 * 1 = 120
...
16
votes
1answer
3k views
Solve the 15 Puzzle (the tile-sliding puzzle)
The 15 Puzzle is a famous puzzle involving sliding 15 tiles around on a 4x4 grid. Starting from a random configuration, the goal is to arrange the tiles in the correct order. Here is an example of a ...
24
votes
11answers
2k views
Palindromic palindrome checker
Write a program to test if a string is palindromic, with the added condition that the program be palindromic itself.
13
votes
62answers
5k views
Pi Calculation Code Golf
The Challenge
You must calculate pi in the shortest length you can. Any language is welcome to join and you can use any formula to calculate pi. It must be able to calculate pi to at least 5 decimal ...
13
votes
5answers
896 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 ...
16
votes
14answers
843 views
Creating a HQ9+ interpreter
The goal of this code golf is to create an interpreter for the programming language HQ9+
There are 4 commands in this programming language:
H - prints "Hello, world!"
Q - prints the source code of ...
11
votes
5answers
1k views
Brainfuck Golfer
One of easiest code written by a programming language is a program printing sequence of characters (ex. "Hello, world!"). However, some esoteric programming languages like Brainfuck, even this ...
3
votes
11answers
897 views
Implement a sorting algorithm with no change.
In this task, you have to write a program, that reads a string with a length of up to 1024 characters and prints it out sorted. In order to make an interesting task from a boring one, I set a few ...
2
votes
10answers
576 views
Return the first N primes
With a twist; your algorithm has to be less complex than O(X2) where X is the Nth prime. Your solution post should include the character count and the theoretical complexity in terms of X (or N, which ...
252
votes
94answers
136k views
Write a program that makes 2 + 2 = 5
Write a program that seemingly adds the numbers 2 and 2 and outputs 5. This is an underhanded contest.
Your program cannot output any errors. Watch out for memory holes! Input is optional.
...
104
votes
19answers
48k views
How slow is python really? (Or how fast is your language?)
I have this code which I have written in python/numpy
from __future__ import division
import numpy as np
import itertools
n=6
iters = 1000
firstzero = 0
bothzero = 0
""" The next line iterates over ...
125
votes
112answers
34k views
Weirdest way to produce a stack overflow
As a programmer you certainly know the error of a stack overflow due to an obvious recursion.
But there are certainly many weird and unusual ways to get your favourite language to spit that error out. ...
40
votes
34answers
11k views
Weirdest obfuscated “Hello World!”
Task:
Create an obfuscated program that prints Hello World! (exactly like that). Your program may not have any strings in it.
Rules:
You can use any programming language you like.
Make it as ...
35
votes
13answers
9k views
How Slow Is Python Really (Part II)?
This is a follow up to How slow is python really? (Or how fast is your language?).
It turns out it was a bit too easy to get a x100 speedup for my last question. For those who have enjoyed the ...
16
votes
4answers
3k views
Meta regex golf
In the spirit of this xkcd
Write a program that plays regex golf with arbitrary pairs of lists. The program should at least attempt to make the regex short, a program that just outputs ...
13
votes
26answers
2k 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.
...
7
votes
16answers
1k 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 ...
17
votes
30answers
2k views
Collatz Conjecture
This is the Collatz Conjecture:
Start with an integer n > 1.
Repeat the following steps:
If n is even, divide it by 2.
If n is odd, multiply it by 3 and add 1.
It is proven that for all ...
9
votes
13answers
1k views
Guess the number.
Description
Create a fully working "Guess the number" game. The game is played by two players as follows:
player one chooses a number (A) between 1 and N
player two tries to guess A choosing a ...