Re: mini-golf: first differing position
"Bernie Cosell" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Organization | Fantasy Farm Fibers |
| Message-ID | <[email protected]> |
On 20 Apr 2004 at 19:57, [email protected] wrote: > We want to find out the first position $n at which strings $x and $y > differ. If $x eq $y, then $n is undef. If $x ne $y but $x is a > prefix (aka initial segment) of $y, then $n should be equal to length > $x. The operation must preserve both $x and $y (i.e. destructive > operations are disallowed). How about [not golfing so the code is clearer]: my $diff = $x ^ $y; my ($len) = $diff =~ /^([\0])[^\0]/ ; return uhdef if not defined $len ; return length $len;' /Bernie\ -- Bernie Cosell Fantasy Farm Fibers mailto:[email protected] Pearisburg, VA --> Too many people, too few sheep <--