aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-28 09:58:42 +0000
committerGitHub <noreply@github.com>2019-10-28 09:58:42 +0000
commit30ca236474bf0bf70dc6f725c450eb5c5db85712 (patch)
tree94a28394148e37f5dc2fad1f75492d4cdfd73bd4
parent4ea534b8afcaa524e258936ac5eae51eaa5a2cc9 (diff)
parentb1e98f68aa91f041d7e83034bd9b98a08e6b9ca0 (diff)
downloadperlweeklychallenge-club-30ca236474bf0bf70dc6f725c450eb5c5db85712.tar.gz
perlweeklychallenge-club-30ca236474bf0bf70dc6f725c450eb5c5db85712.tar.bz2
perlweeklychallenge-club-30ca236474bf0bf70dc6f725c450eb5c5db85712.zip
Merge pull request #855 from Scimon/master
Challenge 1 with a few test files
-rw-r--r--challenge-032/simon-proctor/large-test.txt100
-rw-r--r--challenge-032/simon-proctor/medium-test.txt50
-rw-r--r--challenge-032/simon-proctor/perl6/ch-1.p636
-rw-r--r--challenge-032/simon-proctor/small-test.txt6
4 files changed, 192 insertions, 0 deletions
diff --git a/challenge-032/simon-proctor/large-test.txt b/challenge-032/simon-proctor/large-test.txt
new file mode 100644
index 0000000000..996a4625e3
--- /dev/null
+++ b/challenge-032/simon-proctor/large-test.txt
@@ -0,0 +1,100 @@
+apple
+lemon
+cherry
+apple
+cherry
+strawberry
+pear
+cherry
+pear
+apple
+strawberry
+strawberry
+cherry
+lime
+lemon
+lemon
+lemon
+pear
+cherry
+apple
+cherry
+pear
+lemon
+pear
+strawberry
+apple
+pear
+pear
+lime
+strawberry
+apple
+strawberry
+cherry
+lemon
+apple
+lime
+lemon
+apple
+apple
+lemon
+strawberry
+strawberry
+lime
+lime
+lime
+strawberry
+pear
+lemon
+apple
+lemon
+lime
+pear
+strawberry
+cherry
+strawberry
+pear
+strawberry
+lime
+pear
+lemon
+strawberry
+apple
+lime
+lime
+apple
+pear
+lime
+pear
+apple
+lime
+lemon
+cherry
+apple
+lime
+lime
+cherry
+apple
+cherry
+lime
+cherry
+cherry
+pear
+cherry
+lemon
+strawberry
+pear
+apple
+lemon
+cherry
+lime
+apple
+cherry
+pear
+strawberry
+cherry
+apple
+cherry
+lemon
+pear
+apple
diff --git a/challenge-032/simon-proctor/medium-test.txt b/challenge-032/simon-proctor/medium-test.txt
new file mode 100644
index 0000000000..db5f561f55
--- /dev/null
+++ b/challenge-032/simon-proctor/medium-test.txt
@@ -0,0 +1,50 @@
+strawberry
+cherry
+pear
+lemon
+strawberry
+strawberry
+cherry
+pear
+pear
+lemon
+lemon
+lemon
+apple
+cherry
+apple
+strawberry
+strawberry
+lemon
+apple
+strawberry
+lime
+cherry
+cherry
+strawberry
+lime
+apple
+lime
+strawberry
+cherry
+strawberry
+strawberry
+lime
+strawberry
+cherry
+cherry
+strawberry
+apple
+pear
+lime
+lemon
+apple
+apple
+lime
+lime
+strawberry
+pear
+pear
+lemon
+cherry
+lime
diff --git a/challenge-032/simon-proctor/perl6/ch-1.p6 b/challenge-032/simon-proctor/perl6/ch-1.p6
new file mode 100644
index 0000000000..8253bf56a8
--- /dev/null
+++ b/challenge-032/simon-proctor/perl6/ch-1.p6
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+subset ValidFile of Str where *.IO.f;
+my %*SUB-MAIN-OPTS = :named-anywhere;
+
+#| Print help text
+multi sub MAIN( Bool :h($help) where so * ) {
+ say $*USAGE;
+}
+
+#| Read date from standard out.
+#| Returns a list of name and count sorted by count
+multi sub MAIN(
+ Bool :$csv = False #= Output in CSV
+) {
+ read-files( IO::CatHandle.new( $*IN ), $csv );
+}
+
+#| Given a list of filenames reads each in turn
+multi sub MAIN(
+ *@files where all(@files) ~~ ValidFile, #= Files to read
+ Bool :$csv = False #= Output in CSV
+) {
+ read-files( IO::CatHandle.new( @files ), $csv );
+}
+
+sub read-files( IO::CatHandle $files, $csv ) {
+ my %results := BagHash.new();
+ %results{$_}++ for $files.lines;
+ my $k-dist = %results.keys.map( *.codes ).max;
+ my $v-dist = %results.values.map( *.codes ).max;
+ my $fmt = $csv ?? '"%s",%d' !! "% -{$k-dist+2}s%{$v-dist+2}d";
+ .say for %results.sort( *.value <=> *.value ).reverse.map( { sprintf($fmt,$_.key,$_.value) } );
+}
diff --git a/challenge-032/simon-proctor/small-test.txt b/challenge-032/simon-proctor/small-test.txt
new file mode 100644
index 0000000000..00fe021a08
--- /dev/null
+++ b/challenge-032/simon-proctor/small-test.txt
@@ -0,0 +1,6 @@
+apple
+banana
+apple
+cherry
+cherry
+apple