Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save masak/158336 to your computer and use it in GitHub Desktop.
Save masak/158336 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl6
my %pwd-for;
for $*IN.lines() {
if $_ ~~ /^(\d+)\s+(\S+)/ {
%pwd-for{~$0} = ~$1;
}
}
my @types =
'total ' => /^/,
' alphanumerics-only ' => /^<alnum>+$/,
' digits-only ' => /^\d+$/,
' letters-only ' => /^<alpha>+$/,
' letters&u-score ' => /^[<alpha>*'_']+ <alpha>*$/ & /<alpha>/,
' letters&digits ' => /^[<alpha>*\d]+ <alpha>*$/ & /<alpha>/,
' letters&1digit ' => /^<alpha>*\d<alpha>*$/ & /<alpha>/,
' letters&2digits' => /^[<alpha>*\d]**2 <alpha>*$/ & /<alpha>/,
' letters&3digits' => /^[<alpha>*\d]**3 <alpha>*$/ & /<alpha>/,
' letters&4digits' => /^[<alpha>*\d]**4 <alpha>*$/ & /<alpha>/,
' letters&5digits' => /^[<alpha>*\d]**5 <alpha>*$/ & /<alpha>/,
' letters&6digits' => /^[<alpha>*\d]**6 <alpha>*$/ & /<alpha>/,
' with non-alnums ' => /<-alnum>/,
' 1 non-alnum ' => /^<alnum>*<-alnum><alnum>*$/,
' 2 non-alnums ' => /^[<alnum>*<-alnum>]**2 <alnum>*$/,
' 3 non-alnums ' => /^[<alnum>*<-alnum>]**3 <alnum>*$/,
;
my %occurrences;
my @pwds = %pwd-for.values;
for @types X @pwds -> $type, $pwd {
my ($name, $regex) = $type.kv;
if $pwd ~~ $regex {
++%occurrences{$name}
}
}
for @types>>.key {
my $occ = %occurrences{$_} // 0;
printf "%-22s%3d (%6.2f%%)\n", $_, $occ, $occ/@pwds*100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment