[MPlayer-dev-eng] Quiz [OT]

Michael Niedermayer michaelni at gmx.at
Fri Nov 7 01:46:26 CET 2003


Hi

On Friday 07 November 2003 00:53, Felix Buenemann wrote:
> Hi Jonas,
>
> On Thursday 06 November 2003 10:36, Jonas Fällman wrote:
> > Why a so long and strange code (such as split:ing @_ to @_) when it can
> > be done shorter (and probably a lot shorter than this one also):
> >
> > sub A{my($i)=@_;$i if(length($i)<4);@c=();while($i=~s/(.)//){$c[++$#c]=
> > $1};for($i=0;$i<=($#c*20);$i++){$a=int(rand($#c)+1);$b=int(rand($#c)+1
> > );next if $a==$b;$t=$c[$a];$c[$a]=$c[$b];$c[$b]=$t};return join("", at c)
> > };while(<>){chomp();$z="";s/\b(\w)(\w*?)(\w)\b/sprintf("%s%s%s",$1,
> > A($2),$3)/eg;print"$_\n"}
>
> Well, first your code is more obfuscated (which wasn't my goal), but has
> bugs: I guess you wanna write ... return $i if(length($i)<4); Although it
> really should be 3 not 4 so it directly returns on strings of length 2.
> This has the disadvantage that your code never exchanges strings of length
> 2 (it won't even if you remove that line).
> Then it should be my @c=(); and my $t=$c[$a] otherwise it won't compile
> with use strict. The bogus $z var can be removed. I think your code mangles
> line breaks (eg. \r\n ones).
>
> Nicely formatted your code is 28 lines vs. my 23 lines and 400% slower =)
> (320% with length($i)<4, even slower with 2 which would be correct, but
> isn't handled correctly by your code, eg. 2 char string is never shuffled)
>
> Btw. the splitting of $_[0] to @_ solves the purpose of creating an array
> of chars from a string, it won't work without that line.
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

[...]

-- 
Michael
level[i]= get_vlc(); i+=get_vlc();		(violates patent EP0266049)
median(mv[y-1][x], mv[y][x-1], mv[y+1][x+1]);	(violates patent #5,905,535)
buf[i]= qp - buf[i-1];				(violates patent #?)
for more examples, see http://mplayerhq.hu/~michael/patent.html
stop it, see http://petition.eurolinux.org & http://petition.ffii.org/eubsa/en



More information about the MPlayer-dev-eng mailing list