in reply to Detecting transpositions
Update: Forget it ;-/ Abigail's is MUCH better! ++ forprint comp( 'foo', 'ofo' ) ? "True\n" : "False\n"; print comp( 'foo', 'foo' ) ? "True\n" : "False\n"; print comp( 'abcde', 'bacde' ) ? "True\n" : "False\n"; print comp( 'abcde', 'cabde' ) ? "True\n" : "False\n"; sub comp { my($x,$y)= @_; my($xreg)=join('|', grep $_,map {$1.$3.$2.$4 if $x=~ /^(.{$_})(.)(.) +(.*)/ && $2 ne $3} 0..length $x); return $y=~ /^$xreg$/; }
Update: Thanks to dragonchild and perlguy for telling me that Abigail-II is a he ;-)
|
---|