Linked Questions
12 questions linked to/from Randomizing until 0
175
votes
502
answers
36k
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 ...
334
votes
181
answers
147k
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 ...
173
votes
98
answers
70k
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 ...
168
votes
65
answers
42k
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 ...
103
votes
45
answers
13k
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 ...
45
votes
82
answers
5k
views
Print random integers until 0
You are to write a program which generates random integers between \$0\$ and \$99\$ inclusive, outputting each integer in turn, until \$0\$ is generated. You may choose which single-order random ...
53
votes
51
answers
8k
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. "...
70
votes
43
answers
12k
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 ...
40
votes
40
answers
11k
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 ...
28
votes
36
answers
8k
views
Pick a random number between 0 and n using a constant source of randomness
Task
Given a positive integer n less than 2^30 specified as input in any way you choose, your code should output a random ...
31
votes
27
answers
3k
views
Implement the random Fibonacci sequence
The random Fibonacci sequence is defined as follows:
$$
f_n =
\begin{cases}
f_{n-1}+f_{n-2} \text{ with probability } 1/2 \\
f_{n-1}-f_{n-2} \text{ with probability } 1/2 \\
\end{cases}
$$
$$
f_1 = ...
24
votes
16
answers
6k
views
Alice and Bob have a fight
Alice (A) and Bob (B) decided to have a battle.
Each combatant has 10 health.
They take turns to roll a 6 sided die for damage.
That damage is removed from their opponent's health.
In the end either ...