Pogledajte određenu poruku
Staro 04. 02. 2006.   #36
zextra
Boris
Grand Master
 
Avatar zextra
 
Datum učlanjenja: 01.12.2005
Lokacija: Novi Sad
Poruke: 775
Hvala: 5
156 "Hvala" u 2 poruka
zextra is on a distinguished roadzextra is on a distinguished road
Default

Moze i Perl (+ bash) za manje od 10 sec:

Kôd:
use Digest::MD5 qw/md5_hex/;
use Time::HiRes qw/gettimeofday/;

while( $i++ < 80_000 * 1.001 )
{
    my ( $m, $ms ) = gettimeofday;
    my $code = md5_hex( $m . $ms );

    for( $a = 0; $a < 25; $a++ )
    {
        print substr( $code, $a, 8 ), "\n";
    }
}
Manje petljanja - brze izvrsenje...

Kôd:
$ time perl rnd.pl > /dev/null

real    0m2.542s
user    0m2.452s
sys     0m0.032s

$ time perl rnd.pl | sort -u | head -n 2000000 | wc -l
2000000

real    0m9.187s
user    0m8.629s
sys     0m0.320s
Naravno, MATLAB opet odradi posao znatno brze. Pandan MATLAB-ovog resenja radi malo sporije (11 sec prosek), i generise neznatno vise duplikata (0.05% umesto 0.025%).
__________________
"It’s important to have goals when you pet. Otherwise you’re just rubbing another mammal for no reason." - Scott Adams

Poslednja izmena od zextra : 04. 02. 2006. u 11:33.
zextra je offline   Odgovorite uz citat