aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-07 18:42:07 +0000
committerGitHub <noreply@github.com>2021-01-07 18:42:07 +0000
commitdfd1365687e1a9cedb7a1ac20df3e2ab4b83fe30 (patch)
tree4a433325ec1f80c5da07322ad33123c5fe50ce35
parent6272ee3b91b58c65215cdbcf4e40f0bbc09d2088 (diff)
parent3c80d018362f4cdf6576447fabe12ca084ca91fe (diff)
downloadperlweeklychallenge-club-dfd1365687e1a9cedb7a1ac20df3e2ab4b83fe30.tar.gz
perlweeklychallenge-club-dfd1365687e1a9cedb7a1ac20df3e2ab4b83fe30.tar.bz2
perlweeklychallenge-club-dfd1365687e1a9cedb7a1ac20df3e2ab4b83fe30.zip
Merge pull request #3178 from pkmnx/branch-for-challenge-94
challenge #94, only ch. 1
-rwxr-xr-xchallenge-094/pkmnx/raku/ch-1.raku42
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-094/pkmnx/raku/ch-1.raku b/challenge-094/pkmnx/raku/ch-1.raku
new file mode 100755
index 0000000000..2a5e699ae5
--- /dev/null
+++ b/challenge-094/pkmnx/raku/ch-1.raku
@@ -0,0 +1,42 @@
+#!/usr/bin/env raku
+
+# see usage:
+#
+# pk@pkx:~/stuff/raku/perlweeklychallenge-club/challenge-094/pkmnx/raku$ echo "opt", "bat", "saw", "tab", "pot", "top", "was" | ./ch-1.raku
+# Input: ("opt", "bat", "saw", "tab", "pot", "top", "was")
+# Output: [
+# ("bat", "tab"),
+# ("saw", "was"),
+# ("opt", "pot", "top") ]
+#
+
+sub MAIN() {
+
+ my $ws = [];
+ for lines() -> $l {
+ ( $l ~~ m:g:i/<[a .. z]>+/ ).map({ $ws.push( $_ ~ '' ) });
+ }
+
+ die ("Not enough input words!") if $ws.elems < 1;
+
+ my $fn = -> $x { "(" ~ $x.map({ qq{"$_"} }).join(", ") ~ ")" };
+
+ printf "Input: %s\n", $fn($ws);
+
+ my $anag = {};
+ $ws.map( -> $w {
+ my $h = {};
+ $w.comb().map({ $h{$_}++ });
+ $anag{
+ $h.keys.sort().map({ ($_, $h{$_}).join("|") }).join(";");
+ }.push( $w );
+ });
+
+ my $out = [];
+ for $anag.kv -> $k, $v {
+ $out.push( " " ~ $fn($v) );
+ }
+
+ printf "Output: [\n%s ]\n", $out.join(",\n");
+
+}