diff options
Diffstat (limited to 'challenge-024')
65 files changed, 1276 insertions, 0 deletions
diff --git a/challenge-024/adam-russell/blog.txt b/challenge-024/adam-russell/blog.txt new file mode 100644 index 0000000000..b838b1da20 --- /dev/null +++ b/challenge-024/adam-russell/blog.txt @@ -0,0 +1 @@ +https://adamcrussell.livejournal.com/8122.html diff --git a/challenge-024/adam-russell/blog1.txt b/challenge-024/adam-russell/blog1.txt new file mode 100644 index 0000000000..10db5957a4 --- /dev/null +++ b/challenge-024/adam-russell/blog1.txt @@ -0,0 +1 @@ +https://adamcrussell.livejournal.com/8285.html diff --git a/challenge-024/adam-russell/data/arrow.txt b/challenge-024/adam-russell/data/arrow.txt new file mode 100644 index 0000000000..1754d2fa6a --- /dev/null +++ b/challenge-024/adam-russell/data/arrow.txt @@ -0,0 +1,15 @@ +On a certain afternoon, in the late springtime, the bell upon Tunstall +Moat House was heard ringing at an unaccustomed hour. Far and near, in +the forest and in the fields along the river, people began to desert +their labours and hurry towards the sound; and in Tunstall hamlet a group +of poor country-folk stood wondering at the summons. + +Tunstall hamlet at that period, in the reign of old King Henry VI., wore +much the same appearance as it wears to-day. A score or so of houses, +heavily framed with oak, stood scattered in a long green valley ascending +from the river. At the foot, the road crossed a bridge, and mounting on +the other side, disappeared into the fringes of the forest on its way to +the Moat House, and further forth to Holywood Abbey. Half-way up the +village, the church stood among yews. On every side the slopes were +crowned and the view bounded by the green elms and greening oak-trees of +the forest. diff --git a/challenge-024/adam-russell/data/balloon.txt b/challenge-024/adam-russell/data/balloon.txt new file mode 100644 index 0000000000..6dda8b0bd3 --- /dev/null +++ b/challenge-024/adam-russell/data/balloon.txt @@ -0,0 +1,29 @@ +The End of a much-applauded Speech.--The Presentation of Dr. Samuel +Ferguson.--Excelsior.--Full-length Portrait of the Doctor.--A Fatalist +convinced.--A Dinner at the Travellers’ Club.--Several Toasts for the +Occasion. + +There was a large audience assembled on the 14th of January, 1862, at +the session of the Royal Geographical Society, No. 3 Waterloo +Place, London. The president, Sir Francis M----, made an important +communication to his colleagues, in an address that was frequently +interrupted by applause. + +This rare specimen of eloquence terminated with the following sonorous +phrases bubbling over with patriotism: + +“England has always marched at the head of nations” (for, the reader +will observe, the nations always march at the head of each other), “by +the intrepidity of her explorers in the line of geographical discovery.” + (General assent). “Dr. Samuel Ferguson, one of her most glorious sons, +will not reflect discredit on his origin.” (“No, indeed!” from all parts +of the hall.) + +“This attempt, should it succeed” (“It will succeed!”), “will complete +and link together the notions, as yet disjointed, which the world +entertains of African cartology” (vehement applause); “and, should it +fail, it will, at least, remain on record as one of the most daring +conceptions of human genius!” (Tremendous cheering.) + +“Huzza! huzza!” shouted the immense audience, completely electrified by +these inspiring words. diff --git a/challenge-024/adam-russell/data/call.txt b/challenge-024/adam-russell/data/call.txt new file mode 100644 index 0000000000..e9059de1d3 --- /dev/null +++ b/challenge-024/adam-russell/data/call.txt @@ -0,0 +1,9 @@ +Buck did not read the newspapers, or he would have known that trouble +was brewing, not alone for himself, but for every tide-water dog, +strong of muscle and with warm, long hair, from Puget Sound to San +Diego. Because men, groping in the Arctic darkness, had found a yellow +metal, and because steamship and transportation companies were booming +the find, thousands of men were rushing into the Northland. These men +wanted dogs, and the dogs they wanted were heavy dogs, with strong +muscles by which to toil, and furry coats to protect them from the +frost. diff --git a/challenge-024/adam-russell/data/catriona.txt b/challenge-024/adam-russell/data/catriona.txt new file mode 100644 index 0000000000..3b38fbc6ba --- /dev/null +++ b/challenge-024/adam-russell/data/catriona.txt @@ -0,0 +1,24 @@ +The 25th day of August, 1751, about two in the afternoon, I, David +Balfour, came forth of the British Linen Company, a porter attending me +with a bag of money, and some of the chief of these merchants bowing me +from their doors. Two days before, and even so late as yestermorning, I +was like a beggar-man by the wayside, clad in rags, brought down to my +last shillings, my companion a condemned traitor, a price set on my own +head for a crime with the news of which the country rang. To-day I was +served heir to my position in life, a landed laird, a bank porter by me +carrying my gold, recommendations in my pocket, and (in the words of the +saying) the ball directly at my foot. + +There were two circumstances that served me as ballast to so much sail. +The first was the very difficult and deadly business I had still to +handle; the second, the place that I was in. The tall, black city, and +the numbers and movement and noise of so many folk, made a new world for +me, after the moorland braes, the sea-sands and the still country-sides +that I had frequented up to then. The throng of the citizens in +particular abashed me. Rankeillor’s son was short and small in the +girth; his clothes scarce held on me; and it was plain I was ill +qualified to strut in the front of a bank-porter. It was plain, if I did +so, I should but set folk laughing, and (what was worse in my case) set +them asking questions. So that I behooved to come by some clothes of my +own, and in the meanwhile to walk by the porter’s side, and put my hand +on his arm as though we were a pair of friends. diff --git a/challenge-024/adam-russell/data/eighty.txt b/challenge-024/adam-russell/data/eighty.txt new file mode 100644 index 0000000000..971f0f08e3 --- /dev/null +++ b/challenge-024/adam-russell/data/eighty.txt @@ -0,0 +1,26 @@ +Mr. Phileas Fogg lived, in 1872, at No. 7, Saville Row, Burlington +Gardens, the house in which Sheridan died in 1814. He was one of the +most noticeable members of the Reform Club, though he seemed always to +avoid attracting attention; an enigmatical personage, about whom little +was known, except that he was a polished man of the world. People said +that he resembled Byron--at least that his head was Byronic; but he was +a bearded, tranquil Byron, who might live on a thousand years without +growing old. + +Certainly an Englishman, it was more doubtful whether Phileas Fogg was +a Londoner. He was never seen on 'Change, nor at the Bank, nor in the +counting-rooms of the "City"; no ships ever came into London docks of +which he was the owner; he had no public employment; he had never been +entered at any of the Inns of Court, either at the Temple, or Lincoln's +Inn, or Gray's Inn; nor had his voice ever resounded in the Court of +Chancery, or in the Exchequer, or the Queen's Bench, or the +Ecclesiastical Courts. He certainly was not a manufacturer; nor was he +a merchant or a gentleman farmer. His name was strange to the +scientific and learned societies, and he never was known to take part +in the sage deliberations of the Royal Institution or the London +Institution, the Artisan's Association, or the Institution of Arts and +Sciences. He belonged, in fact, to none of the numerous societies +which swarm in the English capital, from the Harmonic to that of the +Entomologists, founded mainly for the purpose of abolishing pernicious +insects. + diff --git a/challenge-024/adam-russell/data/fang.txt b/challenge-024/adam-russell/data/fang.txt new file mode 100644 index 0000000000..30bd899bb7 --- /dev/null +++ b/challenge-024/adam-russell/data/fang.txt @@ -0,0 +1,12 @@ +Dark spruce forest frowned on either side the frozen waterway. The trees +had been stripped by a recent wind of their white covering of frost, and +they seemed to lean towards each other, black and ominous, in the fading +light. A vast silence reigned over the land. The land itself was a +desolation, lifeless, without movement, so lone and cold that the spirit +of it was not even that of sadness. There was a hint in it of laughter, +but of a laughter more terrible than any sadness--a laughter that was +mirthless as the smile of the sphinx, a laughter cold as the frost and +partaking of the grimness of infallibility. It was the masterful and +incommunicable wisdom of eternity laughing at the futility of life and +the effort of life. It was the Wild, the savage, frozen-hearted +Northland Wild. diff --git a/challenge-024/adam-russell/data/kidnapped.txt b/challenge-024/adam-russell/data/kidnapped.txt new file mode 100644 index 0000000000..0fe6c7616a --- /dev/null +++ b/challenge-024/adam-russell/data/kidnapped.txt @@ -0,0 +1,13 @@ +I will begin the story of my adventures with a certain morning early in +the month of June, the year of grace 1751, when I took the key for the +last time out of the door of my father’s house. The sun began to shine +upon the summit of the hills as I went down the road; and by the time +I had come as far as the manse, the blackbirds were whistling in the +garden lilacs, and the mist that hung around the valley in the time of +the dawn was beginning to arise and die away. + +Mr. Campbell, the minister of Essendean, was waiting for me by the +garden gate, good man! He asked me if I had breakfasted; and hearing +that I lacked for nothing, he took my hand in both of his and clapped it +kindly under his arm. + diff --git a/challenge-024/adam-russell/perl5/ch-1.sh b/challenge-024/adam-russell/perl5/ch-1.sh new file mode 100644 index 0000000000..286af7e33a --- /dev/null +++ b/challenge-024/adam-russell/perl5/ch-1.sh @@ -0,0 +1 @@ +perl -d -e 0 diff --git a/challenge-024/adam-russell/perl5/ch-2.pl b/challenge-024/adam-russell/perl5/ch-2.pl new file mode 100644 index 0000000000..f1e5f7e76b --- /dev/null +++ b/challenge-024/adam-russell/perl5/ch-2.pl @@ -0,0 +1,77 @@ +use strict; +use warnings; +## +# Create a script to implement full text search functionality using Inverted Index. +## +use boolean; +use constant DATA_DIR => "./data/"; + +sub index_contents{ + my($index, $file) = @_; + my %seen; + my $contents; + do{ + local $/; + open(F, $file); + $contents = <F>; + $contents =~ tr/-/ /; + $contents =~ s/[^[:ascii:]]//g; + $contents =~ s/[[:punct:]]//g; + close(F); + }; + my $d = DATA_DIR; + $file =~ s/$d//g; + my @words = split(/\s+/, $contents); + @words = map { lc($_) } @words; + for my $word (@words){ + if(!$index->{$word}){ + $index->{$word} = [$file]; + $seen{$word} = true; + } + if($index->{$word} && !$seen{$word}){ + push @{$index->{$word}}, $file; + $seen{$word} = true; + } + } +} + +sub print_index{ + my($index) = @_; + my($word, $documents); + format INDEX_HEADER = + ------------------------------------------------------------------------------------------------------ + |Word | Documents | + ------------------------------------------------------------------------------------------------------ +. + format INDEX = + |@<<<<<<<<<<<<<<|@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<| + $word, $documents +. + format INDEX_FOOTER = + ------------------------------------------------------------------------------------------------------ +. + $~ = "INDEX_HEADER"; + write; + + $~ = "INDEX"; + for my $w (sort keys %{$index}){ + $word = $w; + $documents = join(", ", @{$index->{$w}}); + write; + } + + $~ = "INDEX_FOOTER"; + write; +} + +MAIN:{ + my %index; + opendir(DATA, DATA_DIR); + while(my $file = readdir(DATA)){ + if(-f DATA_DIR.$file){ + index_contents(\%index, DATA_DIR.$file); + } + } + close(DATA); + print_index(\%index); +} diff --git a/challenge-024/andrezgz/perl5/ch-1.pl b/challenge-024/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..aacea2a264 --- /dev/null +++ b/challenge-024/andrezgz/perl5/ch-1.pl @@ -0,0 +1 @@ +print "This script is the smallest in terms of size that on execution doesn't throw any error, doesn't do anything special and explains what it does" diff --git a/challenge-024/andrezgz/perl5/ch-2.pl b/challenge-024/andrezgz/perl5/ch-2.pl new file mode 100644 index 0000000000..49aa67a02a --- /dev/null +++ b/challenge-024/andrezgz/perl5/ch-2.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-024/ +# Task #2 +# 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. +# Here is a nice example of Inverted Index. +# https://en.wikipedia.org/wiki/Search_engine_indexing#Inverted_indices + +use strict; +use warnings; + +die "Usage: $0 <file1> [<fileN>]" if @ARGV == 0; + +# Prepare inverted index +my %index; +while (<>) { + chomp; # remove line trailing string + s/["'?!]/ /ig; # some cleaning + my @words = grep { # filter words... + length > 2 # with 3 or more... + && /^[a-z\-]+$/i # alphabetic and hyphen characters only + } + split /[.,; ]/; # split line in words + $index{lc $_}{$ARGV}++ for (@words); # store word usage in file +} +print 'Words added: ' . join(',',sort keys %index) . "\n"; + +# Search word +print "\nSearch word: "; +my $w = <>; +chomp $w; +if ( exists $index{lc $w} ) { + print "'$w' was found on ", join(',',keys %{$index{lc $w}}) . "\n"; +} +else { + print "'$w' wasn't found on any document\n"; +} diff --git a/challenge-024/andrezgz/perl5/father_sons.txt b/challenge-024/andrezgz/perl5/father_sons.txt new file mode 100644 index 0000000000..cf15c7f292 --- /dev/null +++ b/challenge-024/andrezgz/perl5/father_sons.txt @@ -0,0 +1,17 @@ +The Father and His Sons + +A FATHER had a family of sons who were perpetually quarreling +among themselves. When he failed to heal their disputes by his +exhortations, he determined to give them a practical illustration +of the evils of disunion; and for this purpose he one day told +them to bring him a bundle of sticks. When they had done so, he +placed the faggot into the hands of each of them in succession, +and ordered them to break it in pieces. They tried with all +their strength, and were not able to do it. He next opened the +faggot, took the sticks separately, one by one, and again put +them into his sons' hands, upon which they broke them easily. He +then addressed them in these words: "My sons, if you are of one +mind, and unite to assist each other, you will be as this faggot, +uninjured by all the attempts of your enemies; but if you are +divided among yourselves, you will be broken as easily as these +sticks." diff --git a/challenge-024/andrezgz/perl5/herdsman_bull.txt b/challenge-024/andrezgz/perl5/herdsman_bull.txt new file mode 100644 index 0000000000..f106e4f08c --- /dev/null +++ b/challenge-024/andrezgz/perl5/herdsman_bull.txt @@ -0,0 +1,14 @@ +The Herdsman and the Lost Bull + +A HERDSMAN tending his flock in a forest lost a Bull-calf from +the fold. After a long and fruitless search, he made a vow that, +if he could only discover the thief who had stolen the Calf, he +would offer a lamb in sacrifice to Hermes, Pan, and the Guardian +Deities of the forest. Not long afterwards, as he ascended a +small hillock, he saw at its foot a Lion feeding on the Calf. +Terrified at the sight, he lifted his eyes and his hands to +heaven, and said: "Just now I vowed to offer a lamb to the +Guardian Deities of the forest if I could only find out who had +robbed me; but now that I have discovered the thief, I would +willingly add a full-grown Bull to the Calf I have lost, if I may +only secure my own escape from him in safety." diff --git a/challenge-024/andrezgz/perl5/lion_mouse.txt b/challenge-024/andrezgz/perl5/lion_mouse.txt new file mode 100644 index 0000000000..36738f2918 --- /dev/null +++ b/challenge-024/andrezgz/perl5/lion_mouse.txt @@ -0,0 +1,15 @@ +The Lion and the Mouse + +A LION was awakened from sleep by a Mouse running over his face. +Rising up angrily, he caught him and was about to kill him, when +the Mouse piteously entreated, saying: "If you would only spare +my life, I would be sure to repay your kindness." The Lion +laughed and let him go. It happened shortly after this that the +Lion was caught by some hunters, who bound him by st ropes to the +ground. The Mouse, recognizing his roar, came gnawed the rope +with his teeth, and set him free, exclaim + +"You ridiculed the idea of my ever being able to help you, +expecting to receive from me any repayment of your favor; I now +you know that it is possible for even a Mouse to con benefits on +a Lion." diff --git a/challenge-024/andrezgz/perl5/wolf_lamb.txt b/challenge-024/andrezgz/perl5/wolf_lamb.txt new file mode 100644 index 0000000000..3b05b40064 --- /dev/null +++ b/challenge-024/andrezgz/perl5/wolf_lamb.txt @@ -0,0 +1,15 @@ +The Wolf and the Lamb + +WOLF, meeting with a Lamb astray from the fold, resolved not to +lay violent hands on him, but to find some plea to justify to the +Lamb the Wolf's right to eat him. He thus addressed him: +"Sirrah, last year you grossly insulted me." "Indeed," bleated +the Lamb in a mournful tone of voice, "I was not then born." Then +said the Wolf, "You feed in my pasture." "No, good sir," replied +the Lamb, "I have not yet tasted grass." Again said the Wolf, +"You drink of my well." "No," exclaimed the Lamb, "I never yet +drank water, for as yet my mother's milk is both food and drink +to me." Upon which the Wolf seized him and ate him up, saying, +"Well! I won't remain supperless, even though you refute every +one of my imputations." The tyrant will always find a pretext for +his tyranny. diff --git a/challenge-024/arne-sommer/blog.txt b/challenge-024/arne-sommer/blog.txt new file mode 100644 index 0000000000..024dba115d --- /dev/null +++ b/challenge-024/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://perl6.eu/small-inversions.html |
