aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-04-15 22:34:00 +0100
committerGitHub <noreply@github.com>2019-04-15 22:34:00 +0100
commita67417479b7d5e807cb6f986192ff85a3ceaaf0f (patch)
tree79cd712e10ae3bb4c0c0e4ccb9753efe7c9e9723
parentc61d4a488e56c01f5e77aae2fb4f7858e535ec1c (diff)
parent29a2314ec091e02a4c3a02cc5d54e7dc7055a440 (diff)
downloadperlweeklychallenge-club-a67417479b7d5e807cb6f986192ff85a3ceaaf0f.tar.gz
perlweeklychallenge-club-a67417479b7d5e807cb6f986192ff85a3ceaaf0f.tar.bz2
perlweeklychallenge-club-a67417479b7d5e807cb6f986192ff85a3ceaaf0f.zip
Merge pull request #59 from jbarrett/jbarrett/challenge4
Week 4
-rw-r--r--challenge-004/john-barrett/perl5/README.md8
-rwxr-xr-xchallenge-004/john-barrett/perl5/ch-1.pl1
-rwxr-xr-xchallenge-004/john-barrett/perl5/ch-2.pl31
3 files changed, 40 insertions, 0 deletions
diff --git a/challenge-004/john-barrett/perl5/README.md b/challenge-004/john-barrett/perl5/README.md
new file mode 100644
index 0000000000..9a98597b12
--- /dev/null
+++ b/challenge-004/john-barrett/perl5/README.md
@@ -0,0 +1,8 @@
+# How I cheated this week...
+
+## Part 1:
+
+You need to run...
+
+`$ perl -MMath::Trig ch-1.pl`
+
diff --git a/challenge-004/john-barrett/perl5/ch-1.pl b/challenge-004/john-barrett/perl5/ch-1.pl
new file mode 100755
index 0000000000..945ae5ca13
--- /dev/null
+++ b/challenge-004/john-barrett/perl5/ch-1.pl
@@ -0,0 +1 @@
+printf'%.0'.((stat$0)[7]-1).'f',pi;
diff --git a/challenge-004/john-barrett/perl5/ch-2.pl b/challenge-004/john-barrett/perl5/ch-2.pl
new file mode 100755
index 0000000000..840eeba777
--- /dev/null
+++ b/challenge-004/john-barrett/perl5/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+print "Usage: $0 letters to find in dict\n" and exit unless @ARGV;
+
+my $fn = '/usr/share/dict/words';
+my $findletters;
+$findletters->{$_}++ for map { map { lc } split '' } @ARGV;
+
+my @found;
+
+open my $fh, '<', $fn;
+
+WORD: while ( my $word = <$fh> ) {
+ chomp $word;
+ my $wordletters;
+ $wordletters->{$_}++ for map { lc } split '', $word;
+ # Change this to 'keys %{ $findletters }' to find
+ # all words containing the specified letters.
+ # This finds all words composed of the specified letters
+ # which I think fulfills "you don’t have to use all the letters"
+ for my $letter ( keys %{ $wordletters } ) {
+ no warnings 'uninitialized';
+ next WORD unless $wordletters->{ $letter } <= $findletters->{ $letter };
+ }
+ push @found, $word;
+}
+
+print "$_\n" for @found;