[MPlayer-dev-eng] Quiz [OT]

Felix Buenemann atmosfear at users.sourceforge.net
Fri Nov 7 02:52:43 CET 2003


On Friday 07 November 2003 01:46, Michael Niedermayer wrote:
> i hate perl ...
> ---
> #include <stdio.h>
> int main(int argc, char **argv){
> 	int i,j, len= strlen(argv[1])-4;
> 	for(i=0; i<1000; i++)
> 		for(j=0; j<len; j++)
> 			if(   isalpha(argv[1][j  ]) && isalpha(argv[1][j+1])
> 			   && isalpha(argv[1][j+2]) && isalpha(argv[1][j+3]))
> 				if((random()>>20)&1){
> 					int c= argv[1][j+1];
> 					argv[1][j+1] =argv[1][j+2];
> 					argv[1][j+2] = c;
> 				}
> 	printf("%s", argv[1]);
> }
> ---
>
> and yes, its icfineefint and solw, i konw
you could say that, it's 1800% slower then a bit modified version of my 
original perl code. (That's 430% faster then Jonas code. All tested on 70kb 
file :)

---changes-to-my-code---
sub randomize (@) {
    my $array = [split //, shift];
    for (my $i = @$array; -- $i;) {
        my $r = int rand ($i + 1);
       ($array -> [$i], $array -> [$r]) = ($array -> [$r], $array -> [$i]);
    }
    return join('', (@$array));
}
---changes-to-my-code---

-- 
Best Regards,
        Atmos
____________________________________________
- MPlayer Developer - http://mplayerhq.hu/ -
____________________________________________



More information about the MPlayer-dev-eng mailing list