aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2024-06-15 13:29:02 -0600
committerJoelle Maslak <jmaslak@antelope.net>2024-06-15 13:29:02 -0600
commit9377c989402c0a0184e67adc359b89eb86bf33ff (patch)
tree4945c97666cb099163419f1084a6490832ac0a6d
parent8f3e4397d6470c8a02791e455fea75fcd4e3c22a (diff)
downloadperlweeklychallenge-club-9377c989402c0a0184e67adc359b89eb86bf33ff.tar.gz
perlweeklychallenge-club-9377c989402c0a0184e67adc359b89eb86bf33ff.tar.bz2
perlweeklychallenge-club-9377c989402c0a0184e67adc359b89eb86bf33ff.zip
Joelle Maslak's Week 273 Submissions
-rw-r--r--challenge-273/joelle-maslak/perl5/ch-1.pl31
-rw-r--r--challenge-273/joelle-maslak/perl5/ch-2.pl29
-rw-r--r--challenge-273/joelle-maslak/raku/ch-1.raku13
-rw-r--r--challenge-273/joelle-maslak/raku/ch-2.raku11
4 files changed, 84 insertions, 0 deletions
diff --git a/challenge-273/joelle-maslak/perl5/ch-1.pl b/challenge-273/joelle-maslak/perl5/ch-1.pl
new file mode 100644
index 0000000000..1d26f44a42
--- /dev/null
+++ b/challenge-273/joelle-maslak/perl5/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+#
+# Copyright (C) 2024 Joelle Maslak
+#
+
+use JTM::Boilerplate 'script';
+
+MAIN: {
+ if ((scalar(@ARGV) != 2) or (length($ARGV[1]) != 1) or (length($ARGV[0]) < 1)) {
+ help();
+ exit(1);
+ }
+
+ calculate($ARGV[0], $ARGV[1]);
+}
+
+sub calculate($str, $char) {
+ # Calculate the percentage that a character appears
+ my $strlen = length($str);
+ my $count = scalar(grep { $_ eq $char } split(//, $str));
+
+ printf("Percentage of times character appears in string: %.0f%%\n", 100.0*$count/$strlen);
+}
+
+sub help() {
+ print STDERR "Calculate the percent of a string that contains a character\n";
+ print STDERR "You must provide two parameters:\n";
+ print STDERR "\n";
+ print STDERR " ch-1.pl <string> <character>\n";
+} \ No newline at end of file
diff --git a/challenge-273/joelle-maslak/perl5/ch-2.pl b/challenge-273/joelle-maslak/perl5/ch-2.pl
new file mode 100644
index 0000000000..003ebb6372
--- /dev/null
+++ b/challenge-273/joelle-maslak/perl5/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+#
+# Copyright (C) 2024 Joelle Maslak
+#
+
+use JTM::Boilerplate;
+
+MAIN: {
+ if ((scalar(@ARGV) != 1)) {
+ help();
+ exit(1);
+ }
+
+ calculate($ARGV[0]);
+}
+
+sub calculate($str) {
+ # Calculate the percentage that a character appears
+ my $check = $str =~ m/^[^b]*b(?!a)/;
+ say("Output: " . ($check ? "true" : "false"));
+}
+
+sub help() {
+ print STDERR "Calculate whether there is a 'b' in a string where the first 'b' isn't followed by an 'a'\n";
+ print STDERR "You must provide one parameter:\n";
+ print STDERR "\n";
+ print STDERR " ch-2.pl <string>\n";
+}
diff --git a/challenge-273/joelle-maslak/raku/ch-1.raku b/challenge-273/joelle-maslak/raku/ch-1.raku
new file mode 100644
index 0000000000..10a8eb6926
--- /dev/null
+++ b/challenge-273/joelle-maslak/raku/ch-1.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+use v6.d;
+
+#
+# Copyright © 2024 Joelle Maslak
+#
+
+sub MAIN(Str:D $str where $str.chars > 0, Str:D $char where $char.chars == 1) {
+ my $charcount = $str.comb.grep($char);
+ printf("Percentage of times character apears in string %.0f%%\n", 100.0*$charcount/$str.chars);
+}
+
+
diff --git a/challenge-273/joelle-maslak/raku/ch-2.raku b/challenge-273/joelle-maslak/raku/ch-2.raku
new file mode 100644
index 0000000000..9e61fcf34b
--- /dev/null
+++ b/challenge-273/joelle-maslak/raku/ch-2.raku
@@ -0,0 +1,11 @@
+#!/usr/bin/env raku
+use v6.d;
+
+#
+# Copyright © 2024 Joelle Maslak
+#
+
+sub MAIN(Str:D $str) {
+ my $match = $str ~~ m/^ <-[ b ]>* 'b' <!before 'a'>/;
+ say "Output: " ~ ($match ?? "true" !! " false");
+} \ No newline at end of file