Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Longest possible run of a single character

by choroba (Cardinal)
on Sep 24, 2015 at 10:26 UTC ( [id://1142892]=note: print w/replies, xml ) Need Help??


in reply to Longest possible run of a single character

TIMTOWTDI. You can also get the positions of the "borders", i.e. places where the character sequences change:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $s = 'ABDBACCBBBCBDDBCDCBCCDBABCBABBBBBADACDABAC'; my $p = 0; my $max = 0; while ($s =~ /(?<=(.))(?!\1)/g) { my $l = pos($s) - $p; $max = $l if $l > $max; $p = pos $s; } say $max;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Longest possible run of a single character
by Anonymous Monk on Sep 24, 2015 at 21:46 UTC

    EXTREME TIMTOWTDI :)

    #!/usr/bin/perl -l # http://perlmonks.org/?node_id=551038 use strict; use warnings; $_ = 'ABDBACCBBBCBDDBCDCBCCDBABCBABBBBBADACDABACC'; print "longest run: ", length eval "'".s/(.)\K\B(?!\1)/'|'/gr."'";

      EXTREME TIMTOWTDI the other way around :)

      #!/usr/bin/perl -l # http://perlmonks.org/?node_id=551038 use strict; use warnings; $_ = 'ABDBACCBBBCBDDBCDCBCCDBABCBABBBBBADACDABACC'; print "longest run: ", length eval "'".s/(.)\1*\K/'|'/gr."'";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1142892]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found