in reply to Monte Carlo approximation of PI

Very nice Abigail-II, but not slow enough! ;) If you will allow me to lift a few lines of your code, we can make it slower:
use strict; use warnings; use POE; my $in = 0; my $count = shift || 1000; POE::Session->create( inline_states => { _start => sub { rand () ** 2 + rand () ** 2 < 1 && $in ++ }, }, ) for 1 .. $count; POE::Kernel->run(); printf "Pi equals %f\n", 4 * $in / $count;
UPDATE: yes, this is very much an attempt at humor. :O) No disrespect meant to you or my new favorite app framework, POE. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Monte Carlo approximation of PI
by Abigail-II (Bishop) on Apr 04, 2003 at 20:53 UTC
    The remark "slow" in my code has nothing to do with code that is slow. The iterations themselves are quick enough. The algorithm is slow itself, taking about 10 times the previous amount of iterations to get one more correct digit (given a random generator that's good enough).

    I fail to understand your "addition". If you want to make the iterations slower, why not add a sleep 1 << 30?

    Abigail

      I think what jeffa was going for was what we mere mortals like to call "humour." Put down the blowtorch and laugh for a change :).