Mailing List

Nested
Re: Code Golf Weekly Newsletter - Tuesday, November 27, 2012
User: afbach
Date: 11/27/2012 3:42 pm
Views: 345
Rating: 0


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
Re: Code Golf Weekly Newsletter - Tuesday, November 27, 2012
User: chrisdolan
Date: 11/29/2012 7:49 am
Views: 0
Rating: 0
Nice.

Trivially shorter (3 bytes):
perl -E'1/int rand 6;say"I survived!"'

Chris

On Nov 27, 2012, at 3:42 PM, <afbach@gmail.com> <afbach@gmail.com> wrote:

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

View Online



Madison Area Perl Mongers - MadMongers
http://www.madmongers.org

PreviousNext
Madison Area Perl Mongers