aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-287/mark-anderson/raku/ch-1.raku25
-rw-r--r--challenge-287/mark-anderson/raku/ch-2.raku15
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-287/mark-anderson/raku/ch-1.raku b/challenge-287/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..92a31564b7
--- /dev/null
+++ b/challenge-287/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+use Test;
+
+is strong-password('a'), 5;
+is strong-password('aB2'), 3;
+is strong-password('PaaSW0rd'), 0;
+is strong-password('Paaasw0rd'), 1;
+is strong-password('aaaaa'), 2;
+
+sub strong-password($str)
+{
+ my $missing;
+
+ $missing++ unless $str ~~ /<digit>/;
+ $missing++ unless $str ~~ /<lower>/;
+ $missing++ unless $str ~~ /<upper>/;
+
+ my $threes = ($str ~~ m:g/(.) $0 $0/).elems;
+ my $steps = max($threes, $missing);
+ my $chars = $steps + $str.chars;
+
+ $steps += 6 - $chars if $chars < 6;
+
+ $steps
+}
diff --git a/challenge-287/mark-anderson/raku/ch-2.raku b/challenge-287/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..282d66da2d
--- /dev/null
+++ b/challenge-287/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+use Test;
+
+ok valid-number("1");
+nok valid-number("a");
+nok valid-number(".");
+nok valid-number("1.2e4.2");
+ok valid-number("-1.");
+ok valid-number("+1E-8");
+ok valid-number(".44");
+
+sub valid-number($str)
+{
+ $str.subst(/\.$/, ~Empty).Num
+}