diff options
| -rw-r--r-- | challenge-024/ruben-westerberg/README | 19 | ||||
| -rw-r--r-- | challenge-024/ruben-westerberg/perl5/ch-1.pl | 0 | ||||
| -rwxr-xr-x | challenge-024/ruben-westerberg/perl5/ch-2.pl | 24 | ||||
| -rw-r--r-- | challenge-024/ruben-westerberg/perl6/ch-1.p6 | 0 | ||||
| -rwxr-xr-x | challenge-024/ruben-westerberg/perl6/ch-2.p6 | 28 |
5 files changed, 61 insertions, 10 deletions
diff --git a/challenge-024/ruben-westerberg/README b/challenge-024/ruben-westerberg/README index fa2d20850a..bd6dab73ef 100644 --- a/challenge-024/ruben-westerberg/README +++ b/challenge-024/ruben-westerberg/README @@ -2,17 +2,16 @@ Solution by Ruben Westerberg ch-1.pl and ch-1.p6 === -Run the program to calculate the forward difference of a number sequence entered on the command line. -If no order is specified an order of 1 is used and if no sequence is specified a example sequence is used - - ch-1.pl usage: - ./ch-1.pl -o 2 -- 1 3 6 9 - ch-2.p6 usage: - ./ch-1.p6 --order=2 1 3 6 9 +Shortest script that doesn't throw an error... + usage + perl ch-1.pl + perl6 ch-1.pl + Scripts are 0 bytes in size ch-2.pl and ch-2.p6 === -Run the program to display the prime decomposition of the number intered on the command line. -If no number is specifed the demo value of 228 is decomposed. - +Builds and prints out a inverted index of all words in in put documents. Text files are provided as command line arguments. +The output of the program show the word, the locations of this word in each of the files. +usage example: + ./ch-2.pl ../text/{beowulf.txt,pride.txt} diff --git a/challenge-024/ruben-westerberg/perl5/ch-1.pl b/challenge-024/ruben-westerberg/perl5/ch-1.pl new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-024/ruben-westerberg/perl5/ch-1.pl diff --git a/challenge-024/ruben-westerberg/perl5/ch-2.pl b/challenge-024/ruben-westerberg/perl5/ch-2.pl new file mode 100755 index 0000000000..90fdecf927 --- /dev/null +++ b/challenge-024/ruben-westerberg/perl5/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +use strict; +use warnings; +my %index; +for my $path (@ARGV) { + open my $h, "<",$path; + my $number=1; + while (my $line=<$h>) { + my @words=split /\W+/, $line; + for my $w (@words) { + $index{$w}{$path}{count}++; + push @{$index{$w}{$path}{lines}}, $number; + } + $number++; + } + close $h; +} +for (sort keys %index) { + print "Word: $_\n"; + my $e=$index{$_}; + for (sort keys %$e) { + printf "\tFile: %s\t Count: %s\t Line: %s\n",$_,$$e{$_}{count},join " ", @{$$e{$_}{lines}}; + } +} diff --git a/challenge-024/ruben-westerberg/perl6/ch-1.p6 b/challenge-024/ruben-westerberg/perl6/ch-1.p6 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-024/ruben-westerberg/perl6/ch-1.p6 diff --git a/challenge-024/ruben-westerberg/perl6/ch-2.p6 b/challenge-024/ruben-westerberg/perl6/ch-2.p6 new file mode 100755 index 0000000000..32ebcba314 --- /dev/null +++ b/challenge-024/ruben-westerberg/perl6/ch-2.p6 @@ -0,0 +1,28 @@ +#!/usr/bin/env perl6 +# +my %index; + +#build the index tree +$*ARGFILES.handles.map({ + .encoding('utf8'); + my $path=.path; + my $line=1; + sink .lines.map({ + sink .comb(/\w+/). map({ + %index{$_}{$path}<count>++; + %index{$_}{$path}<lines>.push($line); + }); + $line++; + }); +}); + +#print out the index tree sorted by words +%index.keys.sort.map({ + print "Word: $_\n"; + my $e=%index{$_};#$_; + sink $e.keys.sort.map({ + printf "\tFile: %s\t Count: %s\t Line: %s\n", $_, $e{$_}.<count>, $e{$_}.<lines>; + }); +}); + + |
