aboutsummaryrefslogtreecommitdiff
path: root/challenge-004/lars-balker/perl5
diff options
context:
space:
mode:
authorLars Balker <balker@adapt.dk>2019-04-20 11:20:44 +0200
committerLars Balker <balker@adapt.dk>2019-04-20 11:20:44 +0200
commit7e843768ae38f11d6b9336b47982d524b4d18781 (patch)
tree7c1badb233ff365c67f04b7fc4d822c3dbdbb4f9 /challenge-004/lars-balker/perl5
parente8fe17e5d2ef315c34a9408b631ed375602e663d (diff)
downloadperlweeklychallenge-club-7e843768ae38f11d6b9336b47982d524b4d18781.tar.gz
perlweeklychallenge-club-7e843768ae38f11d6b9336b47982d524b4d18781.tar.bz2
perlweeklychallenge-club-7e843768ae38f11d6b9336b47982d524b4d18781.zip
ch4 solution from lars balker
Diffstat (limited to 'challenge-004/lars-balker/perl5')
-rw-r--r--challenge-004/lars-balker/perl5/ch-1.pl4
-rw-r--r--challenge-004/lars-balker/perl5/ch-2.pl28
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-004/lars-balker/perl5/ch-1.pl b/challenge-004/lars-balker/perl5/ch-1.pl
new file mode 100644
index 0000000000..68861a9d91
--- /dev/null
+++ b/challenge-004/lars-balker/perl5/ch-1.pl
@@ -0,0 +1,4 @@
+use v5.20;
+use Math::BigFloat qw/bpi/;
+Math::BigFloat->round_mode('zero'); # don't round
+say bpi(-s $0);
diff --git a/challenge-004/lars-balker/perl5/ch-2.pl b/challenge-004/lars-balker/perl5/ch-2.pl
new file mode 100644
index 0000000000..a6e66866b1
--- /dev/null
+++ b/challenge-004/lars-balker/perl5/ch-2.pl
@@ -0,0 +1,28 @@
+# You are given a file containing a list of words (case insensitive 1
+# word per line) and a list of letters. Print each word from the file
+# than can be made using only letters from the list. You can use each
+# letter only once (though there can be duplicates and you can use
+# each of them once), you don’t have to use all the
+# letters. (Disclaimer: The challenge was proposed by Scimon Proctor)
+use v5.20;
+use strict;
+use warnings;
+
+# accept file as first arg, rest of args are letters, ignoring spacing and case
+
+my $file = shift;
+my %letters;
+$letters{$_}++ for map { split //, lc } @ARGV;
+
+die "$0 <file with list of words> <list of letters>\n" unless $file and %letters;
+
+open my $f, "<", $file or die "no such file: $file\n";
+
+WORD: while (my $word = <$f>) {
+ chomp $word;
+ my %temp = %letters;
+ for my $c (split //, lc $word) {
+ next WORD unless $temp{$c}--;
+ }
+ say $word;
+}