aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-287/santiago-leyva/perl/ch-01.pl65
-rw-r--r--challenge-287/santiago-leyva/perl/ch-02.pl23
2 files changed, 88 insertions, 0 deletions
diff --git a/challenge-287/santiago-leyva/perl/ch-01.pl b/challenge-287/santiago-leyva/perl/ch-01.pl
new file mode 100644
index 0000000000..f545e66ffb
--- /dev/null
+++ b/challenge-287/santiago-leyva/perl/ch-01.pl
@@ -0,0 +1,65 @@
+
+use strict;
+use warnings;
+
+my @passwords = ('a',"aB2","PaaSW0rd","Paaasw0rd","aaaaa","axmlsa");
+
+foreach(@passwords){
+ print "--> checking password $_ | ";
+ my $result = checkPassword($_);
+ print "changes that need to be made: $result\n";
+}
+
+sub checkPassword {
+ my $pass = shift;
+ my $length = length($pass);
+ my $changes = 0;
+ my $least6 = $pass =~ /.{6,}/;
+ my $lower = $pass =~ /(?=.*[a-z])/;
+ my $upper = $pass =~ /(?=.*[A-Z])/;
+ my $digit = $pass =~ /(?=.*\d)/;
+ my $repeated = check3Repeated($pass);
+
+ #check if the length of the password is 6 or greater
+ if(!$least6){
+ my $remain = 6-$length;
+ if($remain == 1 and (!$lower or !$upper or !$digit)){
+ $changes++;
+ $changes += $remain;
+ return $changes;
+ }
+ $changes += $remain;
+ return $changes if $remain > 1;
+ }
+ if(!$lower){
+ $changes += 1;
+ }
+ if(!$upper){
+ $changes += 1;
+ }
+ if(!$digit){
+ $changes += 1;
+ }
+ if($repeated){
+ $changes += 1;
+ }
+ return $changes;
+}
+
+sub check3Repeated {
+ my $s = shift;
+ my @char = split("",$s);
+ my %map;
+ foreach(@char){
+ if(!exists($map{$_})){
+ $map{$_} = 1;
+ }else{
+ $map{$_} += 1;
+ }
+ }
+ my @values = sort {$a <=> $b} values %map;
+ if($values[-1] >= 3){
+ return 1;
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/challenge-287/santiago-leyva/perl/ch-02.pl b/challenge-287/santiago-leyva/perl/ch-02.pl
new file mode 100644
index 0000000000..8f3dc1cba6
--- /dev/null
+++ b/challenge-287/santiago-leyva/perl/ch-02.pl
@@ -0,0 +1,23 @@
+use Data::Dumper;
+use strict;
+
+my @input = ("1","a",".","1.2e4.2","-1.","+1E-8","44","1203ñ{}");
+#my @input = ("-1.","+1E-8","44","1203ñ{}");
+
+foreach(@input){
+ my $result = checkNumber($_);
+ print "for $_ -> $result \n";
+}
+
+sub checkNumber {
+ my $num = shift;
+
+ my @N = split(/\./,$num);
+ my $length = scalar @N;
+ if($length == 1){
+ return "True" if ($num =~ /\-*\+*\d+\.*$/g or $num =~ /^\d+e|E\d+$/);
+ }elsif($length == 2){
+ return "True" if ( ($num =~ $N[0] =~ /^\d+$/ and $N[1] =~ /^\d+$/ ) or ($N[0] =~ /^\d+$/ and $N[1] =~ /^\d+e\d+$|E\d+$/) );
+ }
+ return "false";
+} \ No newline at end of file