diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-05-04 08:14:47 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-05-04 08:14:47 +0100 |
| commit | 34d1deb7d3f6124520679c5a443ebc4782889d3c (patch) | |
| tree | 232f79d1e3c0488121e241d3d17f010c655c881f | |
| parent | c17f1c44792273109058997a9a6b2136fbeac791 (diff) | |
| download | perlweeklychallenge-club-34d1deb7d3f6124520679c5a443ebc4782889d3c.tar.gz perlweeklychallenge-club-34d1deb7d3f6124520679c5a443ebc4782889d3c.tar.bz2 perlweeklychallenge-club-34d1deb7d3f6124520679c5a443ebc4782889d3c.zip | |
pushing docs for 111
| -rw-r--r-- | challenge-111/james-smith/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-111/james-smith/perl/ch-2.pl | 35 |
2 files changed, 36 insertions, 14 deletions
diff --git a/challenge-111/james-smith/perl/ch-1.pl b/challenge-111/james-smith/perl/ch-1.pl index a0d65cc263..aae397ff35 100644 --- a/challenge-111/james-smith/perl/ch-1.pl +++ b/challenge-111/james-smith/perl/ch-1.pl @@ -43,6 +43,12 @@ sub find_val { ## If it matches we return 1 o/w we throw the middle value and ## the other half of the list - by using splice... + ## Note rather than dividing by 2 to get the mid point of the + ## list we instead use the bit shift operator ">>" this + ## also has the effect of taking the integer value of the + ## result so instead of having to do int(3/2) you can just + ## write 3>>1 to get the whole number (1) + $list[ $m = @list >> 1 ] == $val ? ( return 1 ) : $list[ $m ] > $val ? ( splice @list, $m ) : ( splice @list, 0, $m+1 ) @@ -58,3 +64,12 @@ sub find_val { ## list either at initially or after one of the splices... } +sub find_val_no_comments { + my( $val, $m, @list ) = ( $_[0], 0, map { @{$_} } @{$_[1]} ); + $list[ $m = @list >> 1 ] == $val ? ( return 1 ) + : $list[ $m ] > $val ? ( splice @list, $m ) + : ( splice @list, 0, $m+1 ) + while @list>1; + return @list && $list[0] == $val ? 1 : 0; +} + diff --git a/challenge-111/james-smith/perl/ch-2.pl b/challenge-111/james-smith/perl/ch-2.pl index ce10a7e856..b5d5b05780 100644 --- a/challenge-111/james-smith/perl/ch-2.pl +++ b/challenge-111/james-smith/perl/ch-2.pl @@ -5,14 +5,20 @@ use strict; use warnings; use feature qw(say); -## These are the dictionary's supplied by Ubuntu. +## Ubuntu supplies a number of different dictionaries +## I have installed all four of the english (UK) +## dictionaries that are available - a summary of the +## number of words is listed below. This does include +## a large number of real names and words containing +## hyphen's and apostrophies +## +## Name: # words # trimmed +## ------- ------- --------- +## small: 50,790 39,781 +## large: 166,828 113,695 +## huge: 344,861 245,593 +## insane: 654,299 427,891 ## -## Name: # words -## ------- ------- -## small: 50,790 -## large: 166,828 -## huge: 344,861 -## insane: 654,299 say longest( '/usr/share/dict/british-english-small' ); say longest( '/usr/share/dict/british-english-large' ); @@ -63,20 +69,21 @@ sub longest_no_comments { ## Two (billowy & beefily) are common in the "huge" list ## The other two 7 letter words are: ## -## chikors - An alternative spelling of chukars - A -## species of partridge native to central -## Asia (Alectoris chukar). +## chikors - An alternative spelling of chukars - A +## species of partridge native to central +## Asia (Alectoris chukar). ## -## dikkops - (From afrikaans) A bird of the family -## Burhinidae. The stone curlew, thick-knee -## Comes from dik-kop or thick head +## dikkops - (From afrikaans) A bird of the family +## Burhinidae. The stone curlew, thick-knee. +## Comes from dik-kop or thick head ## ## Finally the 8 letter word in the insane diction is: ## ## aegilops - a genus of Eurasian and North American ## plants in the grass family, Poaceae. -## They are known generally as goatgrasses. +## They are known generally as goat grasses. ## Some species are known as invasive weeds ## in parts of North America. +## |
