On Fri, Feb 15, 2002 at 01:37:15AM -0500, Jeff 'japhy' Pinyan wrote:
> Except that you are forced to find a 2-character match, which means you
> end up skipping a POTENTIAL 3-character-or-more match.
Due to the while loop, we will keep looking for longer matches.
Otherwise, your version would hav
On Feb 14, Andrew Pimlott said:
>On Thu, Feb 14, 2002 at 10:20:50PM -0500, Jeff 'japhy' Pinyan wrote:
>> while ($str =~ m{ ([^\0]{$len,}) (?= [^\0]* \0 [^\0]*? \1 ) }xg) {
>
>Thanks to the comma, ^
>
>> $len = length($match = $1) + 1;
>> }
>
>this is O(N^3) in the case of no c
On Thu, Feb 14, 2002 at 10:20:50PM -0500, Jeff 'japhy' Pinyan wrote:
> while ($str =~ m{ ([^\0]{$len,}) (?= [^\0]* \0 [^\0]*? \1 ) }xg) {
Thanks to the comma, ^
> $len = length($match = $1) + 1;
> }
this is O(N^3) in the case of no common substring:
- 1 factor for the posit
Accidentally responded to originator, not list:
- Forwarded message from [EMAIL PROTECTED] -
On 14 Feb 02 at 10:25:13PM, Daniel R. Allen wrote:
> Thanks to all of the people who came up with answers. Ultimately the one
> I'm happiest with was the one Japhy emailed me, which shows that i
Thanks to all of the people who came up with answers. Ultimately the one
I'm happiest with was the one Japhy emailed me, which shows that it can
indeed be done in a regex. And it even works in perl 5.005. (see below).
-Daniel
#!/usr/bin/perl
sub lcs {
my $this = shift;
my $that = sh
Here's my regex code:
my $str = join "\0", $a, $b; # provided you know there are no NULs
my $len = 1;
my $match;
while ($str =~ m{ ([^\0]{$len,}) (?= [^\0]* \0 [^\0]*? \1 ) }xg) {
$len = length($match = $1) + 1;
}
When that's done, $len will be (for reasons of nefarity) one more
On 14 Feb 02 at 11:18:51AM, Daniel R. Allen wrote:
> Hi,
>
> Somebody asked on the Toronto Perlmongers list about finding the longest
> common (consecutive) substring of two thousand-character texts using perl.
> I've given a quick search and can find nothing definitive. [1]
Try this:
---
#
On Feb 14, Daniel R. Allen said:
>Somebody asked on the Toronto Perlmongers list about finding the longest
>common (consecutive) substring of two thousand-character texts using perl.
>I've given a quick search and can find nothing definitive. [1]
>
>She doesn't want the longest common subsequen
Am Don, 2002-02-14 um 17.18 schrieb Daniel R. Allen:
> finding the longest common (consecutive) substring
Here is a very straightforward approach (C-ish). All found substrings
are saved in a hash (this part could be optimized/replaced easily)...
sub common($$) {
my($x, $y) = @_;
my %comm
On Thu, Feb 14, 2002 at 05:54:01PM +, Stephen Turner wrote:
> No doubt the experts will be along with a slicker way soon...
I think the following should work, except maybe in the irksome
case the two strings only share one letter thatis at the end of
the second string. There's also p
Oops! Disregard what I wrote a minute ago - the below is better; I
had thought we were just looking for the longest string...
On Thursday, February 14, 2002, at 12:54 PM, Stephen Turner wrote:
> OK, this seems to be one way to do it, if I've understood the problem
> correctly. No doubt the ex
How about:
$longest;
split /\s+/; # ... on whitespace
for $string (@_) {
$longest = $string if (length($string) >= length($longest));
}
Since no one said what a string is, this should be fine. I/O is
left to the imagination of the reader :) There is a problem
however - if there are m
Yes, the common parts can occur anywhere in the string. The reference was
only to show the closest bit of code I could find using google, which
happened to be on this list. I expect if there's a neat way to do it,
somebody on this list knows how.
Restated- given two texts, find the longest iden
OK, this seems to be one way to do it, if I've understood the problem
correctly. No doubt the experts will be along with a slicker way soon...
#!/usr/bin/perl
sub lcs {
my($l,$off1,$off2,$i,$a,$b);
local $_;
for $i(-length($_[0])+1..length($_[1])-1) {
$a=($i>0)?$_[0]:substr($_
On Thu, 14 Feb 2002, Daniel R. Allen wrote:
> Hi,
>
> Somebody asked on the Toronto Perlmongers list about finding the longest
> common (consecutive) substring of two thousand-character texts using perl.
> I've given a quick search and can find nothing definitive. [1]
>
What exactly are the
Hi,
Somebody asked on the Toronto Perlmongers list about finding the longest
common (consecutive) substring of two thousand-character texts using perl.
I've given a quick search and can find nothing definitive. [1]
She doesn't want the longest common subsequence, where elements can be
chopped
Hey.
Somebody'd asked for Reverse od script (which a smarter monger than I did
as:
od -o | perl -ne 'split;shift @_;foreach (@_) {print
pack("S",oct)}'
) as octal/binary math is not my strong point what I came up w/ is this,
which seems to work:
#!/usr/bin/perl
while (<>) {
@oct = split;
John W. Krahn <[EMAIL PROTECTED]> wrote:
> "perl " is not included in the count. :-)
The space before switches is counted for file solutions, so it
seems it should be counted in comparing file solutions with one-
liners (but maybe you're not counting it for the file either).
--
Keith C. Ivey
On Jeudi 14 FĂ©vrier 2002 01:22, [EMAIL PROTECTED] wrote :
> You might be able to force them to officially accept it like this:
>
> #!/usr/bin/perl
> system("perl -e'")
>
> I think that's within the rules.
Excerpt from the rules:
The program may only use the perl executable, no other executab
On Wednesday 13 February 2002 16:15, John W. Krahn wrote:
> Yanick wrote:
> > On Wed, Feb 13, 2002 at 02:00:24PM -0800, John W. Krahn wrote:
> > > Yanick wrote:
> > > > perl -e'codecodecode'
> > > >
> > > > #!perl
> > > > codecodecode
> > > >
> > > > ? Unless I'm forgetting
20 matches
Mail list logo