diff options
| author | Noud Aldenhoven <noud.aldenhoven@gmail.com> | 2019-09-06 22:33:46 +0200 |
|---|---|---|
| committer | Noud Aldenhoven <noud.aldenhoven@gmail.com> | 2019-09-06 22:33:46 +0200 |
| commit | d8c5c002d07d7bc8acbdfcbb240155442daf116e (patch) | |
| tree | c7807d1d3835d3f5a704a065c7098c84f4ff58dc | |
| parent | b2174d47bf84d062cfd14f6b348959c9ee23c977 (diff) | |
| download | perlweeklychallenge-club-d8c5c002d07d7bc8acbdfcbb240155442daf116e.tar.gz perlweeklychallenge-club-d8c5c002d07d7bc8acbdfcbb240155442daf116e.tar.bz2 perlweeklychallenge-club-d8c5c002d07d7bc8acbdfcbb240155442daf116e.zip | |
Solutions for challenge 023 problem 1 and 2 in Perl 6 by Noud
| -rw-r--r-- | challenge-024/noud/perl6/ch-1.p6 | 3 | ||||
| -rw-r--r-- | challenge-024/noud/perl6/ch-2.p6 | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-024/noud/perl6/ch-1.p6 b/challenge-024/noud/perl6/ch-1.p6 new file mode 100644 index 0000000000..b234361f67 --- /dev/null +++ b/challenge-024/noud/perl6/ch-1.p6 @@ -0,0 +1,3 @@ +# Create a smallest script in terms of size that on execution doesn’t throw any +# error. The script doesn’t have to do anything special. You could even come up +# with smallest one-liner. diff --git a/challenge-024/noud/perl6/ch-2.p6 b/challenge-024/noud/perl6/ch-2.p6 new file mode 100644 index 0000000000..be27520626 --- /dev/null +++ b/challenge-024/noud/perl6/ch-2.p6 @@ -0,0 +1,30 @@ +# Create a script to implement full text search functionality using Inverted +# Index. According to wikipedia: +# +# In computer science, an inverted index (also referred to as a postings file +# or inverted file) is a database index storing a mapping from content, such as +# words or numbers, to its locations in a table, or in a document or a set of +# documents (named in contrast to a forward index, which maps from documents to +# content). The purpose of an inverted index is to allow fast full-text +# searches, at a cost of increased processing when a document is added to the +# database. + +sub MAIN(+@files) { + my %inv_index; + + for @files -> $file { + for $file.IO.words.unique -> $word { + if %inv_index{$word}:exists { + %inv_index{$word} = ($file, |(%inv_index{$word})); + } else { + %inv_index{$word} = ($file); + } + } + } + + for %inv_index.kv -> $k, $v { + "$k: $v".say; + } +} + + |
