diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-14 11:58:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-14 11:58:38 +0100 |
| commit | 8338b98c4c2c29a2d590a1c81f8db0cc6213273b (patch) | |
| tree | fa10d0b87e60ba299919f5679b62cc6fbd9538bb | |
| parent | 6dd3064d49b5ea66646c0d6c8419203f7ea1b869 (diff) | |
| parent | c21c42264b9e202cde1fde5f040f6df023c4ea4b (diff) | |
| download | perlweeklychallenge-club-8338b98c4c2c29a2d590a1c81f8db0cc6213273b.tar.gz perlweeklychallenge-club-8338b98c4c2c29a2d590a1c81f8db0cc6213273b.tar.bz2 perlweeklychallenge-club-8338b98c4c2c29a2d590a1c81f8db0cc6213273b.zip | |
Merge pull request #3894 from lakpatashi/branch-004
Finished challenge-004 with perl
| -rw-r--r-- | challenge-004/lakpatashi/README | 1 | ||||
| -rwxr-xr-x | challenge-004/lakpatashi/perl/ch-1.pl | 10 | ||||
| -rwxr-xr-x | challenge-004/lakpatashi/perl/ch-2.pl | 46 | ||||
| -rw-r--r-- | challenge-004/lakpatashi/perl/inputFile | 10 |
4 files changed, 67 insertions, 0 deletions
diff --git a/challenge-004/lakpatashi/README b/challenge-004/lakpatashi/README new file mode 100644 index 0000000000..bc153bd576 --- /dev/null +++ b/challenge-004/lakpatashi/README @@ -0,0 +1 @@ +Solution by lakpatashi diff --git a/challenge-004/lakpatashi/perl/ch-1.pl b/challenge-004/lakpatashi/perl/ch-1.pl new file mode 100755 index 0000000000..ad95a4a7e9 --- /dev/null +++ b/challenge-004/lakpatashi/perl/ch-1.pl @@ -0,0 +1,10 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# PART 1 +use Math::BigFloat qw(bpi); +my $size = -s $0; +print "Script size:: $size\n"; +print"PI value:: ", bpi($size),"\n" ; diff --git a/challenge-004/lakpatashi/perl/ch-2.pl b/challenge-004/lakpatashi/perl/ch-2.pl new file mode 100755 index 0000000000..e9c43aa4cb --- /dev/null +++ b/challenge-004/lakpatashi/perl/ch-2.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# PART 2 +use Data::Dumper; +my $letterSet = "arefileYOu"; #letter set to be matched to +print "Given letter Set:: $letterSet\n"; +$letterSet = lc $letterSet; +my %letterFreq = buildFreq($letterSet); +#print Dumper(\%letterFreq); + +open(FH,'<','inputFile') or die($!); # file containing list of words +while(my $word = <FH>){ + chomp $word; + $word = lc $word; + my $status = wordMatch(\%letterFreq,$word)? "matched":"not matched"; + print "$word ==> $status\n" +} + +sub wordMatch{ + # arg : <hash> <string> + my %letterFreq = %{$_[0]}; + my $word = $_[1]; + my %wordFreq = buildFreq($word); + #print Dumper(\%wordFreq); + + for my $key (keys %wordFreq){ + unless( exists $letterFreq{$key} and $wordFreq{$key} <= $letterFreq{$key} ){ + return 0; + } + } + return 1; +} + + + +sub buildFreq{ #given a string returns letter freq. hash + my $var = shift; + my %freq; + for my $key (split //, $var){ + $freq{$key}++; + } + return %freq; +} diff --git a/challenge-004/lakpatashi/perl/inputFile b/challenge-004/lakpatashi/perl/inputFile new file mode 100644 index 0000000000..90bdc5cf56 --- /dev/null +++ b/challenge-004/lakpatashi/perl/inputFile @@ -0,0 +1,10 @@ +You +are +given +a +file +containing +a +list +of +words |
