diff options
| -rw-r--r-- | challenge-287/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-287/arne-sommer/raku/ch-1.raku | 115 | ||||
| -rwxr-xr-x | challenge-287/arne-sommer/raku/ch-2.raku | 8 | ||||
| -rwxr-xr-x | challenge-287/arne-sommer/raku/strong-password | 94 | ||||
| -rwxr-xr-x | challenge-287/arne-sommer/raku/strong-password-2 | 115 | ||||
| -rwxr-xr-x | challenge-287/arne-sommer/raku/strong-password-replace | 115 | ||||
| -rwxr-xr-x | challenge-287/arne-sommer/raku/valid-number | 8 |
7 files changed, 456 insertions, 0 deletions
diff --git a/challenge-287/arne-sommer/blog.txt b/challenge-287/arne-sommer/blog.txt new file mode 100644 index 0000000000..baf21c8655 --- /dev/null +++ b/challenge-287/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/strong-valid.html diff --git a/challenge-287/arne-sommer/raku/ch-1.raku b/challenge-287/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..ef546fa81e --- /dev/null +++ b/challenge-287/arne-sommer/raku/ch-1.raku @@ -0,0 +1,115 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str is copy, :v(:$verbose)); + +my ($length, $has-len, $has-lc, $has-uc, $has-digit); + +my $steps = 0; + +loop +{ + $length = $str.chars; + $has-len = $length >= 6; + $has-lc = so $str ~~ /<[a..z]>/; + $has-uc = so $str ~~ /<[A..Z]>/; + $has-digit = so $str ~~ /<[0..9]>/; + + my $has-three = so $str ~~ /(.) {} :my $c=$0; <?after $c ** 3>/; + + if $verbose + { + say ": Length: $length"; + say ": Has OK Length : $has-len"; + say ": Has Lower Case: $has-lc"; + say ": Has Upper Case: $has-uc"; + say ": Has Digit : $has-digit"; + say ": Has 3 repeated chars : $has-three"; + } + + last unless $has-three; + + my @tokens = tokenizer($str); + + say ": Tokens: { @tokens.join(";") }" if $verbose; + + my $new = ""; + for @tokens -> $token + { + $token.chars >= 3 + ?? ( $new ~= $token.substr(0,2) ~ get-char-to-add($token, $new ~ $str) ~ $token.substr(3); $steps++; ) + !! ( $new ~= $token ); + } + $str = $new; + say ": Str: $str\n" if $verbose; +} + +{ $steps++; $str ~= ('a'..'z').pick } unless $has-lc; +{ $steps++; $str ~= ('A'..'Z').pick } unless $has-uc; +{ $steps++; $str ~= ('0'..'9').pick } unless $has-digit; + +say ": Str: $str (after adding missing types)" if $verbose; + +while $str.chars < 6 +{ + $str ~= get-char-to-add($str); + $steps++; +} + +say ": Str: $str (after fixing length)" if $verbose; + +say $steps; + +sub tokenizer ($str) +{ + return gather + { + my @chars = $str.comb; + my $first = @chars.shift; + my $count = 1; + + while @chars + { + my $second = @chars.shift; + if $first ne $second + { + take $first x $count; + $first = $second; + $count = 1; + } + else + { + $count++; + } + } + + take $first x $count; + } +} + +multi sub get-char-to-add ($string) +{ + return ("a" .. "z", "0" .. "9").flat.pick if $string ~~ /<[A..Z]>$/; + return ("a" .. "z", "A" .. "Z").flat.pick if $string ~~ /<[0..9]>$/; + return ("A" .. "Z", "0" .. "9").flat.pick if $string ~~ /<[a..z]>$/; +} + +multi sub get-char-to-add ($string, $has) +{ + if $string ~~ /<[A..Z]>$/ + { + return ("a" .. "z").pick unless $has ~~ /<[a..z]>/; + return ("0" .. "9").pick; + } + + if $string ~~ /<[a..z]>$/ + { + return ("A" .. "Z").pick unless $has ~~ /<[A..Z]>/; + return ("0" .. "9").pick; + } + + if $string ~~ /<[0..9]>$/ + { + return ("A" .. "Z").pick unless $has ~~ /<[A..Z]>/; + return ("a" .. "z").pick; + } +} diff --git a/challenge-287/arne-sommer/raku/ch-2.raku b/challenge-287/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..7c512b765e --- /dev/null +++ b/challenge-287/arne-sommer/raku/ch-2.raku @@ -0,0 +1,8 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str, :v(:$verbose)); + +say ":Match Object: ", ( $str ~~ /^(<[+-]>?)(\d*)(\.?)(\d*)(<[eE]><[+-]>?\d+)?$/) if $verbose; + +say so $str ~~ /^(<[+-]>?)(\d*)(\.?)(\d*)(<[eE]><[+-]>?\d+)?$/ && ($1.Str || $3.Str); + diff --git a/challenge-287/arne-sommer/raku/strong-password b/challenge-287/arne-sommer/raku/strong-password new file mode 100755 index 0000000000..a1984d0c4c --- /dev/null +++ b/challenge-287/arne-sommer/raku/strong-password @@ -0,0 +1,94 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str is copy, :v(:$verbose)); + +my ($length, $has-len, $has-lc, $has-uc, $has-digit); + +my $steps = 0; + +loop +{ + $length = $str.chars; + $has-len = $length >= 6; + $has-lc = so $str ~~ /<[a..z]>/; + $has-uc = so $str ~~ /<[A..Z]>/; + $has-digit = so $str ~~ /<[0..9]>/; + + my $has-three = so $str ~~ /(.) {} :my $c=$0; <?after $c ** 3>/; + + if $verbose + { + say ": Length: $length"; + say ": Has OK Length : $has-len"; + say ": Has Lower Case: $has-lc"; + say ": Has Upper Case: $has-uc"; + say ": Has Digit : $has-digit"; + say ": Has 3 repeated chars : $has-three"; + } + + last unless $has-three; + + my @tokens = tokenizer($str); + + say ": Tokens: { @tokens.join(";") }" if $verbose; + + my $new = ""; + for @tokens -> $token + { + $token.chars >= 3 + ?? ( $new ~= $token.substr(0,2) ~ get-char-to-add($token) ~ $token.substr(2); $steps++; ) + !! ( $new ~= $token ); + } + $str = $new; + say ": Str: $str\n" if $verbose; +} + +{ $steps++; $str ~= ('a'..'z').pick } unless $has-lc; +{ $steps++; $str ~= ('A'..'Z').pick } unless $has-uc; +{ $steps++; $str ~= ('0'..'9').pick } unless $has-digit; + +say ": Str: $str (after adding missing types)" if $verbose; + +while $str.chars < 6 +{ + $str ~= get-char-to-add($str); + $steps++; +} + +say ": Str: $str (after fixing length)" if $verbose; + +say $steps; + +sub tokenizer ($str) +{ + return gather + { + my @chars = $str.comb; + my $first = @chars.shift; + my $count = 1; + + while @chars + { + my $second = @chars.shift; + if $first ne $second + { + take $first x $count; + $first = $second; + $count = 1; + } + else + { + $count++; + } + } + + take $first x $count; + } +} + +sub get-char-to-add ($string) +{ + return ("a" .. "z", "0" .. "9").flat.pick if $string ~~ /<[A..Z]>$/; + return ("a" .. "z", "A" .. "Z").flat.pick if $string ~~ /<[0..9]>$/; + return ("A" .. "Z", "0" .. "9").flat.pick if $string ~~ /<[a..z]>$/; +} diff --git a/challenge-287/arne-sommer/raku/strong-password-2 b/challenge-287/arne-sommer/raku/strong-password-2 new file mode 100755 index 0000000000..cc9312bf5a --- /dev/null +++ b/challenge-287/arne-sommer/raku/strong-password-2 @@ -0,0 +1,115 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str is copy, :v(:$verbose)); + +my ($length, $has-len, $has-lc, $has-uc, $has-digit); + +my $steps = 0; + +loop +{ + $length = $str.chars; + $has-len = $length >= 6; + $has-lc = so $str ~~ /<[a..z]>/; + $has-uc = so $str ~~ /<[A..Z]>/; + $has-digit = so $str ~~ /<[0..9]>/; + + my $has-three = so $str ~~ /(.) {} :my $c=$0; <?after $c ** 3>/; + + if $verbose + { + say ": Length: $length"; + say ": Has OK Length : $has-len"; + say ": Has Lower Case: $has-lc"; + say ": Has Upper Case: $has-uc"; + say ": Has Digit : $has-digit"; + say ": Has 3 repeated chars : $has-three"; + } + + last unless $has-three; + + my @tokens = tokenizer($str); + + say ": Tokens: { @tokens.join(";") }" if $verbose; + + my $new = ""; + for @tokens -> $token + { + $token.chars >= 3 + ?? ( $new ~= $token.substr(0,2) ~ get-char-to-add($token, $new ~ $str) ~ $token.substr(2); $steps++; ) + !! ( $new ~= $token ); + } + $str = $new; + say ": Str: $str\n" if $verbose; +} + +{ $steps++; $str ~= ('a'..'z').pick } unless $has-lc; +{ $steps++; $str ~= ('A'..'Z').pick } unless $has-uc; +{ $steps++; $str ~= ('0'..'9').pick } unless $has-digit; + +say ": Str: $str (after adding missing types)" if $verbose; + +while $str.chars < 6 +{ + $str ~= get-char-to-add($str); + $steps++; +} + +say ": Str: $str (after fixing length)" if $verbose; + +say $steps; + +sub tokenizer ($str) +{ + return gather + { + my @chars = $str.comb; + my $first = @chars.shift; + my $count = 1; + + while @chars + { + my $second = @chars.shift; + if $first ne $second + { + take $first x $count; + $first = $second; + $count = 1; + } + else + { + $count++; + } + } + + take $first x $count; + } +} + +multi sub get-char-to-add ($string) +{ + return ("a" .. "z", "0" .. "9").flat.pick if $string ~~ /<[A..Z]>$/; + return ("a" .. "z", "A" .. "Z").flat.pick if $string ~~ /<[0..9]>$/; + return ("A" .. "Z", "0" .. "9").flat.pick if $string ~~ /<[a..z]>$/; +} + +multi sub get-char-to-add ($string, $has) +{ + if $string ~~ /<[A..Z]>$/ + { + return ("a" .. "z").pick unless $has ~~ /<[a..z]>/; + return ("0" .. "9").pick; + } + + if $string ~~ /<[a..z]>$/ + { + return ("A" .. "Z").pick unless $has ~~ /<[A..Z]>/; + return ("0" .. "9").pick; + } + + if $string ~~ /<[0..9]>$/ + { + return ("A" .. "Z").pick unless $has ~~ /<[A..Z]>/; + return ("a" .. "z").pick; + } +} diff --git a/challenge-287/arne-sommer/raku/strong-password-replace b/challenge-287/arne-sommer/raku/strong-password-replace new file mode 100755 index 0000000000..ef546fa81e --- /dev/null +++ b/challenge-287/arne-sommer/raku/strong-password-replace @@ -0,0 +1,115 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str is copy, :v(:$verbose)); + +my ($length, $has-len, $has-lc, $has-uc, $has-digit); + +my $steps = 0; + +loop +{ + $length = $str.chars; + $has-len = $length >= 6; + $has-lc = so $str ~~ /<[a..z]>/; + $has-uc = so $str ~~ /<[A..Z]>/; + $has-digit = so $str ~~ /<[0..9]>/; + + my $has-three = so $str ~~ /(.) {} :my $c=$0; <?after $c ** 3>/; + + if $verbose + { + say ": Length: $length"; + say ": Has OK Length : $has-len"; + say ": Has Lower Case: $has-lc"; + say ": Has Upper Case: $has-uc"; + say ": Has Digit : $has-digit"; + say ": Has 3 repeated chars : $has-three"; + } + + last unless $has-three; + + my @tokens = tokenizer($str); + + say ": Tokens: { @tokens.join(";") }" if $verbose; + + my $new = ""; + for @tokens -> $token + { + $token.chars >= 3 + ?? ( $new ~= $token.substr(0,2) ~ get-char-to-add($token, $new ~ $str) ~ $token.substr(3); $steps++; ) + !! ( $new ~= $token ); + } + $str = $new; + say ": Str: $str\n" if $verbose; +} + +{ $steps++; $str ~= ('a'..'z').pick } unless $has-lc; +{ $steps++; $str ~= ('A'..'Z').pick } unless $has-uc; +{ $steps++; $str ~= ('0'..'9').pick } unless $has-digit; + +say ": Str: $str (after adding missing types)" if $verbose; + +while $str.chars < 6 +{ + $str ~= get-char-to-add($str); + $steps++; +} + +say ": Str: $str (after fixing length)" if $verbose; + +say $steps; + +sub tokenizer ($str) +{ + return gather + { + my @chars = $str.comb; + my $first = @chars.shift; + my $count = 1; + + while @chars + { + my $second = @chars.shift; + if $first ne $second + { + take $first x $count; + $first = $second; + $count = 1; + } + else + { + $count++; + } + } + + take $first x $count; + } +} + +multi sub get-char-to-add ($string) +{ + return ("a" .. "z", "0" .. "9").flat.pick if $string ~~ /<[A..Z]>$/; + return ("a" .. "z", "A" .. "Z").flat.pick if $string ~~ /<[0..9]>$/; + return ("A" .. "Z", "0" .. "9").flat.pick if $string ~~ /<[a..z]>$/; +} + +multi sub get-char-to-add ($string, $has) +{ + if $string ~~ /<[A..Z]>$/ + { + return ("a" .. "z").pick unless $has ~~ /<[a..z]>/; + return ("0" .. "9").pick; + } + + if $string ~~ /<[a..z]>$/ + { + return ("A" .. "Z").pick unless $has ~~ /<[A..Z]>/; + return ("0" .. "9").pick; + } + + if $string ~~ /<[0..9]>$/ + { + return ("A" .. "Z").pick unless $has ~~ /<[A..Z]>/; + return ("a" .. "z").pick; + } +} diff --git a/challenge-287/arne-sommer/raku/valid-number b/challenge-287/arne-sommer/raku/valid-number new file mode 100755 index 0000000000..7c512b765e --- /dev/null +++ b/challenge-287/arne-sommer/raku/valid-number @@ -0,0 +1,8 @@ +#! /usr/bin/env raku + +unit sub MAIN ($str, :v(:$verbose)); + +say ":Match Object: ", ( $str ~~ /^(<[+-]>?)(\d*)(\.?)(\d*)(<[eE]><[+-]>?\d+)?$/) if $verbose; + +say so $str ~~ /^(<[+-]>?)(\d*)(\.?)(\d*)(<[eE]><[+-]>?\d+)?$/ && ($1.Str || $3.Str); + |
