logo       

AW: mini-golf: first differing position: msg#00041

Subject: AW: mini-golf: first differing position
No, this one also counts similarities after the first differing character.
$x = "abcfff"; $y = "abcggg";
correctly gives 3, but just try out
$x = "abcfff"; $y = "abcgff";
which gives you 5 because of the matching "f"s.

This way it should work:
$_=$x^$y; $n=s/[^\0]//?$-[0]:()

A little toyed around with kynn's idea:
for(split//,$x){$_eq substr($y,$n++,1)||last}$n x=$n<length$y

-Christian


> -----Ursprüngliche Nachricht-----
> Von: Terje Kristensen [mailto:terje.kristensen@xxxxxxxxx] 
> Gesendet: Mittwoch, 21. April 2004 07:49
> An: Fwp@Perl. Org
> Betreff: RE: mini-golf: first differing position
> 
> 
> This should work.
> 
> $_=$x^$y;$n=s/\0//g||undef
> 
> Terje
> 
> > -----Original Message-----
> > From: kynn@xxxxxxxxx [mailto:kynn@xxxxxxxxx]
> > Sent: Wednesday, April 21, 2004 2:02 AM
> > To: kynn@xxxxxxxxx
> > Cc: fwp@xxxxxxxx
> > Subject: Re: mini-golf: first differing position
> > 
> > 
> > 
> > 
> >    X-Original-To: kynn@xxxxxxxxx
> >    Mailing-List: contact fwp-help@xxxxxxxx; run by ezmlm
> >    X-Spam-Status: No, hits=0.3 required=7.0
> >        tests=NO_REAL_NAME
> >    X-Spam-Check-By: la.mx.develooper.com
> >    Date: Tue, 20 Apr 2004 19:57:27 -0400 (EDT)
> >    From: <kynn@xxxxxxxxx>
> > 
> > 
> > 
> > 
> >    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).
> > 
> >    By way of baseline, here's an utterly uninspired solution:
> > 
> >    $n=0;while(($c=substr($x,$n,1)||undef $n) && $c eq
> > substr($y,$n++,1)){;}
> > 
> > It's worse than uninspired, actually.  It's wrong.
> > 
> > kj
> 



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe