diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-09-16 19:49:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-16 19:49:36 +0100 |
| commit | 2ddf99e60cb67e300da199abc999f6681ee1014d (patch) | |
| tree | d9384df95b32621814ae14de2ddb688abfc88b88 | |
| parent | f9a3334de636ef4884237d827937394304bba4bf (diff) | |
| parent | a71d909d897bd82161ce24b1cbc2bb182602daf7 (diff) | |
| download | perlweeklychallenge-club-2ddf99e60cb67e300da199abc999f6681ee1014d.tar.gz perlweeklychallenge-club-2ddf99e60cb67e300da199abc999f6681ee1014d.tar.bz2 perlweeklychallenge-club-2ddf99e60cb67e300da199abc999f6681ee1014d.zip | |
Merge pull request #639 from duanepowell/pwc26
Commit solutions for perl weekly challenge 026
| -rwxr-xr-x | challenge-026/duane-powell/perl5/ch-1.pl | 32 | ||||
| -rwxr-xr-x | challenge-026/duane-powell/perl5/ch-2.pl | 34 |
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-026/duane-powell/perl5/ch-1.pl b/challenge-026/duane-powell/perl5/ch-1.pl new file mode 100755 index 0000000000..4a088bcb18 --- /dev/null +++ b/challenge-026/duane-powell/perl5/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +use strict; + +# Create a script that accepts two strings, let us call it, “stones” and “jewels”. +# It should print the count of “alphabet” from the string “stones” found in the string “jewels”. For example, +# if your stones is “chancellor” and “jewels” is “chocolate”, then the script should print “8”. +# To keep it simple, only A-Z,a-z characters are acceptable. Also make the comparison case sensitive + +my $stones = shift || "chancellor"; +my $jewels = shift || "chocolate"; + +$stones =~ s/[^a-zA-Z]//g; +$jewels =~ s/[^a-zA-Z]//g; + +my $exp = join('|',split(//,$stones)); +my $count = () = $jewels =~ /$exp/g; +print "$count\n"; + +__END__ + +./ch-1.pl +8 + +./ch-1.pl abcdefgh ijklmnop +0 + +./ch-1.pl abcdefgh abcd +4 + +./ch-1.pl abcdefgh aaaaahhhhh +10 + diff --git a/challenge-026/duane-powell/perl5/ch-2.pl b/challenge-026/duane-powell/perl5/ch-2.pl new file mode 100755 index 0000000000..3121a97d2f --- /dev/null +++ b/challenge-026/duane-powell/perl5/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl +use strict; +use Math::Trig; + +# Create a script that prints mean angles of the given list of angles in degrees. Please read see +# https://en.wikipedia.org/wiki/Mean_of_circular_quantities +# that explains the formula in details with an example + +my @angles = @ARGV; +my $count = scalar(@angles); +my $x; +my $y; +foreach (@angles) { + $x += cos($_ * pi/180); + $y += sin($_ * pi/180); +} + +my $angle_mean = atan2( $y/$count, $x/$count) * 180/pi; +print "The mean of angles ", join(',',@angles), " is $angle_mean\n"; + +__END__ + +/ch-2.pl 10 20 30 +The mean of angles 10,20,30 is 20 + +./ch-2.pl 355 5 15 +The mean of angles 355,5,15 is 5 + +./ch-2.pl 5 10 15 20 25 30 35 +The mean of angles 5,10,15,20,25,30,35 is 20 + +./ch-2.pl 180 270 360 +The mean of angles 180,270,360 is -90 + |
