# fuzzy problem - Page 2

•  Subject
• Author
• Posted on

## Re: fuzzy problem

sharma__r@hotmail.com writes:

minimum lenght of 2'.

## Re: fuzzy problem

On Wednesday, 5 August 2015 12:19:00 UTC+5:30, Rainer Weikusat  wrote:

It is you who needs to ask, I have shown very unambiguously what consecutive means. If you have difficulty understanding then go back to school & stop wasting other's time.

## Re: fuzzy problem

sharma__r@hotmail.com writes:

"I don't agree with your opinion" and "I don't understand your opinion"
are two very much different things. In the given case, this means I
consider 1 a consecutive sequence of length 1 and I also believe the OP
meant to ask for 'the longest sequence' and not 'the longest sequence of
at least two digits'.

## Re: fuzzy problem

... and as a little wordplay I can't resist here: 'Following each other'
seems to describe a circular relationship so 11 definitely wouldn't
qualify as the 2nd one follows the 1st but the 1st doesn't follow the
2nd so they're not following each other ...

## Re: fuzzy problem

On 05.08.15 10:32, sharma__r@hotmail.com wrote:

In natural language, yes; given the usual mathematical
twists an turns, this fails: a pizza with 0 vegetable toppings
added one after the other is a veggie pizza; all cars of an empty
set following each other without interruptions are painted red;
n multiplied 0 times with itself is 1. There is "finding 0
or more consecutive occurrences of a character", which instead
could use "sequence", which again warrant asking for an
interpretation, as both words are derived from the same stem.
A messy area to which, I think, most of us are not properly
introduced during education. Different understandings ensue.

From this point of view only the OP could decide this?

# consecutive powers:
sub p {
\$_[1] > 0 ? \$_[0] * p(\$_[0], \$_[1] - 1) : 1
}
print p(-2, \$_), "\n" for 0 .. 10;

## Re: fuzzy problem

On 05.08.15 11:47, G.B. wrote:

I'm sorry, this should rather have been like:

use List::Util ('reduce');
sub p {
@consecutive_ns = (\$_[0]) x \$_[1];
reduce {\$a * \$b} @consecutive_ns or 1;
}
print p(2, \$_), "\n" for 0 .. 10;

## Re: fuzzy problem

That's a bad example here because the twist is really in the other
direction: Considering that 'a veggie pizza' is one with only vegetable
toppings, can a pizza whose only topping is onions be considered 'a
veggie pizza' despite the defintion clearly (!!1) used the plural form?
Likewise, should the program, given an input of '1001' and 'look for
ones' reply 1 or throw an "You're an idiot asking the wrong question!"
exception. I consider the former more likely.

## Re: fuzzy problem

On Wednesday, August 5, 2015 at 1:32:50 AM UTC-7, shar...@hotmail.com wrote:

Unambiguous in the usually accepted meaning of the word but mathematically it's much less clear. The OP's phrasing of "maximum number" could definitely suggest a less restrictive usage of the word "consecutive".

Asked what is the maximum number of consecutive pink or purple houses that would nauseate me,  I'd want to be sure to convey one would do it, not two or more.

--
Charles DeRykus

## Re: fuzzy problem

On Wednesday, August 5, 2015 at 11:14:53 AM UTC-7, C.DeRykus wrote:

In this case:  s/maximum//;

## Re: fuzzy problem

On 4/8/2015 18:37, bubunia2000ster@gmail.com wrote:

use strict; use warnings; use feature 'say';

my \$str = '1000000111111110101010100000000';

my \$last='';
my %max = my %cur = qw/0 0 1 0/;

while (\$str =~/[01]/g)
{
if (\$last eq \$&)
{
++\$cur > \$max and \$max = \$cur
}
else
{
\$cur=1
}

\$last = \$&
}

say \$max;
say \$max;

## Re: fuzzy problem

On 08/04/2015 08:37 AM, bubunia2000ster@gmail.com wrote:

What exactly are you after?  Do you want to know both
the max 1 and the max 0 in a row?  Or just who has the
most?

-T

Just of of curiosity, what is the application you
need this for?

## Re: fuzzy problem

I just wanted to find the maximum number of consecutive 1s and 0s and its length in a given string.

## Re: fuzzy problem

On 04.08.15 17:37, bubunia2000ster@gmail.com wrote:

sub l {
for (reverse 0 .. length \$str) {
return \$_ if (index \$str, \$_[0] x \$_) >= 0;
}
return -1;
}

print STDOUT (sort {\$b <=> \$a} l('0'), l('1'))[0];

## Re: fuzzy problem

Since the most straight-forward algorithm for this wasn't posted so far
('most straight-forward' wrt 'finding the longest') and als because it
works w/ a regex as 2nd parameter:

----------
\$str = "1000000111111110101010100000000101101";

sub longest_run
{
my (\$s, \$what, \$x);

\$s = \$_[0];
\$what = qr/\$_[1]/;

for (\$s) {
if (/\G(\$what+)/gc && length(\$1) > length(\$x)) {
\$x = \$1;
last if length() - pos() <= length(\$x);
}

/\G.+?(?=\$what)/g and redo;
}

return \$x;
}

print(longest_run(\$str, '0'), "\n");
print(longest_run(\$str, '10'), "\n");

## Re: fuzzy problem

this is two passes, not good ...

## Re: fuzzy problem

This is one-pass but with an overlapping \$what test.

## Re: fuzzy problem

On 6/8/2015 02:13, Rainer Weikusat wrote:

this is a pass for each pattern. that means two.

## Re: fuzzy problem

You're looking at the wrong code. The subroutine I posted will take a
string and a 'regex string' (I only tested combinations of 1 and 0) as
parameters and return the longest consecutive[*] sequence composed of
somethings matching the second argument existing in the first. It does
not find all consecutive sequences composed of at least two elements and
return the length of the largest of these.

[*] Suggestions for a way to express this such that it encompasses
sequences of any length > 0 without giving some semantic terrorist
the opportunity to point out that one implies 'singular' and 'more
than one' plural and - surely!! - no right-minded word would ever
want to refer to both cases very much welcome ...

## Re: fuzzy problem

On 06.08.15 11:48, Rainer Weikusat wrote:

... the longest sequence composed solely/exclusively/entirely
of somethings matching the second argument

... the longest sequence of just xs/nothing but xs

## Re: fuzzy problem

On 6/8/2015 12:48, Rainer Weikusat wrote:

for N patterns max lengths the subroutine must be called N times