All Questions
4,642
questions
47
votes
14
answers
16k
views
Tips for golfing in 05AB1E
Do you have any tips for code-golfing in 05AB1E, a golfing language created by Adnan?
Your tips should be at least somewhat specific to 05AB1E.
Please post one tip per answer.
326
votes
177
answers
138k
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 ...
88
votes
58
answers
17k
views
Tips for golfing in Haskell
What general tips do you have for golfing in Haskell? I am looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Haskell. Please post only one ...
106
votes
39
answers
27k
views
Tips for golfing in Java
Are there any useful shortcuts that can be used in Java?
As shown below, import already adds at least 17 characters to a program.
...
242
votes
450
answers
63k
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 ...
515
votes
969
answers
188k
views
"Hello, World!"
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
102
votes
44
answers
12k
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 ...
162
votes
61
answers
39k
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 ...
173
votes
97
answers
67k
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 ...
50
votes
49
answers
7k
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. "...
138
votes
29
answers
12k
views
Making Future Posts Runnable Online with Stack Snippets [closed]
Stack Snippets were recently added to PPCG! Reminiscent of JSFiddle, Stack Snippets allow HTML, CSS, and JavaScript to be run directly in posts!
Here is a very simple Stack Snippet:
...
15
votes
14
answers
3k
views
I want 8 bits for every character!
This is the reverse of this challenge.
Given an encoded list of codepoints and the characters used to encode it, you need to decompress it to its original string.
For example, given the encoded list <...
75
votes
59
answers
20k
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 ...
234
votes
366
answers
65k
views
Is this number a prime?
Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in ...
70
votes
23
answers
7k
views
Tips for golfing in R
I'm looking for tips for golfing in the R statistical language. R is perhaps an unconventional choice for Golf. However, it does certain things very compactly (sequences, randomness, vectors, and ...
52
votes
43
answers
7k
views
Tips for golfing in Mathematica
What general tips do you have for golfing in Mathematica? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Mathematica (e.g. "remove ...
78
votes
53
answers
35k
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 ...
109
votes
43
answers
18k
views
Tips for Golfing in ECMAScript 6 and above
This is similar to other "Tips for golfing in <...>" but specifically targeting the newer features in JavaScript brought up in ECMAScript 6 and above.
JavaScript inherently is a very verbose ...
70
votes
43
answers
11k
views
Tips for golfing in Bash
What general tips do you have for golfing in Bash? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Bash (e.g. "remove comments" is not ...
289
votes
73
answers
79k
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 dump:...
550
votes
241
answers
134k
views
Showcase of Languages
Notes
This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not ...
149
votes
330
answers
42k
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 ...
43
votes
18
answers
5k
views
Tips for golfing in APL
I started one code golf challenge recently and it seems like the winner is GolfScript (surprise, surprise!). What's interesting is that there was another very strong competitor that had all chances to ...
65
votes
113
answers
17k
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 ...
52
votes
26
answers
14k
views
Tips for golfing in Perl?
What general tips do you have for golfing in Perl? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Perl (e.g. "remove comments" is not ...
49
votes
35
answers
8k
views
Tips for golfing in x86/x64 machine code
I noticed that there's no such question, so here it is:
Do you have general tips for golfing in x86/x64 machine code? If the tip only applies to a certain environment or calling convention, please ...
194
votes
413
answers
74k
views
1, 2, Fizz, 4, Buzz
Introduction
In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other ...
41
votes
40
answers
10k
views
Tips for golfing in PHP
What general tips do you have for golfing in PHP? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to PHP (e.g. "remove comments" is not ...
153
votes
82
answers
23k
views
Fewest (distinct) characters for Turing Completeness
Summary:
For any given language, what is the smallest amount of unique characters for your language to be Turing-Complete?
Challenge:
For any language of your choice, find the smallest subset of ...
58
votes
25
answers
16k
views
Tips for golfing in Jelly
Jelly is a tacit, golf-oriented programming language by our very own Dennis. It’s popping up in answers here more and more often, beating other golf-y languages like Pyth and CJam, both by using its ...
23
votes
12
answers
2k
views
Tips for golfing in MATL
MATL is a golfing language created by Luis Mendo. MATL has proven to be highly competitive, often beating submissions in other golfing languages such as Pyth, CJam and Jelly.
What are some useful ...
110
votes
328
answers
22k
views
Simple cat program
One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after ...
62
votes
30
answers
19k
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 ...
43
votes
18
answers
6k
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 ...
52
votes
6
answers
5k
views
Language Design: 2-D Pattern Matching
This is Fortnightly Challenge #6. Theme: Language Design
There's a chatroom for this challenge. Come and join us if you want to discuss ideas!
And now for something completely different...
This ...
18
votes
8
answers
2k
views
Tips for golfing in Whitespace
What general tips do you have for golfing in Whitespace? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Whitespace (e.g. "remove ...
150
votes
160
answers
22k
views
I double the source, you double the output!
Your task, if you wish to accept it, is to write a program that outputs a positive integer (higher than 0). The tricky part is that if I duplicate your source code, the output must be double the ...
19
votes
33
answers
3k
views
Tips for golfing in VBA
Similar to this, this, and this question...
What general tips do you have for golfing in VBA? I'm looking for ideas that can be applied to code golf problems in ...
144
votes
93
answers
31k
views
Largest Number Printable
Your goal is to write a program that prints a number. The bigger the number, the more points you'll get. But be careful! Code length is both limited and heavily weighted in the scoring function. Your ...
70
votes
48
answers
6k
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 ...
29
votes
8
answers
3k
views
Tips for golfing in Julia
What general tips do you have for golfing in Julia? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Julia (e.g. "remove comments" is ...
40
votes
17
answers
4k
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 ...
13
votes
10
answers
3k
views
Encode a program with the fewest distinct characters possible
The goal is to write a program that encodes an other program (input) with the fewest character possible.
Scoring
The score is equal to the different number of characters needed for the output.
Lower ...
358
votes
7
answers
50k
views
Upgoat or Downgoat?
Given an image of a goat, your program should best try to identify whether the goat is upside down, or not.
Examples
These are examples of what the input may be. Not actual inputs
Input:
Output:
<...
44
votes
34
answers
4k
views
Tips for golfing in CJam
CJam is a GolfScript-inspired stack-based golfing language, created by PPCG user aditsu.
So, in the vein of other language-specific tips questions:
What general tips do you have for golfing in CJam? ...
618
votes
320
answers
237k
views
Produce the number 2014 without any numbers in your source code
Note to challenge writers as per meta consensus:
This question was well-received when it was posted, but challenges
like this, asking answerers to Do X without using
Y
are likely to be poorly received....
172
votes
489
answers
35k
views
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:
Gets a ...
136
votes
144
answers
44k
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 ...
93
votes
168
answers
23k
views
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.
Lyrics:
...
92
votes
159
answers
13k
views
Determine whether strings are anagrams
Challenge
Given two strings, work out if they both have exactly the same characters in them.
Example
Input
word, wrdo
This returns true because they are the ...