Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Check a string for consecutive digits

by johngg (Canon)
on Nov 28, 2015 at 13:26 UTC ( [id://1148755]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Check a string for consecutive digits
in thread Check a string for consecutive digits

Sorry for the slow reply, $work rather got in the way. Yes, it can be adapted quite easily:-

use strict; use warnings; use 5.014; use re qw{ eval }; my $max = shift || 3; my $ascPatt = q{(?x) ( \d ) (??{ join q{}, map { $1 + $_ } 1 .. $max }) }; my $descPatt = q{(?x) ( \d ) (??{ join q{}, map { $1 - $_ } 1 .. $max }) }; my @passwords = qw{ 1234 1243 4321 298761 4562 4568 4578 123 12 1 01234 01243 04321 0298761 04562 04568 04578 0123 012 01 a1234 1a234 12a34 123a4 1234a a1b2c3 a12b34c56 a1b2c3d a12b34c56d a123b45c6 a12b345c6 a123b45c6d a12b345c6d 1a2 1ab2 12ab34 12abc34def 12abc34def567 abc ab12c 2345 234y 01234 2356 }; say qq{$_ - }, checkConsec( $_ ) ? q{too many consecutive digits} : q{pass} for @passwords; sub checkConsec { my $pw = shift; return 1 if $pw =~ m{$ascPatt}; return 1 if $pw =~ m{$descPatt}; return 0; }

Three runs, the first using the default of no more than three consecutive digits, then four and two.

johngg@shiraz:~/perl/Monks > ./spw1148625 1234 - too many consecutive digits 1243 - pass 4321 - too many consecutive digits 298761 - too many consecutive digits 4562 - pass 4568 - pass 4578 - pass 123 - pass 12 - pass 1 - pass 01234 - too many consecutive digits 01243 - pass 04321 - too many consecutive digits 0298761 - too many consecutive digits 04562 - pass 04568 - pass 04578 - pass 0123 - too many consecutive digits 012 - pass 01 - pass a1234 - too many consecutive digits 1a234 - pass 12a34 - pass 123a4 - pass 1234a - too many consecutive digits a1b2c3 - pass a12b34c56 - pass a1b2c3d - pass a12b34c56d - pass a123b45c6 - pass a12b345c6 - pass a123b45c6d - pass a12b345c6d - pass 1a2 - pass 1ab2 - pass 12ab34 - pass 12abc34def - pass 12abc34def567 - pass abc - pass ab12c - pass 2345 - too many consecutive digits 234y - pass 01234 - too many consecutive digits 2356 - pass johngg@shiraz:~/perl/Monks > ./spw1148625 4 1234 - pass 1243 - pass 4321 - pass 298761 - pass 4562 - pass 4568 - pass 4578 - pass 123 - pass 12 - pass 1 - pass 01234 - too many consecutive digits 01243 - pass 04321 - pass 0298761 - pass 04562 - pass 04568 - pass 04578 - pass 0123 - pass 012 - pass 01 - pass a1234 - pass 1a234 - pass 12a34 - pass 123a4 - pass 1234a - pass a1b2c3 - pass a12b34c56 - pass a1b2c3d - pass a12b34c56d - pass a123b45c6 - pass a12b345c6 - pass a123b45c6d - pass a12b345c6d - pass 1a2 - pass 1ab2 - pass 12ab34 - pass 12abc34def - pass 12abc34def567 - pass abc - pass ab12c - pass 2345 - pass 234y - pass 01234 - too many consecutive digits 2356 - pass johngg@shiraz:~/perl/Monks > ./spw1148625 2 1234 - too many consecutive digits 1243 - pass 4321 - too many consecutive digits 298761 - too many consecutive digits 4562 - too many consecutive digits 4568 - too many consecutive digits 4578 - pass 123 - too many consecutive digits 12 - pass 1 - pass 01234 - too many consecutive digits 01243 - too many consecutive digits 04321 - too many consecutive digits 0298761 - too many consecutive digits 04562 - too many consecutive digits 04568 - too many consecutive digits 04578 - pass 0123 - too many consecutive digits 012 - too many consecutive digits 01 - pass a1234 - too many consecutive digits 1a234 - too many consecutive digits 12a34 - pass 123a4 - too many consecutive digits 1234a - too many consecutive digits a1b2c3 - pass a12b34c56 - pass a1b2c3d - pass a12b34c56d - pass a123b45c6 - too many consecutive digits a12b345c6 - too many consecutive digits a123b45c6d - too many consecutive digits a12b345c6d - too many consecutive digits 1a2 - pass 1ab2 - pass 12ab34 - pass 12abc34def - pass 12abc34def567 - too many consecutive digits abc - pass ab12c - pass 2345 - too many consecutive digits 234y - too many consecutive digits 01234 - too many consecutive digits 2356 - pass johngg@shiraz:~/perl/Monks >

I hope this is helpful.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-23 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found