Date: 11/27/2012 3:42 pm
Rating: 0
Russian Roulette
Write a program which plays Russian Roulette!
If the program is started,
- there should be a 5 in 6 chance of it ending normally after printing "I survived!"
- there should be a 1 in 6 chance of the program crashing. (segmentation fault, etc.)
No input, and no other outputs are allowed.
The randomness must be fair: it must have a uniform probability distribution. This means an uninitialized variable (or a RNG without seed) MOD 6 will not be sufficient.
If the solution works with only one dedicated operating system / platform, you will receive a 6 byte penalty to the score.
http://codegolf.stackexchange.com/questions/9062/russian-roulette?newsletter=1&nlcode=16624|abb2
There's wasn't a Perl version, yet; I came up with (stole):
which dies on zero, lives on 1-5. Shorter?
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk
Date: 11/29/2012 7:49 am
Rating: 0
afbach wrote:
On Tue, Nov 27, 2012 at 11:03 AM, Stack Exchange <do-not-reply@stackexchange.com> wrote:
Russian Roulette
Write a program which plays Russian Roulette!If the program is started,
- there should be a 5 in 6 chance of it ending normally after printing "I survived!"
- there should be a 1 in 6 chance of the program crashing. (segmentation fault, etc.)
No input, and no other outputs are allowed.
The randomness must be fair: it must have a uniform probability distribution. This means an uninitialized variable (or a RNG without seed) MOD 6 will not be sufficient.
If the solution works with only one dedicated operating system / platform, you will receive a 6 byte penalty to the score.
http://codegolf.stackexchange.com/questions/9062/russian-roulette?newsletter=1&nlcode=16624|abb2
There's wasn't a Perl version, yet; I came up with (stole):
perl -E '1/int rand(6);say "I survived!"'
which dies on zero, lives on 1-5. Shorter?
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org