aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-04-25 08:45:54 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-04-25 08:45:54 +0100
commit5fd7b3b85e632fa3c9368f58d86d95f569dd70ca (patch)
treeeed918401c5936aeb688ee6882827e11c72b6895
parent050ec05065ff7157374fe3942607dd915e3c9227 (diff)
parent1d2cea0a3b3c942fb9ff310bfc5ebcf668b93945 (diff)
downloadperlweeklychallenge-club-5fd7b3b85e632fa3c9368f58d86d95f569dd70ca.tar.gz
perlweeklychallenge-club-5fd7b3b85e632fa3c9368f58d86d95f569dd70ca.tar.bz2
perlweeklychallenge-club-5fd7b3b85e632fa3c9368f58d86d95f569dd70ca.zip
Merge remote-tracking branch 'upstream/master'
-rwxr-xr-xchallenge-161/jaldhar-h-vyas/perl/ch-1.pl24
-rwxr-xr-xchallenge-161/jaldhar-h-vyas/raku/ch-1.raku20
-rwxr-xr-xchallenge-161/jaldhar-h-vyas/raku/ch-2.raku58
3 files changed, 102 insertions, 0 deletions
diff --git a/challenge-161/jaldhar-h-vyas/perl/ch-1.pl b/challenge-161/jaldhar-h-vyas/perl/ch-1.pl
new file mode 100755
index 0000000000..bda55bc634
--- /dev/null
+++ b/challenge-161/jaldhar-h-vyas/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use 5.030;
+use warnings;
+use English qw/ -no_match_vars /;
+
+# Boy abhors forty cent eggs; cost is crux. Cops chip in, buy a box for him.
+
+# Hippy most ably aces dirty cello ditty. Accept or boo?
+
+my @abcde;
+
+open my $dictionary, '<', 'dictionary.txt' or die "$OS_ERROR\n";
+while (my $line = <$dictionary>) {
+ chomp $line;
+ my $word = $line;
+ if ($word eq join q{}, sort split //, $word) {
+ push @abcde, $word;
+ }
+}
+close $dictionary;
+
+for my $word (sort { length $b <=> length $a } @abcde) {
+ say $word;
+}
diff --git a/challenge-161/jaldhar-h-vyas/raku/ch-1.raku b/challenge-161/jaldhar-h-vyas/raku/ch-1.raku
new file mode 100755
index 0000000000..df4b94be69
--- /dev/null
+++ b/challenge-161/jaldhar-h-vyas/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/raku
+
+# A deers' deep bellow at nosy chimps: "Moo!" it do cry, "Be ill o dirty fuzz foots!"
+
+# Guy airs hip hop art film. It flops in city. His boss bins it.
+
+sub MAIN() {
+ my @words = "dictionary.txt".IO.lines;
+ my @abcde;
+
+ for @words -> $word {
+ if $word eq $word.comb.sort.join {
+ @abcde.push($word);
+ }
+ }
+
+ for @abcde.sort({ $^b.chars <=> $^a.chars }) -> $word {
+ say $word;
+ }
+} \ No newline at end of file
diff --git a/challenge-161/jaldhar-h-vyas/raku/ch-2.raku b/challenge-161/jaldhar-h-vyas/raku/ch-2.raku
new file mode 100755
index 0000000000..b82ac18b45
--- /dev/null
+++ b/challenge-161/jaldhar-h-vyas/raku/ch-2.raku
@@ -0,0 +1,58 @@
+#!/usr/bin/raku
+
+sub makePangram(%wordlists, @completeOrder) {
+ my @pangram = ();
+ my @used;
+ my @order = @completeOrder;
+ my $count = 0;
+
+ loop {
+ my $letter = @order[0];
+ my @choices = (| %wordlists{$letter}).sort({ $^b.chars <=> $^a.chars });
+ my $word = q{};
+ for @choices -> $choice {
+ if $choice.comb ∩ @used == ∅ {
+ $word = $choice;
+ last;
+ }
+ }
+ if $word eq q{} {
+ $word = @choices[0];
+ };
+ @pangram.push($word);
+ @used.push(| $word.comb);
+ @order = @order.grep({ $_ ne @used.any; });
+ $count += $word.chars;
+ if @order.elems == 0 {
+ last;
+ }
+ }
+
+ return @pangram;
+}
+
+sub count(@pangram) {
+ return [+] @pangram.map({ $_.chars});
+}
+
+sub MAIN() {
+ my @words = "dictionary.txt".IO.lines;
+ my %wordlists;
+
+ for @words -> $word {
+ my @letters = $word.comb;
+ if $word eq @letters.sort.join && (@letters.categorize({ $_ })).values.all == 1 {
+ for $word.comb -> $letter {
+ %wordlists{$letter}.push($word);
+ }
+ }
+ }
+
+ my @order = %wordlists
+ .keys
+ .sort({ %wordlists{$^a}.elems <=> %wordlists{$^b}.elems });
+
+ my @pangram = makePangram(%wordlists, @order);
+
+ say "'", @pangram.join(q{ }), "' has ", count(@pangram), ' letters.';
+}