From dd93f741588af128748c55bf327bf2ed9bf75b7c Mon Sep 17 00:00:00 2001 From: Rob4t Date: Mon, 22 Apr 2019 14:39:05 +0200 Subject: solution for challenge 005 --- challenge-005/rob4t/perl6/ch-1.p6 | 16 ++++++++++++++++ challenge-005/rob4t/perl6/ch-2.p6 | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 challenge-005/rob4t/perl6/ch-1.p6 create mode 100644 challenge-005/rob4t/perl6/ch-2.p6 diff --git a/challenge-005/rob4t/perl6/ch-1.p6 b/challenge-005/rob4t/perl6/ch-1.p6 new file mode 100644 index 0000000000..5e12e50898 --- /dev/null +++ b/challenge-005/rob4t/perl6/ch-1.p6 @@ -0,0 +1,16 @@ +#!/usr/bin/env perl6 +use v6; + +sub MAIN(Str $word, Str $file = '/usr/share/dict/words') { + my $word_bag = $word.lc.comb.Bag; + + my @found_words = $file.IO.lines.grep: { + # not the same word + .lc ne $word.lc + and + # look for words AND phrases + .lc.words.map({.comb}).flat.Bag eqv $word_bag + }; + + .say for @found_words; +} diff --git a/challenge-005/rob4t/perl6/ch-2.p6 b/challenge-005/rob4t/perl6/ch-2.p6 new file mode 100644 index 0000000000..d705130729 --- /dev/null +++ b/challenge-005/rob4t/perl6/ch-2.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/env perl6 +use v6; + +sub MAIN(Str $file where *.IO.r = '/usr/share/dict/words' ) { + my %a is Bag = $file.IO.lines.map({.words.map({.comb}).flat.Bag}); + + my $max_val = %a.values.max; + for %a.pairs.grep: *.value == $max_val { + say join(": ", .value, .key.kxxv.sort.join); + } +} -- cgit