From 1391a8dd6400d0c5c8acbb7ab9111fb0548accdd Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 2 Sep 2019 09:23:15 +0100 Subject: Apparently an empty file runs fine in both perl5 and perl6 --- challenge-024/simon-proctor/perl5/ch-1.pl | 0 challenge-024/simon-proctor/perl6/ch-1.p6 | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 challenge-024/simon-proctor/perl5/ch-1.pl create mode 100644 challenge-024/simon-proctor/perl6/ch-1.p6 diff --git a/challenge-024/simon-proctor/perl5/ch-1.pl b/challenge-024/simon-proctor/perl5/ch-1.pl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-024/simon-proctor/perl6/ch-1.p6 b/challenge-024/simon-proctor/perl6/ch-1.p6 new file mode 100644 index 0000000000..e69de29bb2 -- cgit From 4eb4b2ae6f28de11475256dd94eeec739446517e Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 2 Sep 2019 11:20:49 +0100 Subject: Inverted Indexer creator. Multi threaded because why wouldn't you? --- challenge-024/simon-proctor/perl6/ch-2.p6 | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 challenge-024/simon-proctor/perl6/ch-2.p6 diff --git a/challenge-024/simon-proctor/perl6/ch-2.p6 b/challenge-024/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..c8ac377ffa --- /dev/null +++ b/challenge-024/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,51 @@ +#!/usr/bin/env perl6 + +use v6; +use JSON::Fast; + +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Display Help information +multi sub MAIN ( Bool :h(:$help) where so * ) { + say $*USAGE; +} + +subset FileExists of Str where { $_.IO.e && $_.IO.f }; + +#| Work out the reverse index for the given documents +multi sub MAIN ( + *@documents where { @documents.all ~~ FileExists }, #= List of documents to process + Int :$min-length = 3, #= Minimum word length to count for inclusion in the index. Default is 3 characters. +) { + my %index; + my $word-channel = Channel.new; + my @promises; + my $promise-count++; + + for @documents -> $path { + @promises.push( + start { + my $res-path = $path.IO.resolve.Str; + for $path.IO.words -> $word is copy { + $word ~~ s:g!<[\W]>!!; + next unless $word.chars >= $min-length; + $word-channel.send( ( $word.fc, $res-path ) ); + } + } + ); + } + + my $reactor = start react { + whenever $word-channel -> ( $word, $path ) { + %index{$word} //= SetHash.new; + %index{$word}.{$path} = True; + } + } + await @promises; + $word-channel.close; + await $reactor; + + %index = %index.map( { $_.key => $_.value.keys } ); + say to-json( %index ); +} + -- cgit From 8422e1828e6d2eaa04e9efef795f315edd9b6d58 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 2 Sep 2019 11:21:53 +0100 Subject: Don't need this --- challenge-024/simon-proctor/perl6/ch-2.p6 | 1 - 1 file changed, 1 deletion(-) diff --git a/challenge-024/simon-proctor/perl6/ch-2.p6 b/challenge-024/simon-proctor/perl6/ch-2.p6 index c8ac377ffa..d44fbc40fc 100644 --- a/challenge-024/simon-proctor/perl6/ch-2.p6 +++ b/challenge-024/simon-proctor/perl6/ch-2.p6 @@ -20,7 +20,6 @@ multi sub MAIN ( my %index; my $word-channel = Channel.new; my @promises; - my $promise-count++; for @documents -> $path { @promises.push( -- cgit