From 6d1796003fe2615b57d22edde75ddecbbdc341c4 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jun 2024 08:09:08 +0000 Subject: Challenge 273 Solutions (Raku) --- challenge-273/mark-anderson/raku/ch-1.raku | 14 +++++++++ challenge-273/mark-anderson/raku/ch-2.raku | 49 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 challenge-273/mark-anderson/raku/ch-1.raku create mode 100644 challenge-273/mark-anderson/raku/ch-2.raku diff --git a/challenge-273/mark-anderson/raku/ch-1.raku b/challenge-273/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..33af93d32c --- /dev/null +++ b/challenge-273/mark-anderson/raku/ch-1.raku @@ -0,0 +1,14 @@ +#!/usr/bin/env raku +use Test; + +is perc-of-char('perl', 'e'), 25; +is perc-of-char('java', 'a'), 50; +is perc-of-char('python', 'm'), 0; +is perc-of-char('ada', 'a'), 67; +is perc-of-char('ballerina', 'l'), 22; +is perc-of-char('analitik', 'k'), 13; + +sub perc-of-char($str, $char) +{ + round 100 * $str.indices($char) / $str.chars +} diff --git a/challenge-273/mark-anderson/raku/ch-2.raku b/challenge-273/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..6abd68338d --- /dev/null +++ b/challenge-273/mark-anderson/raku/ch-2.raku @@ -0,0 +1,49 @@ +#!/usr/bin/env raku +use Test; + +ok b-after-a("aabb"); +nok b-after-a("abab"); +nok b-after-a("aaa"); +ok b-after-a("bbb"); +ok b-after-a("aaabxyzbcde"); +nok b-after-a("aaabxayzbcde"); +nok b-after-a("aaabxyzbcade"); +nok b-after-a("aaabxyzcde"); + +ok b-after-a-pos("aabb"); +nok b-after-a-pos("abab"); +nok b-after-a-pos("aaa"); +ok b-after-a-pos("bbb"); +ok b-after-a-pos("aaabxyzbcde"); +nok b-after-a-pos("aaabxayzbcde"); +nok b-after-a-pos("aaabxyzbcade"); +nok b-after-a-pos("aaabxyzcde"); + +ok b-after-a-indices("aabb"); +nok b-after-a-indices("abab"); +nok b-after-a-indices("aaa"); +ok b-after-a-indices("bbb"); +ok b-after-a-indices("aaabxyzbcde"); +nok b-after-a-indices("aaabxayzbcde"); +nok b-after-a-indices("aaabxyzbcade"); +nok b-after-a-indices("aaabxyzcde"); + +sub b-after-a($str) +{ + $str ~~ / ^ <-[b]>* b <-[a]>* b <-[a]>* $ / +} + +sub b-after-a-pos($str) +{ + my $b = $str ~~ m:1st / b / || return False; + my $a-after-b = $str ~~ m:1st:c($b.pos)/ a /; + my $b-after-b = $str ~~ m:1st:c($b.pos)/ b /; + $b-after-b and not $a-after-b +} + +sub b-after-a-indices($str) +{ + my @a = $str.indices('a'); + my @b = $str.indices('b'); + @b >= 2 && @b.head > all(@a) +} -- cgit From 08c32fe471035f7dd427b6312f79c7e9bae98723 Mon Sep 17 00:00:00 2001 From: pme Date: Mon, 10 Jun 2024 11:07:14 +0200 Subject: challenge-273 --- challenge-273/peter-meszaros/perl/ch-1.pl | 70 +++++++++++++++++++++++++++++++ challenge-273/peter-meszaros/perl/ch-2.pl | 57 +++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100755 challenge-273/peter-meszaros/perl/ch-1.pl create mode 100755 challenge-273/peter-meszaros/perl/ch-2.pl diff --git a/challenge-273/peter-meszaros/perl/ch-1.pl b/challenge-273/peter-meszaros/perl/ch-1.pl new file mode 100755 index 0000000000..85c79b6701 --- /dev/null +++ b/challenge-273/peter-meszaros/perl/ch-1.pl @@ -0,0 +1,70 @@ +#!/usr/bin/env perl +# +=head1 Task 1: Percentage of Character + +You are given a string, $str and a character $char. + +Write a script to return the percentage, nearest whole, of given character in +the given string. + +=head2 Example 1 + + Input: $str = "perl", $char = "e" + Output: 25 + +=head2 Example 2 + + Input: $str = "java", $char = "a" + Output: 50 + +=head2 Example 3 + + Input: $str = "python", $char = "m" + Output: 0 + +=head2 Example 4 + + Input: $str = "ada", $char = "a" + Output: 67 + +=head2 Example 5 + + Input: $str = "ballerina", $char = "l" + Output: 22 + +=head2 Example 6 + + Input: $str = "analitik", $char = "k" + Output: 13 + +=cut + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; + +my $cases = [ + [['perl', 'e'], 25], + [['java', 'a'], 50], + [['python', 'm'], 0], + [['ada', 'a'], 67], + [['ballerina', 'l'], 22], + [['analitik', 'k'], 13], +]; + +sub percentage_of_character +{ + my $str = $_[0]->[0]; + my $chr = $_[0]->[1]; + + my $num = () = $str =~ /$chr/gi; + return int($num / length($str) * 100.0 + 0.5); +} + +for (@$cases) { + is(percentage_of_character($_->[0]), $_->[1], $_->[2]); +} +done_testing(); + +exit 0; diff --git a/challenge-273/peter-meszaros/perl/ch-2.pl b/challenge-273/peter-meszaros/perl/ch-2.pl new file mode 100755 index 0000000000..397bf7518e --- /dev/null +++ b/challenge-273/peter-meszaros/perl/ch-2.pl @@ -0,0 +1,57 @@ +#!/usr/bin/env perl +# +=head1 Task 2: B After A + +You are given a string, $str. + +Write a script to return true if there is at least one b, and no a appears +after the first b. + +=head2 Example 1 + + Input: $str = "aabb" + Output: true + +=head2 Example 2 + + Input: $str = "abab" + Output: false + +=head2 Example 3 + + Input: $str = "aaa" + Output: false + +=head2 Example 4 + + Input: $str = "bbb" + Output: true + +=cut + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; + +my $cases = [ + ['aabb', 1], + ['abab', 0], + ['aaa', 0], + ['bbb', 1], +]; + +sub b_after_a +{ + my $str = shift; + + return $str =~ m/^[^b]*b[^a]+$/ ? 1 : 0; +} + +for (@$cases) { + is(b_after_a($_->[0]), $_->[1], $_->[2]); +} +done_testing(); + +exit 0; + -- cgit From a972a7f4601bd5647610a89df4858840e6fd9390 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 10 Jun 2024 09:25:40 +0000 Subject: w273 - Task 1 & 2 --- challenge-273/perlboy1967/perl/ch1.pl | 36 ++++++++++++++++++++++++++++++++++ challenge-273/perlboy1967/perl/ch2.pl | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 challenge-273/perlboy1967/perl/ch1.pl create mode 100755 challenge-273/perlboy1967/perl/ch2.pl diff --git a/challenge-273/perlboy1967/perl/ch1.pl b/challenge-273/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..1b63f8c4ec --- /dev/null +++ b/challenge-273/perlboy1967/perl/ch1.pl @@ -0,0 +1,36 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 273 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-273 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Percentage of Character +Submitted by: Mohammad Sajid Anwar + +You are given a string, $str and a character $char. + +Write a script to return the percentage, nearest whole, of given +character in the given string. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Test2::V0; + +sub percentageOfString ($str,$char) { + my %f; $f{$_}++ for (split(//,$str)); + int(0.5 + 100 * ($f{$char} // 0) / length($str)); +} + +is(percentageOfString('perl','e'),25,'Example 1'); +is(percentageOfString('java','a'),50,'Example 2'); +is(percentageOfString('python','m'),0,'Example 3'); +is(percentageOfString('ada','67'),0,'Example 4'); + +done_testing; diff --git a/challenge-273/perlboy1967/perl/ch2.pl b/challenge-273/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..db7ee646d1 --- /dev/null +++ b/challenge-273/perlboy1967/perl/ch2.pl @@ -0,0 +1,37 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 273 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-273 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: B After A +Submitted by: Mohammad Sajid Anwar + +You are given a string, $str. + +Write a script to return true if there is at least one 'b', and +no 'a' appears after the first 'b'. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Data::Printer; + +use Test2::V0; + +sub bAfterA ($str) { + 0 + ($str =~ m#^[^b]*b[^a]*$#); +} + +is(bAfterA('aabb'),1,'Example 1 (aabb)'); +is(bAfterA('abab'),0,'Example 2 (abab)'); +is(bAfterA('aaa'),0,'Example 3 (aaa)'); +is(bAfterA('bbb'),1,'Example 3 (bbb)'); + +done_testing; -- cgit From 15b218f8d0a57e1b1b1f97c2c804ce8f4fdce5a4 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 10 Jun 2024 11:56:41 +0200 Subject: Solve 273: Percentage of Character & B After A by E. Choroba --- challenge-273/e-choroba/perl/ch-1.pl | 20 ++++++++++++++++++++ challenge-273/e-choroba/perl/ch-2.pl | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 challenge-273/e-choroba/perl/ch-1.pl create mode 100755 challenge-273/e-choroba/perl/ch-2.pl diff --git a/challenge-273/e-choroba/perl/ch-1.pl b/challenge-273/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..7346da2e0f --- /dev/null +++ b/challenge-273/e-choroba/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +use POSIX qw{ round }; + +sub percentage_of_character($str, $char) { + my $count =()= $str =~ /\Q$char/g; + return round(100 * $count / length $str) +} + +use Test::More tests => 6; + +is percentage_of_character('perl', 'e'), 25, 'Example 1'; +is percentage_of_character('java', 'a'), 50, 'Example 2'; +is percentage_of_character('python', 'm'), 0, 'Example 3'; +is percentage_of_character('ada', 'a'), 67, 'Example 4'; +is percentage_of_character('ballerina', 'l'), 22, 'Example 5'; +is percentage_of_character('analitik', 'k'), 13, 'Example 6'; diff --git a/challenge-273/e-choroba/perl/ch-2.pl b/challenge-273/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..3ebdf460d3 --- /dev/null +++ b/challenge-273/e-choroba/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub b_after_a($str) { + $str =~ /^ # Start of the string. + [^b]* # Anything up to the first b. + b # The first b. + (?! # Not folllowed by... + .* # ... anything... + a # ... and a. + ) + /x +} + +use Test::More tests => 4; + +ok b_after_a('aabb'), 'Example 1'; +ok ! b_after_a('abab'), 'Example 2'; +ok ! b_after_a('aaa'), 'Example 3'; +ok b_after_a('bbb'), 'Example 4'; -- cgit From fad50cc7b38a6b9d1a86f8b4b6886d611f34610b Mon Sep 17 00:00:00 2001 From: Peter Campbell Smith Date: Mon, 10 Jun 2024 13:05:21 +0100 Subject: Week 273 - All about characters --- challenge-273/peter-campbell-smith/blog.txt | 1 + challenge-273/peter-campbell-smith/perl/ch-1.pl | 26 +++++++++++++++++++++++++ challenge-273/peter-campbell-smith/perl/ch-2.pl | 24 +++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 challenge-273/peter-campbell-smith/blog.txt create mode 100755 challenge-273/peter-campbell-smith/perl/ch-1.pl create mode 100755 challenge-273/peter-campbell-smith/perl/ch-2.pl diff --git a/challenge-273/peter-campbell-smith/blog.txt b/challenge-273/peter-campbell-smith/blog.txt new file mode 100644 index 0000000000..51209c8de0 --- /dev/null +++ b/challenge-273/peter-campbell-smith/blog.txt @@ -0,0 +1 @@ +http://ccgi.campbellsmiths.force9.co.uk/challenge/273 diff --git a/challenge-273/peter-campbell-smith/perl/ch-1.pl b/challenge-273/peter-campbell-smith/perl/ch-1.pl new file mode 100755 index 0000000000..5c83632497 --- /dev/null +++ b/challenge-273/peter-campbell-smith/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge + +use v5.26; # The Weekly Challenge - 2024-06-10 +use utf8; # Week 273 - task 1 - Percentage of character +use warnings; # Peter Campbell Smith +binmode STDOUT, ':utf8'; + +percentage_of_character('the cat sat on the mat', 'a'); +percentage_of_character('percentage of character', 'g'); +percentage_of_character('the weekly challenge', 'z'); +percentage_of_character('zzzzzzzzzzzzzzzzzz', 'z'); + +sub percentage_of_character { + + my ($str, $char, $chars); + + # remove $char from $str + ($str, $char) = @_; + $chars = $str; + $chars =~ s|[^$char]+||g; + + say qq[\nInput: \$str = '$str', \$char = '$char']; + say qq[Output: ] . int(length($chars) / length($str) * 100 + 0.5); +} diff --git a/challenge-273/peter-campbell-smith/perl/ch-2.pl b/challenge-273/peter-campbell-smith/perl/ch-2.pl new file mode 100755 index 0000000000..9e4b5701f8 --- /dev/null +++ b/challenge-273/peter-campbell-smith/perl/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge + +use v5.26; # The Weekly Challenge - 2024-06-10 +use utf8; # Week 273 - task 2 - B after a +use warnings; # Peter Campbell Smith +binmode STDOUT, ':utf8'; + +b_after_a('aabb'); +b_after_a('abab'); +b_after_a('aaa'); +b_after_a('bbb'); +b_after_a('ccc'); +b_after_a('Write a script to return true if there is at least one b'); + +sub b_after_a { + + my $str = $_[0]; + + # match a 'b', and then match no 'a' in the rest of the string + say qq[\nInput: \$str = '$str']; + say qq[Output: ] . (($str =~ m|b(.*)| and $1 =~ m|^[^a]*$|) ? 'true' : 'false'); +} -- cgit From 2243e21438f7c7a143e6873f8bafa21835d6db69 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 10 Jun 2024 09:45:26 -0400 Subject: Week 273 --- challenge-273/zapwai/c/ch-1.c | 32 +++++++++++++++++++++++++ challenge-273/zapwai/c/ch-2.c | 41 +++++++++++++++++++++++++++++++++ challenge-273/zapwai/javascript/ch-1.js | 24 +++++++++++++++++++ challenge-273/zapwai/javascript/ch-2.js | 36 +++++++++++++++++++++++++++++ challenge-273/zapwai/perl/ch-1.pl | 22 ++++++++++++++++++ challenge-273/zapwai/perl/ch-2.pl | 29 +++++++++++++++++++++++ challenge-273/zapwai/python/ch-1.py | 26 +++++++++++++++++++++ challenge-273/zapwai/python/ch-2.py | 29 +++++++++++++++++++++++ challenge-273/zapwai/rust/ch-1.rs | 26 +++++++++++++++++++++ challenge-273/zapwai/rust/ch-2.rs | 38 ++++++++++++++++++++++++++++++ 10 files changed, 303 insertions(+) create mode 100644 challenge-273/zapwai/c/ch-1.c create mode 100644 challenge-273/zapwai/c/ch-2.c create mode 100644 challenge-273/zapwai/javascript/ch-1.js create mode 100644 challenge-273/zapwai/javascript/ch-2.js create mode 100644 challenge-273/zapwai/perl/ch-1.pl create mode 100644 challenge-273/zapwai/perl/ch-2.pl create mode 100644 challenge-273/zapwai/python/ch-1.py create mode 100644 challenge-273/zapwai/python/ch-2.py create mode 100644 challenge-273/zapwai/rust/ch-1.rs create mode 100644 challenge-273/zapwai/rust/ch-2.rs diff --git a/challenge-273/zapwai/c/ch-1.c b/challenge-273/zapwai/c/ch-1.c new file mode 100644 index 0000000000..ee9a057bc9 --- /dev/null +++ b/challenge-273/zapwai/c/ch-1.c @@ -0,0 +1,32 @@ +#include +#include + +void proc(char* mystr, char mychar) { + printf( "Input: str = %s, char = %c\n", mystr, mychar); + int cnt = 0; + for (int i = 0; i < strlen(mystr); i++) + if (mystr[i] == mychar) + cnt++; + int inty = 100*((float) cnt / strlen(mystr)); + float r = 100*((float) cnt / strlen(mystr)) - inty; + if (r >= .5) + inty++; + printf("Output: %d\n", inty); +} + +int main() { + char* mystr = "perl"; + char mychar = 'e'; + proc(mystr, mychar); + mystr = "java"; mychar = 'a'; + proc(mystr, mychar); + mystr = "python"; mychar = 'm'; + proc(mystr, mychar); + mystr = "ada"; mychar = 'a'; + proc(mystr, mychar); + mystr = "ballerina"; mychar = 'l'; + proc(mystr, mychar); + mystr = "analitik"; mychar = 'k'; + proc(mystr, mychar); +} + diff --git a/challenge-273/zapwai/c/ch-2.c b/challenge-273/zapwai/c/ch-2.c new file mode 100644 index 0000000000..832af95751 --- /dev/null +++ b/challenge-273/zapwai/c/ch-2.c @@ -0,0 +1,41 @@ +#include +#include +#include + +void proc(char* str) { + printf( "Input: str = %s\n", str); + bool ver = false; + int bcnt = 0; + for (int i = 0; i <= strlen(str); i++) + if (str[i] == 'b') + bcnt++; + if (bcnt > 0) { + ver = true; + bool bflag = false; + for (int i = 0; i <= strlen(str); i++) { + char l = str[i]; + if ((l == 'a') && bflag) { + ver = false; + break; + } else { + if (l == 'b') + bflag = true; + } + } + } + printf( "Output: "); + printf((ver) ? "true" : "false"); + printf("\n"); +} + +int main() { + char* str = "aabb"; + proc(str); + str = "abab"; + proc(str); + str = "aaa"; + proc(str); + str = "bbb"; + proc(str); +} + diff --git a/challenge-273/zapwai/javascript/ch-1.js b/challenge-273/zapwai/javascript/ch-1.js new file mode 100644 index 0000000000..403abc52e6 --- /dev/null +++ b/challenge-273/zapwai/javascript/ch-1.js @@ -0,0 +1,24 @@ +let mystr = "perl"; let mychar = "e"; +proc(mystr, mychar); +mystr = "java"; mychar = "a"; +proc(mystr, mychar); +mystr = "python"; mychar = "m"; +proc(mystr, mychar); +mystr = "ada"; mychar = "a"; +proc(mystr, mychar); +mystr = "ballerina"; mychar = "l"; +proc(mystr, mychar); +mystr = "analitik"; mychar = "k"; +proc(mystr, mychar); + +function proc(mystr, mychar) { + console.log("Input: mystr =", mystr, "mychar =", mychar); + let cnt = 0; + for (let l of mystr) { + if (l == mychar) { + cnt++; + } + } + let i = 100*(cnt / mystr.length); + console.log( "Output:", Math.round(i)); +} diff --git a/challenge-273/zapwai/javascript/ch-2.js b/challenge-273/zapwai/javascript/ch-2.js new file mode 100644 index 0000000000..24ea47ef22 --- /dev/null +++ b/challenge-273/zapwai/javascript/ch-2.js @@ -0,0 +1,36 @@ +let mystr = "aabb"; +proc(mystr); +mystr = "abab"; +proc(mystr); +mystr = "aaa"; +proc(mystr); +mystr = "bbb"; +proc(mystr); + +function proc(mystr) { + console.log( "Input: mystr =", mystr); + let ver = 0; + for (let l of mystr) { + if (l == 'b') { + ver = 1; + } + } + if (ver == 1) { + let bflag = 0; + for (let l of mystr) { + if (l == 'a' && bflag == 1) { + ver = 0; + break; + } else { + if (l == 'b') { + bflag = 1; + } + } + } + } + if (ver == 1) { + console.log("Output: true"); + } else { + console.log("Output: false"); + } +} diff --git a/challenge-273/zapwai/perl/ch-1.pl b/challenge-273/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..fb63c409c8 --- /dev/null +++ b/challenge-273/zapwai/perl/ch-1.pl @@ -0,0 +1,22 @@ +use v5.38; +my $str = "perl"; my $char = "e"; +proc($str, $char); +$str = "java"; $char = "a"; +proc($str, $char); +$str = "python"; $char = "m"; +proc($str, $char); +$str = "ada"; $char = "a"; +proc($str, $char); +$str = "ballerina"; $char = "l"; +proc($str, $char); +$str = "analitik"; $char = "k"; +proc($str, $char); + +sub proc($str, $char) { + say "Input: \$str = $str, \$char = $char"; + my $cnt = grep { $_ eq $char } split "", $str; + my $i = int 100*($cnt / length $str); + my $r = 100*($cnt / length $str) - $i; + $i++ if ($r >= .5); + say "Output: $i"; +} diff --git a/challenge-273/zapwai/perl/ch-2.pl b/challenge-273/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..59c0b63e44 --- /dev/null +++ b/challenge-273/zapwai/perl/ch-2.pl @@ -0,0 +1,29 @@ +use v5.38; +my $str = "aabb"; +proc($str); +$str = "abab"; +proc($str); +$str = "aaa"; +proc($str); +$str = "bbb"; +proc($str); + +sub proc($str) { + say "Input: \$str = $str"; + my $ver = 0; + if ($str =~ /b/) { + $ver = 1; + my $bflag = 0; + for my $l (split "", $str) { + if ($l eq "a" and $bflag) { + $ver = 0; + last; + } else { + if ($l eq "b") { + $bflag = 1; + } + } + } + } + say "Output: ", $ver ? "true" : "false"; +} diff --git a/challenge-273/zapwai/python/ch-1.py b/challenge-273/zapwai/python/ch-1.py new file mode 100644 index 0000000000..0cfe3c56b5 --- /dev/null +++ b/challenge-273/zapwai/python/ch-1.py @@ -0,0 +1,26 @@ +def proc(mystr, mychar): + print("Input: mystr =",mystr, "mychar =", mychar); + cnt = 0 + for l in list(mystr): + if l == mychar: + cnt += 1 + i = 100.0 * (cnt / len(mystr)); + I = int(i) + r = i - I + if r >= .5: + I += 1; + print("Output:", I); + +mystr = "perl"; mychar = "e" +proc(mystr, mychar) +mystr = "java"; mychar = "a" +proc(mystr, mychar) +mystr = "python"; mychar = "m" +proc(mystr, mychar) +mystr = "ada"; mychar = "a" +proc(mystr, mychar) +mystr = "ballerina"; mychar = "l" +proc(mystr, mychar) +mystr = "analitik"; mychar = "k" +proc(mystr, mychar) + diff --git a/challenge-273/zapwai/python/ch-2.py b/challenge-273/zapwai/python/ch-2.py new file mode 100644 index 0000000000..f749308fd9 --- /dev/null +++ b/challenge-273/zapwai/python/ch-2.py @@ -0,0 +1,29 @@ +def proc(mystr): + print("Input: mystr =", mystr) + ver = False + for l in list(mystr): + if l == 'b': + ver = True + if ver: + bflag = False + for l in list(mystr): + if (l == 'a' and bflag): + ver = False + break + else: + if (l == "b"): + bflag = True + if ver: + print("Output: true") + else: + print("Output: false") + +mystr = "aabb" +proc(mystr) +mystr = "abab" +proc(mystr) +mystr = "aaa" +proc(mystr) +mystr = "bbb" +proc(mystr) + diff --git a/challenge-273/zapwai/rust/ch-1.rs b/challenge-273/zapwai/rust/ch-1.rs new file mode 100644 index 0000000000..c1eb8fa555 --- /dev/null +++ b/challenge-273/zapwai/rust/ch-1.rs @@ -0,0 +1,26 @@ +fn main() { + let mut mystr = "perl"; let mut mychar = 'e'; + proc(mystr, mychar); + mystr = "java"; mychar = 'a'; + proc(mystr, mychar); + mystr = "python"; mychar = 'm'; + proc(mystr, mychar); + mystr = "ada"; mychar = 'a'; + proc(mystr, mychar); + mystr = "ballerina"; mychar = 'l'; + proc(mystr, mychar); + mystr = "analitik"; mychar = 'k'; + proc(mystr, mychar); +} + +fn proc(mystr : &str, mychar : char) { + println!("Input: mystr = {mystr}, mychar = {mychar}"); + let mut cnt = 0; + for l in mystr.chars() { + if l == mychar { + cnt += 1; + } + } + let i :f32 = 100.0 * cnt as f32 / mystr.len() as f32; + println!("Output: {}", i.round()); +} diff --git a/challenge-273/zapwai/rust/ch-2.rs b/challenge-273/zapwai/rust/ch-2.rs new file mode 100644 index 0000000000..750d65dd9c --- /dev/null +++ b/challenge-273/zapwai/rust/ch-2.rs @@ -0,0 +1,38 @@ +fn main() { + let mut mystr = "aabb"; + proc(mystr); + mystr = "abab"; + proc(mystr); + mystr = "aaa"; + proc(mystr); + mystr = "bbb"; + proc(mystr); +} + +fn proc(mystr : &str) { + println!("Input: mystr = {mystr}"); + let mut ver : bool = false; + for l in mystr.chars() { + if l == 'b' { + ver = true; + } + } + let mut bflag : bool = false; + if ver { + for l in mystr.chars() { + if l == 'a' && bflag { + ver = false; + break; + } else { + if l == 'b' { + bflag = true; + } + } + } + } + if ver { + println!("Output: true"); + } else { + println!("Output: false"); + } +} -- cgit From 33685946d60ac25cbbe9d221413d1240f124145f Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 10 Jun 2024 16:52:00 +0200 Subject: PWC 273 Task 1 Raku done Task 2 Raku done Task 1 PL/Perl done Task 2 PL/Perl done Task 1 PL/PgSQL done Task 2 PL/PgSql done Task 1 PL/Java done Task 2 PL/Java done Task 1 Python done Task 2 Python done --- challenge-273/luca-ferrari/blog-1.txt | 1 + challenge-273/luca-ferrari/blog-10.txt | 1 + challenge-273/luca-ferrari/blog-2.txt | 1 + challenge-273/luca-ferrari/blog-3.txt | 1 + challenge-273/luca-ferrari/blog-4.txt | 1 + challenge-273/luca-ferrari/blog-5.txt | 1 + challenge-273/luca-ferrari/blog-6.txt | 1 + challenge-273/luca-ferrari/blog-7.txt | 1 + challenge-273/luca-ferrari/blog-8.txt | 1 + challenge-273/luca-ferrari/blog-9.txt | 1 + challenge-273/luca-ferrari/pljava/pom.xml | 6 +- .../luca-ferrari/pljava/src/main/java/Task1.java | 68 ++++++++++++++++++++++ .../luca-ferrari/pljava/src/main/java/Task2.java | 60 +++++++++++++++++++ challenge-273/luca-ferrari/plperl/ch-1.plperl | 23 ++++++++ challenge-273/luca-ferrari/plperl/ch-2.plperl | 20 +++++++ challenge-273/luca-ferrari/plpgsql/ch-1.sql | 22 +++++++ challenge-273/luca-ferrari/plpgsql/ch-2.sql | 21 +++++++ challenge-273/luca-ferrari/python/ch-1.py | 23 ++++++++ challenge-273/luca-ferrari/python/ch-2.py | 26 +++++++++ challenge-273/luca-ferrari/raku/ch-1.raku | 12 ++++ challenge-273/luca-ferrari/raku/ch-2.raku | 14 +++++ 21 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 challenge-273/luca-ferrari/blog-1.txt create mode 100644 challenge-273/luca-ferrari/blog-10.txt create mode 100644 challenge-273/luca-ferrari/blog-2.txt create mode 100644 challenge-273/luca-ferrari/blog-3.txt create mode 100644 challenge-273/luca-ferrari/blog-4.txt create mode 100644 challenge-273/luca-ferrari/blog-5.txt create mode 100644 challenge-273/luca-ferrari/blog-6.txt create mode 100644 challenge-273/luca-ferrari/blog-7.txt create mode 100644 challenge-273/luca-ferrari/blog-8.txt create mode 100644 challenge-273/luca-ferrari/blog-9.txt create mode 100644 challenge-273/luca-ferrari/pljava/src/main/java/Task1.java create mode 100644 challenge-273/luca-ferrari/pljava/src/main/java/Task2.java create mode 100644 challenge-273/luca-ferrari/plperl/ch-1.plperl create mode 100644 challenge-273/luca-ferrari/plperl/ch-2.plperl create mode 100644 challenge-273/luca-ferrari/plpgsql/ch-1.sql create mode 100644 challenge-273/luca-ferrari/plpgsql/ch-2.sql create mode 100644 challenge-273/luca-ferrari/python/ch-1.py create mode 100644 challenge-273/luca-ferrari/python/ch-2.py create mode 100644 challenge-273/luca-ferrari/raku/ch-1.raku create mode 100644 challenge-273/luca-ferrari/raku/ch-2.raku diff --git a/challenge-273/luca-ferrari/blog-1.txt b/challenge-273/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..6c5f158157 --- /dev/null +++ b/challenge-273/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task1 diff --git a/challenge-273/luca-ferrari/blog-10.txt b/challenge-273/luca-ferrari/blog-10.txt new file mode 100644 index 0000000000..8ea138d487 --- /dev/null +++ b/challenge-273/luca-ferrari/blog-10.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/[= date -%]/PerlWeeklyChallenge273.html#task2pljava diff --git a/challenge-273/luca-ferrari/blog-2.txt b/challenge-273/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..40635c9385 --- /dev/null +++ b/challenge-273/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task2 diff --git a/challenge-273/luca-ferrari/blog-3.txt b/challenge-273/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..6c9a9638bb --- /dev/null +++ b/challenge-273/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task1plperl diff --git a/challenge-273/luca-ferrari/blog-4.txt b/challenge-273/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..826cabd8d7 --- /dev/null +++ b/challenge-273/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task2plperl diff --git a/challenge-273/luca-ferrari/blog-5.txt b/challenge-273/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..b0402584ef --- /dev/null +++ b/challenge-273/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task1plpgsql diff --git a/challenge-273/luca-ferrari/blog-6.txt b/challenge-273/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..a97cf8b8b6 --- /dev/null +++ b/challenge-273/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task2plpgsql diff --git a/challenge-273/luca-ferrari/blog-7.txt b/challenge-273/luca-ferrari/blog-7.txt new file mode 100644 index 0000000000..3638fe271a --- /dev/null +++ b/challenge-273/luca-ferrari/blog-7.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task1python diff --git a/challenge-273/luca-ferrari/blog-8.txt b/challenge-273/luca-ferrari/blog-8.txt new file mode 100644 index 0000000000..2c9d30467c --- /dev/null +++ b/challenge-273/luca-ferrari/blog-8.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task2python diff --git a/challenge-273/luca-ferrari/blog-9.txt b/challenge-273/luca-ferrari/blog-9.txt new file mode 100644 index 0000000000..8a9060e6a2 --- /dev/null +++ b/challenge-273/luca-ferrari/blog-9.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/10/PerlWeeklyChallenge273.html#task1pljava diff --git a/challenge-273/luca-ferrari/pljava/pom.xml b/challenge-273/luca-ferrari/pljava/pom.xml index 88583e06f9..ade9b2efb4 100644 --- a/challenge-273/luca-ferrari/pljava/pom.xml +++ b/challenge-273/luca-ferrari/pljava/pom.xml @@ -7,14 +7,14 @@ PWC - PWC272 + PWC273 1 - Perl Weekly Challenge 272 with package PWC272 - Implementation of the tasks in PL/Java for PWC 272 + Perl Weekly Challenge 273 with package PWC273 + Implementation of the tasks in PL/Java for PWC 273 US-ASCII diff --git a/challenge-273/luca-ferrari/pljava/src/main/java/Task1.java b/challenge-273/luca-ferrari/pljava/src/main/java/Task1.java new file mode 100644 index 0000000000..be0d702144 --- /dev/null +++ b/challenge-273/luca-ferrari/pljava/src/main/java/Task1.java @@ -0,0 +1,68 @@ + + + +package PWC273; + +/** + * PL/Java implementation for PWC 273 + * Task 1 + * See + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ scp target/PWC273-1.jar luca@rachel:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC273-1.jar', 'PWC273', true ); + select sqlj.set_classpath( 'public', 'PWC273' ); + + select pwc273.task2_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC273-1.jar', 'PWC273', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.util.stream.*; +import java.sql.SQLException; +import java.util.logging.*; +import java.sql.ResultSet; +import java.sql.Date; + +public class Task1 { + + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( schema = "pwc273", + onNullInput = RETURNS_NULL, + effects = IMMUTABLE ) + public static final int task1_pljava( String s, String c ) throws SQLException { + logger.log( Level.INFO, "Entering pwc273.task1_pljava" ); + + if ( c.length() != 1 ) + throw new SQLException( "Need a single char!" ); + + + final int[] values = new int[]{ 0, 0 }; + values[ 1 ] = s.length(); + Stream.of( s.split( "" ) ) + .forEach( cc -> { + if ( cc.equals( c ) ) + values[ 0 ]++; + } ); + + return (int) Math.round( (double) values[ 0 ] / values[ 1 ] * 100 ); + } +} diff --git a/challenge-273/luca-ferrari/pljava/src/main/java/Task2.java b/challenge-273/luca-ferrari/pljava/src/main/java/Task2.java new file mode 100644 index 0000000000..91e2f8078b --- /dev/null +++ b/challenge-273/luca-ferrari/pljava/src/main/java/Task2.java @@ -0,0 +1,60 @@ + + + +package PWC273; + +/** + * PL/Java implementation for PWC 273 + * Task 2 + * See + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ scp target/PWC273-1.jar luca@rachel:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC273-1.jar', 'PWC273', true ); + select sqlj.set_classpath( 'public', 'PWC273' ); + + select pwc273.task2_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC273-1.jar', 'PWC273', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.util.regex.*; +import java.util.stream.*; +import java.sql.SQLException; +import java.util.logging.*; +import java.sql.ResultSet; +import java.sql.Date; + +public class Task2 { + + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( schema = "pwc273", + onNullInput = RETURNS_NULL, + effects = IMMUTABLE ) + public static final boolean task2_pljava( String s ) throws SQLException { + logger.log( Level.INFO, "Entering pwc273.task2_pljava" ); + + Pattern p1 = Pattern.compile( "b" ); + Pattern p2 = Pattern.compile( "b.*a" ); + + return p1.matcher( s ).find() && ! p2.matcher( s ).find(); + } +} diff --git a/challenge-273/luca-ferrari/plperl/ch-1.plperl b/challenge-273/luca-ferrari/plperl/ch-1.plperl new file mode 100644 index 0000000000..d19899ae38 --- /dev/null +++ b/challenge-273/luca-ferrari/plperl/ch-1.plperl @@ -0,0 +1,23 @@ +-- +-- Perl Weekly Challenge 273 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc273; + +CREATE OR REPLACE FUNCTION +pwc273.task1_plperl( text, text ) +RETURNS int +AS $CODE$ + use POSIX; + + my ( $string, $char ) = @_; + + die "Pass a single char!" if ( length( $char ) != 1 ); + + return 0 if $string !~ / $char /x; + return POSIX::ceil( ( scalar( grep { $_ eq $char } split //, $string ) / scalar( split //, $string ) * 100 ) ); + +$CODE$ +LANGUAGE plperlu; diff --git a/challenge-273/luca-ferrari/plperl/ch-2.plperl b/challenge-273/luca-ferrari/plperl/ch-2.plperl new file mode 100644 index 0000000000..ee82054085 --- /dev/null +++ b/challenge-273/luca-ferrari/plperl/ch-2.plperl @@ -0,0 +1,20 @@ +-- +-- Perl Weekly Challenge 273 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc273; + +CREATE OR REPLACE FUNCTION +pwc273.task2_plperl( text ) +RETURNS boolean +AS $CODE$ + + my ( $string ) = @_; + + return 1 if ( $string =~ / b /x and $string !~ / b .* a /x ); + return 0; + +$CODE$ +LANGUAGE plperl; diff --git a/challenge-273/luca-ferrari/plpgsql/ch-1.sql b/challenge-273/luca-ferrari/plpgsql/ch-1.sql new file mode 100644 index 0000000000..2cbb56b6d2 --- /dev/null +++ b/challenge-273/luca-ferrari/plpgsql/ch-1.sql @@ -0,0 +1,22 @@ +-- +-- Perl Weekly Challenge 273 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc273; + +CREATE OR REPLACE FUNCTION +pwc273.task1_plpgsql( s text, c char ) +RETURNS int +AS $CODE$ + + WITH letters AS ( SELECT v FROM regexp_split_to_table( s, '' ) v ) + , matches AS ( SELECT v FROM letters v WHERE v = c ) + , c_l AS ( SELECT count(*) as x FROM letters ) + , c_m AS ( SELECT count(*) as x FROM matches ) + SELECT m.x::numeric / l.x::numeric * 100 + FROM c_l l , c_m m; + +$CODE$ +LANGUAGE sql; diff --git a/challenge-273/luca-ferrari/plpgsql/ch-2.sql b/challenge-273/luca-ferrari/plpgsql/ch-2.sql new file mode 100644 index 0000000000..3246c04f0e --- /dev/null +++ b/challenge-273/luca-ferrari/plpgsql/ch-2.sql @@ -0,0 +1,21 @@ +-- +-- Perl Weekly Challenge 273 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc273; + +CREATE OR REPLACE FUNCTION +pwc273.task2_plpgsql( s text ) +RETURNS boolean +AS $CODE$ + + WITH has_b AS ( SELECT v FROM regexp_count( s, 'b' ) v ) + , has_b_without_trailing_a AS ( SELECT v FROM regexp_count( s, 'b.*a' ) v ) + SELECT CASE b.v WHEN NULL THEN false ELSE true END + FROM has_b b, has_b_without_trailing_a a + WHERE a.v = 0 AND b.v >= 1; + +$CODE$ +LANGUAGE sql; diff --git a/challenge-273/luca-ferrari/python/ch-1.py b/challenge-273/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..00e24b5173 --- /dev/null +++ b/challenge-273/luca-ferrari/python/ch-1.py @@ -0,0 +1,23 @@ +#!python + +# +# Perl Weekly Challenge 273 +# Task 1 +# +# See +# + +import sys + +# task implementation +# the return value will be printed +def task_1( args ): + s = args[ 0 ] + c = args[ 1 ] + + return round( len( list( filter( lambda x: x == c, s ) ) ) / len( s ) * 100 ) + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) diff --git a/challenge-273/luca-ferrari/python/ch-2.py b/challenge-273/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..98cb99df7a --- /dev/null +++ b/challenge-273/luca-ferrari/python/ch-2.py @@ -0,0 +1,26 @@ +#!python + +# +# Perl Weekly Challenge 273 +# Task 2 +# +# See +# + +import sys +import re + +# task implementation +# the return value will be printed +def task_2( args ): + s = args[ 0 ] + p1 = re.compile( 'b' ) + p2 = re.compile( 'b.*a' ) + return p1.search( s ) and not p2.search( s ) + + + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_2( sys.argv[ 1: ] ) ) diff --git a/challenge-273/luca-ferrari/raku/ch-1.raku b/challenge-273/luca-ferrari/raku/ch-1.raku new file mode 100644 index 0000000000..95681c6a98 --- /dev/null +++ b/challenge-273/luca-ferrari/raku/ch-1.raku @@ -0,0 +1,12 @@ +#!raku + +# +# Perl Weekly Challenge 273 +# Task 1 +# +# See +# + +sub MAIN( Str $string, Str $char where { $char.chars == 1 } ) { + ( $string.comb.grep( * ~~ $char ).elems / $string.comb.elems * 100 ).Rat.round.say; +} diff --git a/challenge-273/luca-ferrari/raku/ch-2.raku b/challenge-273/luca-ferrari/raku/ch-2.raku new file mode 100644 index 0000000000..679bc0b643 --- /dev/null +++ b/challenge-273/luca-ferrari/raku/ch-2.raku @@ -0,0 +1,14 @@ +#!raku + +# +# Perl Weekly Challenge 273 +# Task 2 +# +# See +# + +sub MAIN( Str $string where { $string.chars > 0 } ) { + 'True'.say and exit if ( $string ~~ / b / && $string !~~ / b .* a / ); + 'False'.say; + +} -- cgit From c1f56716a6b7db5c435b20a154e903535f1d710d Mon Sep 17 00:00:00 2001 From: Thomas Köhler Date: Mon, 10 Jun 2024 20:25:38 +0200 Subject: Add solution 273. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Köhler --- challenge-273/jeanluc2020/blog-1.txt | 1 + challenge-273/jeanluc2020/blog-2.txt | 1 + challenge-273/jeanluc2020/perl/ch-1.pl | 74 ++++++++++++++++++++++++++++++++++ challenge-273/jeanluc2020/perl/ch-2.pl | 68 +++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 challenge-273/jeanluc2020/blog-1.txt create mode 100644 challenge-273/jeanluc2020/blog-2.txt create mode 100755 challenge-273/jeanluc2020/perl/ch-1.pl create mode 100755 challenge-273/jeanluc2020/perl/ch-2.pl diff --git a/challenge-273/jeanluc2020/blog-1.txt b/challenge-273/jeanluc2020/blog-1.txt new file mode 100644 index 0000000000..7ee7b3dc94 --- /dev/null +++ b/challenge-273/jeanluc2020/blog-1.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-273-1.html diff --git a/challenge-273/jeanluc2020/blog-2.txt b/challenge-273/jeanluc2020/blog-2.txt new file mode 100644 index 0000000000..9bcbd79a15 --- /dev/null +++ b/challenge-273/jeanluc2020/blog-2.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-273-2.html diff --git a/challenge-273/jeanluc2020/perl/ch-1.pl b/challenge-273/jeanluc2020/perl/ch-1.pl new file mode 100755 index 0000000000..cec9e25e69 --- /dev/null +++ b/challenge-273/jeanluc2020/perl/ch-1.pl @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-273/#TASK1 +# +# Task 1: Percentage of Character +# =============================== +# +# You are given a string, $str and a character $char. +# +# Write a script to return the percentage, nearest whole, of given character in +# the given string. +# +## Example 1 +## +## Input: $str = "perl", $char = "e" +## Output: 25 +# +## Example 2 +## +## Input: $str = "java", $char = "a" +## Output: 50 +# +## Example 3 +## +## Input: $str = "python", $char = "m" +## Output: 0 +# +## Example 4 +## +## Input: $str = "ada", $char = "a" +## Output: 67 +# +## Example 5 +## +## Input: $str = "ballerina", $char = "l" +## Output: 22 +# +## Example 6 +## +## Input: $str = "analitik", $char = "k" +## Output: 13 +# +############################################################ +## +## discussion +## +############################################################ +# +# We split $str into its characters and count both the overall +# sum and the sum of the characters that match $char. We calculate +# the percentage, add 0.5 and convert to an integer. This way, we +# obtain the nearest whole percentage. + +use strict; +use warnings; + +percentage_of_char("perl", "e"); +percentage_of_char("java", "a"); +percentage_of_char("python", "m"); +percentage_of_char("ada", "a"); +percentage_of_char("ballerina", "l"); +percentage_of_char("analitik", "k"); + +sub percentage_of_char { + my ($str, $char) = @_; + print "Input: '$str', '$char'\n"; + my $overall_char_count = 0; + my $this_char_count = 0; + foreach my $c (split //, $str) { + $overall_char_count++; + $this_char_count++ if $c eq $char; + } + my $percentage = int(100*$this_char_count/$overall_char_count + 0.5); + print "Output: $percentage\n"; +} diff --git a/challenge-273/jeanluc2020/perl/ch-2.pl b/challenge-273/jeanluc2020/perl/ch-2.pl new file mode 100755 index 0000000000..fcf2ad08c2 --- /dev/null +++ b/challenge-273/jeanluc2020/perl/ch-2.pl @@ -0,0 +1,68 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-273/#TASK2 +# +# Task 2: B After A +# ================= +# +# You are given a string, $str. +# +# Write a script to return true if there is at least one b, and no a appears +# after the first b. +# +## Example 1 +## +## Input: $str = "aabb" +## Output: true +# +## Example 2 +## +## Input: $str = "abab" +## Output: false +# +## Example 3 +## +## Input: $str = "aaa" +## Output: false +# +## Example 4 +## +## Input: $str = "bbb" +## Output: true +# +############################################################ +## +## discussion +## +############################################################ +# +# We walk the string character for character. If we find a "b" +# we remember this fact. If we encounter an "a" and have already +# seen a "b", we return false. If we're at the end of the string +# our output depends on whether or not we have seen a "b": we +# didn't bail out for seeing an "a" after a "b", so if we didn't +# see any "b" at all, we return false, otherwise true. + +use strict; +use warnings; + +b_after_a("aabb"); +b_after_a("abab"); +b_after_a("aaa"); +b_after_a("bbb"); + +sub b_after_a { + my $str = shift; + print "Input: '$str'\n"; + my $b_seen = 0; + foreach my $char (split //, $str) { + $b_seen = 1 if $char eq "b"; + if($b_seen) { + return print "Output: false\n" if $char eq "a"; + } + } + if($b_seen) { + print "Output: true\n"; + } else { + print "Output: false\n"; + } +} -- cgit From 2bdd0742da7c7e81a343f506f0f6ba71225fc1fa Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Mon, 10 Jun 2024 17:54:42 -0400 Subject: DAJ 273 --- challenge-273/dave-jacoby/perl/ch-1.pl | 36 ++++++++++++++++++++++++++++++++++ challenge-273/dave-jacoby/perl/ch-2.pl | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 challenge-273/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-273/dave-jacoby/perl/ch-2.pl diff --git a/challenge-273/dave-jacoby/perl/ch-1.pl b/challenge-273/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..eb1de94c52 --- /dev/null +++ b/challenge-273/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,36 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ bitwise fc postderef say signatures state }; + +use List::Util qw{max}; + +my @examples = ( + + { str => "perl", char => "e" }, + { str => "java", char => "a" }, + { str => "python", char => "m" }, + { str => "ada", char => "a" }, + { str => "ballerina", char => "l" }, + { str => "analitik", char => "k" }, +); +for my $example (@examples) { + my $char = $example->{char}; + my $str = $example->{str}; + my @str = split //, $str; + my $count = scalar grep { $_ eq $char } @str; + my $total = scalar @str; + my $output = round( 100 * $count / $total ); + say <<"END"; +Input: \$str = "$str", \$char = "$char" +Output: "$output" +END +} + +sub round ($number) { + my $int = int $number; + return $number if $number == $int; + my $r = $number - $int; + return $r < 0.5 ? $int : $int + 1; +} diff --git a/challenge-273/dave-jacoby/perl/ch-2.pl b/challenge-273/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..8d4420e62f --- /dev/null +++ b/challenge-273/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ fc say postderef signatures state }; + +use List::Util qw{ sum0 }; + +my @examples = ( + + "aabb", + "abab", + "aaa", + "bbb", +); + +for my $example (@examples) { + my $output = baftera($example); + + say <<"END"; +Input: \$str = "$example" +Output: $output +END +} + +sub baftera ($str) { + return 'false' unless $str =~ /b/mix; + my $has_b = 0; + for my $i ( 0 .. length $str ) { + my $char = substr $str, $i, 1; + $has_b = 1 if $char eq 'b'; + return 'false' if $has_b && $char eq 'a'; + } + return 'true'; +} -- cgit From 0427319d906e68ec8680c0973a1b82d49a439524 Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Mon, 10 Jun 2024 18:27:41 -0400 Subject: blogged as well --- challenge-273/dave-jacoby/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-273/dave-jacoby/blog.txt diff --git a/challenge-273/dave-jacoby/blog.txt b/challenge-273/dave-jacoby/blog.txt new file mode 100644 index 0000000000..0a773a0b80 --- /dev/null +++ b/challenge-273/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby-lpwk.onrender.com/2024/06/10/round-here-weekly-challenge-273.html -- cgit From 311ed781407135d382d33d69e1e0671078ade91d Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 11 Jun 2024 00:56:38 +0000 Subject: Challenge 273 Solutions (Raku) --- challenge-273/mark-anderson/raku/ch-2.raku | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/challenge-273/mark-anderson/raku/ch-2.raku b/challenge-273/mark-anderson/raku/ch-2.raku index 6abd68338d..65221a6570 100644 --- a/challenge-273/mark-anderson/raku/ch-2.raku +++ b/challenge-273/mark-anderson/raku/ch-2.raku @@ -28,6 +28,10 @@ nok b-after-a-indices("aaabxayzbcde"); nok b-after-a-indices("aaabxyzbcade"); nok b-after-a-indices("aaabxyzcde"); +# Note: I may have misunderstood the problem. I thought it was to check +# for a 'b' and then a 'b' following the first 'b' and no 'a' following +# the first 'b' 🤷 + sub b-after-a($str) { $str ~~ / ^ <-[b]>* b <-[a]>* b <-[a]>* $ / @@ -36,8 +40,8 @@ sub b-after-a($str) sub b-after-a-pos($str) { my $b = $str ~~ m:1st / b / || return False; - my $a-after-b = $str ~~ m:1st:c($b.pos)/ a /; - my $b-after-b = $str ~~ m:1st:c($b.pos)/ b /; + my $a-after-b = $str ~~ m:c($b.pos):1st/ a /; + my $b-after-b = $str ~~ m:c($b.pos):1st/ b /; $b-after-b and not $a-after-b } @@ -45,5 +49,5 @@ sub b-after-a-indices($str) { my @a = $str.indices('a'); my @b = $str.indices('b'); - @b >= 2 && @b.head > all(@a) + @b > 1 and all(@a) < @b.head } -- cgit From 75aa0f2a5cc9e834db897e64e97ab7a0fb2d4943 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 11 Jun 2024 01:18:40 +0000 Subject: Challenge 273 Solutions (Raku) --- challenge-273/mark-anderson/raku/ch-2.raku | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/challenge-273/mark-anderson/raku/ch-2.raku b/challenge-273/mark-anderson/raku/ch-2.raku index 65221a6570..d769f0bb69 100644 --- a/challenge-273/mark-anderson/raku/ch-2.raku +++ b/challenge-273/mark-anderson/raku/ch-2.raku @@ -29,8 +29,9 @@ nok b-after-a-indices("aaabxyzbcade"); nok b-after-a-indices("aaabxyzcde"); # Note: I may have misunderstood the problem. I thought it was to check -# for a 'b' and then a 'b' following the first 'b' and no 'a' following -# the first 'b' 🤷 +# for a 'b' and then a 'b' after the first 'b' and no 'a' after the first +# 'b' but it looks like others have checked for a 'b' and no 'a' after +# that first 'b' 🤷 sub b-after-a($str) { -- cgit From 05d2c21673b4d4ff46129c10cf1a91259a294ac2 Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Mon, 10 Jun 2024 21:44:16 -0700 Subject: Robbie Hatley's solutions, in Perl, for The Weekly Challenge #273. --- challenge-273/robbie-hatley/blog.txt | 1 + challenge-273/robbie-hatley/perl/ch-1.pl | 118 +++++++++++++++++++++++++++++++ challenge-273/robbie-hatley/perl/ch-2.pl | 97 +++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 challenge-273/robbie-hatley/blog.txt create mode 100755 challenge-273/robbie-hatley/perl/ch-1.pl create mode 100755 challenge-273/robbie-hatley/perl/ch-2.pl diff --git a/challenge-273/robbie-hatley/blog.txt b/challenge-273/robbie-hatley/blog.txt new file mode 100644 index 0000000000..57339653ed --- /dev/null +++ b/challenge-273/robbie-hatley/blog.txt @@ -0,0 +1 @@ +https://hatley-software.blogspot.com/2024/06/robbie-hatleys-solutions-to-weekly_10.html \ No newline at end of file diff --git a/challenge-273/robbie-hatley/perl/ch-1.pl b/challenge-273/robbie-hatley/perl/ch-1.pl new file mode 100755 index 0000000000..03c97c45fe --- /dev/null +++ b/challenge-273/robbie-hatley/perl/ch-1.pl @@ -0,0 +1,118 @@ +#!/usr/bin/env -S perl -CSDA + +=pod + +-------------------------------------------------------------------------------------------------------------- +TITLE AND ATTRIBUTION: +Solutions in Perl for The Weekly Challenge 273-1, +written by Robbie Hatley on Mon Jun 10, 2024. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM DESCRIPTION: +Task 273-1: Percentage of Character +Submitted by: Mohammad Sajid Anwar +You are given a string, $str and a character $chr. Write a +script to return the nearest integer percentage of the +characters in $str which are $chr. + +Example 1: +Input: $str = "perl", $chr = "e" +Output: 25 + +Example 2: +Input: $str = "java", $chr = "a" +Output: 50 + +Example 3: +Input: $str = "python", $chr = "m" +Output: 0 + +Example 4: +Input: $str = "ada", $chr = "a" +Output: 67 + +Example 5: +Input: $str = "ballerina", $chr = "l" +Output: 22 + +Example 6: +Input: $str = "analitik", $chr = "k" +Output: 13 + +-------------------------------------------------------------------------------------------------------------- +PROBLEM NOTES: +This is just a matter of counting instances of $chr in $str, dividing by length($str), multiplying by 100, +and rounding to nearest integer. The m// operator and the "lround" function from POSIX are useful here: + + sub pct_chr_in_str ($str, $chr) { + my $length = length($str); + my @matches = $str =~ m/$chr/g; + lround(100*(scalar(@matches)/$length)); + } + +-------------------------------------------------------------------------------------------------------------- +IO NOTES: +Input is via either built-in variables or via @ARGV. If using @ARGV, provide one argument which must be a +single-quoted array of arrays of two double-quoted strings, in proper Perl syntax. The second element of each +inner array will be construed as a character to be searched-for in the first element. Eg: +./ch-1.pl '(["aardvark", "a"], ["茶と茶と茶", "茶"])' + +Output is to STDOUT and will be each input followed by the corresponding output. + +=cut + +# ------------------------------------------------------------------------------------------------------------ +# PRAGMAS, MODULES, AND SUBS: + + use v5.38; + use utf8; + use POSIX 'lround'; + + # What is the percentage, to the nearest integer, + # of a given character in a given string? + sub pct_chr_in_str ($str, $chr) { + my $length = length($str); + my @matches = $str =~ m/$chr/g; + lround(100*(scalar(@matches)/$length)); + } + +# ------------------------------------------------------------------------------------------------------------ +# INPUTS: +my @arrays = @ARGV ? eval($ARGV[0]) : +( + # Example 1 input: + ["perl", "e"], + # Expected output: 25 + + # Example 2: + ["java", "a"], + # Expected output: 50 + + # Example 3: + ["python", "m"], + # Expected output: 0 + + # Example 4: + ["ada", "a"], + # Expected output: 67 + + # Example 5: + ["ballerina", "l"], + # Expected output: 22 + + # Example 6: + ["analitik", "k"], + # Expected output: 13 +); + +# ------------------------------------------------------------------------------------------------------------ +# MAIN BODY OF PROGRAM: +say 'Percentange (to nearest integer) of each character in each string:'; +for my $aref (@arrays) { + say ''; + my ($str, $chr) = @$aref; + my $pcis = pct_chr_in_str($str, $chr); + say "String = $str"; + say "Char = $chr"; + say "Pct = $pcis%"; +} diff --git a/challenge-273/robbie-hatley/perl/ch-2.pl b/challenge-273/robbie-hatley/perl/ch-2.pl new file mode 100755 index 0000000000..647f237d95 --- /dev/null +++ b/challenge-273/robbie-hatley/perl/ch-2.pl @@ -0,0 +1,97 @@ +#!/usr/bin/env -S perl -CSDA + +=pod + +-------------------------------------------------------------------------------------------------------------- +TITLE AND ATTRIBUTION: +Solutions in Perl for The Weekly Challenge 273-2, +written by Robbie Hatley on Mon Jun 10, 2024. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM DESCRIPTION: +Task 273-2: B After A +Submitted by: Mohammad Sajid Anwar +You are given a string, $str. Write a script to return true if +there is at least one b, and no a appears after the first b. + +Example 1: +Input: $str = "aabb" +Output: true + +Example 2: +Input: $str = "abab" +Output: false + +Example 3: +Input: $str = "aaa" +Output: false + +Example 4: +Input: $str = "bbb" +Output: true + +-------------------------------------------------------------------------------------------------------------- +PROBLEM NOTES: +A regular expression will solve this. What we're looking for is "b followed by non-a characters to end +of string". The regular expression for that is "^[^b]*b[^a]*$": + + sub b_after_a ($str) { + $str =~ m/^[^b]*b[^a]*$/ + } + +-------------------------------------------------------------------------------------------------------------- +IO NOTES: +Input is via either built-in variables or via @ARGV. If using @ARGV, provide one argument which must be a +single-quoted array of double-quoted strings, in proper Perl syntax, like so: +./ch-2.pl '("Bob shaved?", "I shaved Bob!", "soliloquy", "ambient", "麦藁雪")' + +Output is to STDOUT and will be each input followed by the corresponding output. + +=cut + +# ------------------------------------------------------------------------------------------------------------ +# PRAGMAS, MODULES, AND SUBS: + + use v5.38; + use strict; + use warnings; + use utf8; + use warnings FATAL => 'utf8'; + + # Does a given string contain at least one "b" + # but no "a" after the first "b"? + sub b_after_a ($str) { + $str =~ m/^[^b]*b[^a]*$/ + } + +# ------------------------------------------------------------------------------------------------------------ +# INPUTS: +my @strings = @ARGV ? eval($ARGV[0]) : +( + # Example 1 input: + "aabb", + # Expected output: true + + # Example 2 input: + "abab", + # Expected output: false + + # Example 3 input: + "aaa", + # Expected output: false + + # Example 4 input: + "bbb", + # Expected output: true +); + +# ------------------------------------------------------------------------------------------------------------ +# MAIN BODY OF PROGRAM: +say 'Does each string contain at least one "b" with no "a" after first "b"?'; +for my $str (@strings) { + say ''; + say "String = $str"; + my $ab = b_after_a($str); + my $truefalse = $ab ? 'true' : 'false'; + say "Result = $truefalse"; +} -- cgit From 9b0d62f010c7cbfaadbad2358b208acb9af7dd56 Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Mon, 10 Jun 2024 21:50:00 -0700 Subject: Corrected error in 273-2. --- challenge-273/robbie-hatley/perl/ch-2.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-273/robbie-hatley/perl/ch-2.pl b/challenge-273/robbie-hatley/perl/ch-2.pl index 647f237d95..636b4c20c2 100755 --- a/challenge-273/robbie-hatley/perl/ch-2.pl +++ b/challenge-273/robbie-hatley/perl/ch-2.pl @@ -32,8 +32,8 @@ Output: true -------------------------------------------------------------------------------------------------------------- PROBLEM NOTES: -A regular expression will solve this. What we're looking for is "b followed by non-a characters to end -of string". The regular expression for that is "^[^b]*b[^a]*$": +A regular expression will solve this. What we're looking for is "initial b followed by non-a characters +to end of string". The regular expression for that is "^[^b]*b[^a]*$": sub b_after_a ($str) { $str =~ m/^[^b]*b[^a]*$/ -- cgit From 292b6158c007e8600f9fdefc113e52f3a14f21dc Mon Sep 17 00:00:00 2001 From: Michael Manring Date: Tue, 11 Jun 2024 17:45:40 +1000 Subject: pwc273 solution in python --- challenge-273/pokgopun/python/ch-1.py | 66 +++++++++++++++++++++++++++++++++++ challenge-273/pokgopun/python/ch-2.py | 60 +++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 challenge-273/pokgopun/python/ch-1.py create mode 100644 challenge-273/pokgopun/python/ch-2.py diff --git a/challenge-273/pokgopun/python/ch-1.py b/challenge-273/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..a6194a7d01 --- /dev/null +++ b/challenge-273/pokgopun/python/ch-1.py @@ -0,0 +1,66 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-273/ +""" + +Task 1: Percentage of Character + +Submitted by: [52]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a string, $str and a character $char. + + Write a script to return the percentage, nearest whole, of given + character in the given string. + +Example 1 + +Input: $str = "perl", $char = "e" +Output: 25 + +Example 2 + +Input: $str = "java", $char = "a" +Output: 50 + +Example 3 + +Input: $str = "python", $char = "m" +Output: 0 + +Example 4 + +Input: $str = "ada", $char = "a" +Output: 67 + +Example 5 + +Input: $str = "ballerina", $char = "l" +Output: 22 + +Example 6 + +Input: $str = "analitik", $char = "k" +Output: 13 + +Task 2: B After A +""" +### solution by pokgopun@gmail.com + +def poc(string, char): + res = 1000 * string.count(char) / len(string) + return res // 10 if res % 10 < 5 else 1 + res // 10 + +import unittest + +class TestPoc(unittest.TestCase): + def test(self): + for (string, char), otpt in { + ("perl", "e"): 25, + ("java", "a"): 50, + ("python", "m"): 0, + ("ada", "a"): 67, + ("ballerina", "l"): 22, + ("analitik", "k"): 13, + }.items(): + self.assertEqual(poc(string, char), otpt) + +unittest.main() diff --git a/challenge-273/pokgopun/python/ch-2.py b/challenge-273/pokgopun/python/ch-2.py new file mode 100644 index 0000000000..060fe3686e --- /dev/null +++ b/challenge-273/pokgopun/python/ch-2.py @@ -0,0 +1,60 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-273/ +""" + +Task 2: B After A + +Submitted by: [53]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a string, $str. + + Write a script to return true if there is at least one b, and no a + appears after the first b. + +Example 1 + +Input: $str = "aabb" +Output: true + +Example 2 + +Input: $str = "abab" +Output: false + +Example 3 + +Input: $str = "aaa" +Output: false + +Example 4 + +Input: $str = "bbb" +Output: true + __________________________________________________________________ + + Last date to submit the solution 23:59 (UK Time) Sunday 16th June 2024. + __________________________________________________________________ + +SO WHAT DO YOU THINK ? +""" +### solution by pokgopun@gmail.com + +def bAfterA(string): + i = string.find("b") + if i == -1: + return False + return string[i+1:].find("a") == -1 + +import unittest + +class TestBAfterA(unittest.TestCase): + def test(self): + for string, otpt in { + "aabb": True, + "abab": False, + "aaa": False, + "bbb": True, + }.items(): + self.assertEqual(bAfterA(string),otpt) + +unittest.main() -- cgit From 7f4455ab3e39bd208a6a1f6449c2d702f19df091 Mon Sep 17 00:00:00 2001 From: Michael Manring Date: Tue, 11 Jun 2024 18:17:22 +1000 Subject: pwc273 solution in go --- challenge-273/pokgopun/go/ch-1.go | 86 +++++++++++++++++++++++++++++++++++++++ challenge-273/pokgopun/go/ch-2.go | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 challenge-273/pokgopun/go/ch-1.go create mode 100644 challenge-273/pokgopun/go/ch-2.go diff --git a/challenge-273/pokgopun/go/ch-1.go b/challenge-273/pokgopun/go/ch-1.go new file mode 100644 index 0000000000..5e9355844b --- /dev/null +++ b/challenge-273/pokgopun/go/ch-1.go @@ -0,0 +1,86 @@ +//# https://theweeklychallenge.org/blog/perl-weekly-challenge-273/ +/*# + +Task 1: Percentage of Character + +Submitted by: [52]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a string, $str and a character $char. + + Write a script to return the percentage, nearest whole, of given + character in the given string. + +Example 1 + +Input: $str = "perl", $char = "e" +Output: 25 + +Example 2 + +Input: $str = "java", $char = "a" +Output: 50 + +Example 3 + +Input: $str = "python", $char = "m" +Output: 0 + +Example 4 + +Input: $str = "ada", $char = "a" +Output: 67 + +Example 5 + +Input: $str = "ballerina", $char = "l" +Output: 22 + +Example 6 + +Input: $str = "analitik", $char = "k" +Output: 13 + +Task 2: B After A +#*/ +//# solution by pokgopun@gmail.com + +package main + +import ( + "io" + "os" + + "github.com/google/go-cmp/cmp" +) + +func poc(str string, chr rune) int { + res := 0 + for _, v := range str { + if v == chr { + res++ + } + } + res = 1000 * res / len(str) + if res%10 < 5 { + return res / 10 + } + return 1 + res/10 +} + +func main() { + for _, data := range []struct { + str string + chr rune + p int + }{ + {"perl", 'e', 25}, + {"java", 'a', 50}, + {"python", 'm', 0}, + {"ada", 'a', 67}, + {"ballerina", 'l', 22}, + {"analitik", 'k', 13}, + } { + io.WriteString(os.Stdout, cmp.Diff(poc(data.str, data.chr), data.p)) // blank if ok, otherwise show the differences + } +} diff --git a/challenge-273/pokgopun/go/ch-2.go b/challenge-273/pokgopun/go/ch-2.go new file mode 100644 index 0000000000..79ba8a20ff --- /dev/null +++ b/challenge-273/pokgopun/go/ch-2.go @@ -0,0 +1,77 @@ +//# https://theweeklychallenge.org/blog/perl-weekly-challenge-273/ +/*# + +Task 2: B After A + +Submitted by: [53]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a string, $s