diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-04-22 02:09:57 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-04-22 02:09:57 +0100 |
| commit | 9193f6efa6b1c5627818ae70b22bca942934d9b1 (patch) | |
| tree | a8013501d340c9ce3db3b6590f951d9f7c2ab1db /challenge-005 | |
| parent | 1843da5ab5b8146cc9b70fbb8285ca6e9390e11f (diff) | |
| download | perlweeklychallenge-club-9193f6efa6b1c5627818ae70b22bca942934d9b1.tar.gz perlweeklychallenge-club-9193f6efa6b1c5627818ae70b22bca942934d9b1.tar.bz2 perlweeklychallenge-club-9193f6efa6b1c5627818ae70b22bca942934d9b1.zip | |
- Added template for challenge 005.
Diffstat (limited to 'challenge-005')
77 files changed, 170 insertions, 0 deletions
diff --git a/challenge-005/abigail/README b/challenge-005/abigail/README new file mode 100644 index 0000000000..5f0d73ae16 --- /dev/null +++ b/challenge-005/abigail/README @@ -0,0 +1 @@ +Solution by Abigail diff --git a/challenge-005/adam-russell/README b/challenge-005/adam-russell/README new file mode 100644 index 0000000000..9420c9a781 --- /dev/null +++ b/challenge-005/adam-russell/README @@ -0,0 +1 @@ +Solution by Adam Russell diff --git a/challenge-005/ailbhe-tweedie/README b/challenge-005/ailbhe-tweedie/README new file mode 100644 index 0000000000..36d4034b70 --- /dev/null +++ b/challenge-005/ailbhe-tweedie/README @@ -0,0 +1 @@ +Solution by Ailbhe Tweedie diff --git a/challenge-005/alex-daniel/README b/challenge-005/alex-daniel/README new file mode 100644 index 0000000000..65550789bd --- /dev/null +++ b/challenge-005/alex-daniel/README @@ -0,0 +1 @@ +Solution by Alex Daniel. diff --git a/challenge-005/alexander-karelas/README b/challenge-005/alexander-karelas/README new file mode 100644 index 0000000000..3de9fce8d9 --- /dev/null +++ b/challenge-005/alexander-karelas/README @@ -0,0 +1 @@ +Solution by Alexander Karelas diff --git a/challenge-005/alexey-melezhik/README b/challenge-005/alexey-melezhik/README new file mode 100644 index 0000000000..ca7008f224 --- /dev/null +++ b/challenge-005/alexey-melezhik/README @@ -0,0 +1 @@ +Solution by Alexey Melezhik diff --git a/challenge-005/alicia-bielsa/README b/challenge-005/alicia-bielsa/README new file mode 100644 index 0000000000..c5187874c3 --- /dev/null +++ b/challenge-005/alicia-bielsa/README @@ -0,0 +1 @@ +Solution by Alicia Beilsa. diff --git a/challenge-005/andrezgz/README b/challenge-005/andrezgz/README new file mode 100644 index 0000000000..f4fd0da88e --- /dev/null +++ b/challenge-005/andrezgz/README @@ -0,0 +1 @@ +Solution by Andrezgz diff --git a/challenge-005/antonio-gamiz/README b/challenge-005/antonio-gamiz/README new file mode 100644 index 0000000000..1f5ed5871a --- /dev/null +++ b/challenge-005/antonio-gamiz/README @@ -0,0 +1 @@ +Solution by Antonio Gamiz diff --git a/challenge-005/arne-sommer/README b/challenge-005/arne-sommer/README new file mode 100644 index 0000000000..b5d88e4df4 --- /dev/null +++ b/challenge-005/arne-sommer/README @@ -0,0 +1 @@ +Solution by Arne Sommer. diff --git a/challenge-005/arpad-toth/README b/challenge-005/arpad-toth/README new file mode 100644 index 0000000000..6661dd82c1 --- /dev/null +++ b/challenge-005/arpad-toth/README @@ -0,0 +1 @@ +Solution by Arpad Toth diff --git a/challenge-005/athanasius/README b/challenge-005/athanasius/README new file mode 100644 index 0000000000..cc357fda4a --- /dev/null +++ b/challenge-005/athanasius/README @@ -0,0 +1 @@ +Solution by Athanasius diff --git a/challenge-005/aubrey-quarcoo/README b/challenge-005/aubrey-quarcoo/README new file mode 100644 index 0000000000..8e63a2c1f5 --- /dev/null +++ b/challenge-005/aubrey-quarcoo/README @@ -0,0 +1 @@ +Solution by Aubrey Quarcoo diff --git a/challenge-005/bill-palmer/README b/challenge-005/bill-palmer/README new file mode 100644 index 0000000000..08ec849a41 --- /dev/null +++ b/challenge-005/bill-palmer/README @@ -0,0 +1 @@ +Solution by Bill Palmer. diff --git a/challenge-005/bob-kleemann/README b/challenge-005/bob-kleemann/README new file mode 100644 index 0000000000..78680e4035 --- /dev/null +++ b/challenge-005/bob-kleemann/README @@ -0,0 +1 @@ +Solution by Bob Kleemann diff --git a/challenge-005/cliveholloway/README b/challenge-005/cliveholloway/README new file mode 100644 index 0000000000..b69201296e --- /dev/null +++ b/challenge-005/cliveholloway/README @@ -0,0 +1 @@ +Solution by Clive Holloway diff --git a/challenge-005/daniel-mantovani/README b/challenge-005/daniel-mantovani/README new file mode 100644 index 0000000000..ed538216f2 --- /dev/null +++ b/challenge-005/daniel-mantovani/README @@ -0,0 +1 @@ +Solution by Daniel Mantovani diff --git a/challenge-005/dave-cross/README b/challenge-005/dave-cross/README new file mode 100644 index 0000000000..04b1b0623b --- /dev/null +++ b/challenge-005/dave-cross/README @@ -0,0 +1 @@ +Solution by Dave Cross diff --git a/challenge-005/dave-jacoby/README b/challenge-005/dave-jacoby/README new file mode 100644 index 0000000000..7c06689f16 --- /dev/null +++ b/challenge-005/dave-jacoby/README @@ -0,0 +1 @@ +Solution by Dave Jacoby diff --git a/challenge-005/david-kayal/README b/challenge-005/david-kayal/README new file mode 100644 index 0000000000..66f8615260 --- /dev/null +++ b/challenge-005/david-kayal/README @@ -0,0 +1 @@ +Solution by David Kayal diff --git a/challenge-005/doug-schrag/README b/challenge-005/doug-schrag/README new file mode 100644 index 0000000000..bf8a10ffb4 --- /dev/null +++ b/challenge-005/doug-schrag/README @@ -0,0 +1 @@ +Solution by Doug Schrag diff --git a/challenge-005/duncan-c-white/README b/challenge-005/duncan-c-white/README new file mode 100644 index 0000000000..c5628c24dd --- /dev/null +++ b/challenge-005/duncan-c-white/README @@ -0,0 +1,24 @@ +Challenge 1: "Write a script to output the same number of PI digits +as the size of your script. Say, if your script size is 10, it should +print 3.141592653." + +Note that it DOESN'T SAY "calculate the same number of PI digits..." so +I took the liberty to grab them over the internet (via a bitly link I set +up to shorten the URL and hence the program) rather than generate them +on the fly, because generating Pi is so dull. + +Note that ch-1.pl takes an optional single command line argument to tell +how many digits to print, if absent the default is to use the size of +the script as the question wanted. I built two cut down versions of the +script, but didn't include them here. + + +Challenge 2: "You are given a file containing a list of words (case +insensitive 1 word per line) and a list of letters. Print each word from +the file than can be made using only letters from the list. You can use +each letter only once (though there can be duplicates and you can use +each of them once), you don't have to use all the letters." + +This is a natural "bag of words" question, essentially we need to build +a "bag subset" operation. See ch-2.pl for the solution, simple and obvious +(I love Perl's hashes especially for their idiomatic set and bag uses). diff --git a/challenge-005/eddy-hs/README b/challenge-005/eddy-hs/README new file mode 100644 index 0000000000..0ed51d222d --- /dev/null +++ b/challenge-005/eddy-hs/README @@ -0,0 +1 @@ +Solution by Eddy HS diff --git a/challenge-005/finley/README b/challenge-005/finley/README new file mode 100644 index 0000000000..f08a121076 --- /dev/null +++ b/challenge-005/finley/README @@ -0,0 +1 @@ +Solution by Finley diff --git a/challenge-005/fjwhittle/README b/challenge-005/fjwhittle/README new file mode 100644 index 0000000000..7dcc95e189 --- /dev/null +++ b/challenge-005/fjwhittle/README @@ -0,0 +1 @@ +Solution by Francis Whittle diff --git a/challenge-005/fred-zinn/README b/challenge-005/fred-zinn/README new file mode 100644 index 0000000000..17bac4f094 --- /dev/null +++ b/challenge-005/fred-zinn/README @@ -0,0 +1 @@ +Solution by Fred Zinn diff --git a/challenge-005/freddie-b/README b/challenge-005/freddie-b/README new file mode 100644 index 0000000000..823d7474b5 --- /dev/null +++ b/challenge-005/freddie-b/README @@ -0,0 +1 @@ +Solution by Freddie B diff --git a/challenge-005/gustavo-chaves/README b/challenge-005/gustavo-chaves/README new file mode 100644 index 0000000000..a66bbbf8a3 --- /dev/null +++ b/challenge-005/gustavo-chaves/README @@ -0,0 +1 @@ +Solution by Gustavo Chaves diff --git a/challenge-005/jacques-guinnebault/README b/challenge-005/jacques-guinnebault/README new file mode 100644 index 0000000000..9d3e7c037f --- /dev/null +++ b/challenge-005/jacques-guinnebault/README @@ -0,0 +1 @@ +Solution by Jacques Guinnebault. diff --git a/challenge-005/jaime/README b/challenge-005/jaime/README new file mode 100644 index 0000000000..5b29651691 --- /dev/null +++ b/challenge-005/jaime/README @@ -0,0 +1 @@ +Solution by Jaime Corchado. diff --git a/challenge-005/jaldhar-h-vyas/README b/challenge-005/jaldhar-h-vyas/README new file mode 100644 index 0000000000..7dce927eca --- /dev/null +++ b/challenge-005/jaldhar-h-vyas/README @@ -0,0 +1 @@ +Solution by Jaldhar H. Vyas diff --git a/challenge-005/james-smith/README.md b/challenge-005/james-smith/README.md new file mode 100644 index 0000000000..f58242a0a0 --- /dev/null +++ b/challenge-005/james-smith/README.md @@ -0,0 +1,55 @@ +Solution by James Smith + +I'm new to Perl 6 so looking for interesting (not necessarily optimal +solutions) to try out some of the cool features that Perl 6 gives over +Perl 5 - especially as it is basically a new language with new syntactic +sugar.... + +# Problem 1 + +This is quirky same code between Perl 5 and Perl 6 produce different output - Perl 6 displays one more digit of Pi... so we need to extend the script by one byte (adding ";") to the end of the line... + +``` +perl -Mfeature=say perl5/ch-1.pl +perl6 perl6/ch-1.p6 +``` + +# Problem 2 + +## Perl 5 + +This is a nice problem - I solved this in Perl 5 in two ways - firstly with nested loops - but this requires a label (which is ugly code) to break out of the inner loop and get to the next word. The neater solution requires encapsulating the inner loop inside a function and calling that. Returning true if the word can be matched and false otherwise. + +The first part collects together the counts of the letters and the second loops through each of the words to see if there are sufficient letters. + +The loop is destructive of the counts array so we pass a copy into the function rather than the usual pass by reference.. This effectively clones the counts array so we don't have to do this explicitly + +For 2a see notes about perl 6 (this is non-destructive...) +``` +perl perl5/ch-2.pl back < /usr/share/dict/british-english-insane +perl perl5/ch-2a.pl back < /usr/share/dict/british-english-insane +``` + +## Perl 6 + +Because Perl 6 can't pass by value - I've rewritten this to be non-destructive (the checkword function counts up and compares to the main count)... need to check for performance.... + +The other change is split - you don't use the empty regex "//" to perform the split - rather the empty string (something frowned upon in Perl5) and to remove the rogue white-space split adds you need to include the additional flag `:skip-empty` + +I haven't golfed this one entirely - but have used "golf" techniques along the way to make the code in someways more readable using grep rather than if for instance! +``` +perl6 perl6/ch-2.p6 back < /usr/share/dict/british-english-insane +``` + +## Timings + +Yet again perl5 out performs perl 6 - perhaps I need to know how to optimize perl 6 code... + +``` + perl5 ch-2.pl 1.9 seconds + perl5 ch-2a.pl 1.3 seconds + perl6 ch-2.p6 27.1 seconds +``` + +This time by what looks like a factor of 20.... need a Perl 6 expert to suggest why.... + diff --git a/challenge-005/jeff/README b/challenge-005/jeff/README new file mode 100644 index 0000000000..d5f15f4a8e --- /dev/null +++ b/challenge-005/jeff/README @@ -0,0 +1 @@ +Solution by Jeff diff --git a/challenge-005/jeremy-carman/README b/challenge-005/jeremy-carman/README new file mode 100644 index 0000000000..3d08510e49 --- /dev/null +++ b/challenge-005/jeremy-carman/README @@ -0,0 +1 @@ +Solution by Jeremy Carman diff --git a/challenge-005/jim-bacon/README b/challenge-005/jim-bacon/README new file mode 100644 index 0000000000..8dcfd637a3 --- /dev/null +++ b/challenge-005/jim-bacon/README @@ -0,0 +1 @@ +Solution by Jim Bacon diff --git a/challenge-005/jj-merelo/README b/challenge-005/jj-merelo/README new file mode 100644 index 0000000000..d09838676b --- /dev/null +++ b/challenge-005/jj-merelo/README @@ -0,0 +1 @@ +Solution by JJ Merelo diff --git a/challenge-005/jo-christian-oterhals/README b/challenge-005/jo-christian-oterhals/README new file mode 100644 index 0000000000..eafff999fb --- /dev/null +++ b/challenge-005/jo-christian-oterhals/README @@ -0,0 +1 @@ +Solution by Jo Christian Oterhals diff --git a/challenge-005/joelle-maslak/README b/challenge-005/joelle-maslak/README new file mode 100644 index 0000000000..d12c7940c3 --- /dev/null +++ b/challenge-005/joelle-maslak/README @@ -0,0 +1 @@ +Solution by Joelle Maslak diff --git a/challenge-005/joelle-maslak/perl6/ch-1-readme b/challenge-005/joelle-maslak/perl6/ch-1-readme new file mode 100644 index 0000000000..d3f6e261ab --- /dev/null +++ b/challenge-005/joelle-maslak/perl6/ch-1-readme @@ -0,0 +1,2 @@ +The program, including line feeds, is 46 bytes long. +The output on Unix is 46 pi digits. diff --git a/challenge-005/john-barrett/README b/challenge-005/john-barrett/README new file mode 100644 index 0000000000..a7ff0af641 --- /dev/null +++ b/challenge-005/john-barrett/README @@ -0,0 +1 @@ +Solution by John Barrett diff --git a/challenge-005/john-barrett/perl5/README.md b/challenge-005/john-barrett/perl5/README.md new file mode 100644 index 0000000000..9a98597b12 --- /dev/null +++ b/challenge-005/john-barrett/perl5/README.md @@ -0,0 +1,8 @@ |
