aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-014/aaron-sherman/META6.json21
-rw-r--r--challenge-014/aaron-sherman/README16
-rw-r--r--challenge-014/aaron-sherman/README.md23
-rwxr-xr-xchallenge-014/aaron-sherman/eck.p617
-rwxr-xr-xchallenge-014/aaron-sherman/us-words.p690
-rw-r--r--challenge-014/aaron-sherman/words1000
6 files changed, 1151 insertions, 16 deletions
diff --git a/challenge-014/aaron-sherman/META6.json b/challenge-014/aaron-sherman/META6.json
new file mode 100644
index 0000000000..18aa0e5da3
--- /dev/null
+++ b/challenge-014/aaron-sherman/META6.json
@@ -0,0 +1,21 @@
+{
+ "perl" : "6.c",
+ "name" : "Challenge014::AJS",
+ "api" : "1",
+ "auth" : "github:ajs",
+ "version" : "0.0.1",
+ "description" : "Solutions to this week's puzzles.",
+ "authors" : [ "Aaron Sherman" ],
+ "license" : "Artistic-2.0",
+ "provides" : { },
+ "depends" : [
+ "JSON::Tiny",
+ "WWW",
+ "Math::Sequences::Numberphile"
+ ],
+ "build-depends" : [ ],
+ "test-depends" : [ ],
+ "resources" : [ ],
+ "tags": [ ],
+ "source-url" : "git@github.com:manwar/perlweeklychallenge-club.git"
+}
diff --git a/challenge-014/aaron-sherman/README b/challenge-014/aaron-sherman/README
deleted file mode 100644
index 08d5ec39d2..0000000000
--- a/challenge-014/aaron-sherman/README
+++ /dev/null
@@ -1,16 +0,0 @@
-Solutions by Aaron Sherman.
-
-Challenge #1: The first Euclid non-prime
-
-This puzzle afforded me the opportunity to advertize a bit for the
-Math::Sequences module by showing how a new entry would be defined.
-
-It otherwise simply prints the solution number uninterestingly.
-
-Challenge #2: Common path prefixes
-
-I thought that this would be a good chance to show off Perl 6's
-user-defined operator features including the use of a user-defined
-operator in a reduction meta-operator.
-
-The use of the program is simple and can be shown using --help
diff --git a/challenge-014/aaron-sherman/README.md b/challenge-014/aaron-sherman/README.md
new file mode 100644
index 0000000000..03516ee2e1
--- /dev/null
+++ b/challenge-014/aaron-sherman/README.md
@@ -0,0 +1,23 @@
+# Solutions by Aaron Sherman.
+
+## Challenge #1: Van Eck’s sequence
+
+This week's first puzzle happens to be one that I just finished
+adding to [`Math::Sequences::Integer`](https://github.com/ajs/perl6-Math-Sequences)
+so my solution is an underwhelming reference to and plug for that
+module. [Here is the specific definition](https://github.com/ajs/perl6-Math-Sequences/blob/cb8d9f58092718f85debf68d2f183288741bdfad/lib/Math/Sequences/Numberphile.pm#L196).
+
+## Challenge #2: State Words
+
+My solution is pretty simple. It uses Perl 6's powerful regex engine
+to match the state abbreviations against a wordlist. A short example
+wordlist is provided, but it can also use a web version that is VERY
+large and then the solution takes much longer (feels like a performance
+bug to me).
+
+### Examples
+
+ $ ./us-words.p6
+ decade
+ $ ./us-words.p6 --verbose
+ Delaware + California + Delaware = decade
diff --git a/challenge-014/aaron-sherman/eck.p6 b/challenge-014/aaron-sherman/eck.p6
new file mode 100755
index 0000000000..f5c914c060
--- /dev/null
+++ b/challenge-014/aaron-sherman/eck.p6
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl6
+
+# Challenge #014.2
+#
+# Write a script to generate Van Eck’s sequence starts with 0. For more
+# information, please check out wikipedia page. This challenge was
+# proposed by team member Andrezgz.
+
+# This solution is somewhat cheeting, but since I just wrote this module
+# a few days ago (not knowing about the upcoming challenge) I won't feel
+# bad about it. ;-)
+
+use v6.c;
+
+use Math::Sequences::Numberphile;
+
+.say for @A181391;
diff --git a/challenge-014/aaron-sherman/us-words.p6 b/challenge-014/aaron-sherman/us-words.p6
new file mode 100755
index 0000000000..fdc5be91f9
--- /dev/null
+++ b/challenge-014/aaron-sherman/us-words.p6
@@ -0,0 +1,90 @@
+#!/usr/bin/env perl6
+
+# Challenge #2
+# Using only the official postal (2-letter) abbreviations for the 50 U.S.
+# states, write a script to find the longest English word you can spell?
+# Here is the list of U.S. states abbreviations as per wikipedia page.
+# This challenge was proposed by team member Neil Bowers.
+
+# My solution is really just the one line:
+# say @wordlist.grep(/:i^@states+$/).max(*.chars);
+
+use v6.c;
+
+use WWW;
+
+our $online-wordlist = 'https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt';
+our $local-wordlist = '/usr/share/dict/words';
+
+sub get-words(Bool :$web-words) {
+ sub get-local-words($path) {
+ $path.IO.e ?? $path.IO.lines>>.trim !! Nil
+ }
+ return get($online-wordlist).words if $web-words;
+ get-local-words($local-wordlist) // get-local-words('words') //
+ get($online-wordlist).words;
+}
+sub get-states-map() {
+ my @states = <
+ AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS
+ MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV
+ WI WY>;
+ my @others = <DC AS GU MP PR VI FM MH PW AA AE AP CM CZ NB PI TT>;
+ my @names =
+ "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
+ "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
+ "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
+ "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi",
+ "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
+ "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota",
+ "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
+ "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah",
+ "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin",
+ "Wyoming";
+ my @others-names =
+ "District of Columbia", "American Samoa", "Guam",
+ "Northern Mariana Islands", "Puerto Rico", "U.S. Virgin Islands",
+ "Micronesia", "Marshall Islands", "Palau",
+ "U.S. Armed Forces – Americas", "U.S. Armed Forces – Europe",
+ "U.S. Armed Forces – Pacific", "Northern Mariana Islands",
+ "Panama Canal Zone", "Nebraska", "Philippine Islands",
+ "Trust Territory of the Pacific Islands";
+ return {
+ states => Hash.new(@states Z @names),
+ others => Hash.new(@others Z @others-names),
+ };
+}
+
+proto MAIN(|) {*}
+multi MAIN(Bool :$test!) {
+ use Test;
+ my $states-map = get-states-map;
+ my @states = $states-map<states>.keys;
+ like 'code', /:i^@states+$/, "Pattern match a word";
+ is $states-map<states><CA>, 'California', 'CA lookup';
+}
+multi MAIN(
+ Bool :$territories, #= Include US Territories
+ Bool :$verbose, #= Verbose output
+ Bool :$web-words #= Force downloading large wordlist
+) {
+ my @wordlist = get-words(:$web-words).grep({.defined});
+ my $states-map = get-states-map;
+ my @states = $states-map<states>.keys;
+ if $territories {
+ @states.push($states-map<others>.keys);
+ }
+ @states .= sort;
+ my $answer = @wordlist.grep(/:i^@states+$/).max(*.chars);
+ if not $answer {
+ say "Could not find a match";
+ }
+ if $verbose {
+ my @parts = $answer ~~ m:g/(\w\w)/;
+ say "{@parts>>.map({
+ $states-map<states>{uc $_}//$states-map<others>{uc $_}
+ }).join(' + ')} = $answer";
+ } else {
+ say $answer;
+ }
+}
diff --git a/challenge-014/aaron-sherman/words b/challenge-014/aaron-sherman/words
new file mode 100644
index 0000000000..660e5f2c20
--- /dev/null
+++ b/challenge-014/aaron-sherman/words
@@ -0,0 +1,1000 @@
+a
+ability
+able
+about
+above
+accept
+according
+account
+across
+act
+action
+activity
+actually
+add
+address
+administration
+admit
+adult
+affect
+after
+again
+against
+age
+agency
+agent
+ago
+agree
+agreement
+ahead
+air
+all
+allow
+almost
+alone
+along
+already
+also
+although
+always
+American
+among
+amount
+analysis
+and
+animal
+another
+answer
+any
+anyone
+anything
+appear
+apply
+approach
+area
+argue
+arm
+around
+arrive
+art
+article
+artist
+as
+ask
+assume
+at
+attack
+attention
+attorney
+audience
+author
+authority
+available
+avoid
+away
+baby
+back
+bad
+bag
+ball
+bank
+bar
+base
+be
+beat
+beautiful
+because
+become
+bed
+before
+begin
+behavior
+behind
+believe
+benefit
+best
+better
+between
+beyond
+big
+bill
+billion
+bit
+black
+blood
+blue
+board
+body
+book
+born
+both
+box
+boy
+break
+bring
+brother
+budget
+build
+building
+business
+but
+buy
+by
+call
+camera
+campaign
+can
+cancer
+candidate
+capital
+car
+card
+care
+career
+carry
+case
+catch
+cause
+cell
+center
+central
+century
+certain
+certainly
+chair
+challenge
+chance
+change
+character
+charge
+check
+child
+choice
+choose
+church
+citizen
+city
+civil
+claim
+class
+clear
+clearly
+close
+coach
+cold
+collection
+college
+color
+come
+commercial
+common
+community
+company
+compare
+computer
+concern
+condition
+conference
+Congress
+consider
+consumer
+contain
+continue
+control
+cost
+could
+country
+couple
+course
+court
+cover
+create
+crime
+cultural
+culture
+cup
+current
+customer
+cut
+dark
+data
+daughter
+day
+dead
+deal
+death
+debate
+decade
+decide
+decision
+deep
+defense
+degree
+Democrat
+democratic
+describe
+design
+despite
+detail
+determine
+develop
+development
+die
+difference
+different
+difficult
+dinner
+direction
+director
+discover
+discuss
+discussion
+disease
+do
+doctor
+dog
+door
+down
+draw
+dream
+drive
+drop
+drug
+during
+each
+early
+east
+easy
+eat
+economic
+economy
+edge
+education
+effect
+effort
+eight
+either
+election
+else
+employee
+end
+energy
+enjoy
+enough
+enter
+entire
+environment
+environmental
+especially
+establish
+even
+evening
+event
+ever
+every
+everybody
+everyone
+everything
+evidence
+exactly
+example
+executive
+exist
+expect
+experience
+expert
+explain
+eye
+face
+fact
+factor
+fail
+fall
+family
+far
+fast
+father
+fear
+federal
+feel
+feeling
+few
+field
+fight
+figure
+fill
+film
+final
+finally
+financial
+find
+fine
+finger
+finish
+fire
+firm
+first
+fish
+five
+floor
+fly
+focus
+follow
+food
+foot
+for
+force
+foreign
+forget
+form
+former
+forward
+four
+free
+friend
+from
+front
+full
+fund
+future
+game
+garden
+gas
+general
+generation
+get
+girl
+give
+glass
+go
+goal
+good
+government
+great
+green
+ground
+group
+grow
+growth
+guess
+gun
+guy
+hair
+half
+hand
+hang
+happen
+happy
+hard
+have
+he
+head
+health
+hear
+heart
+heat
+heavy
+help
+her
+here
+herself
+high
+him
+himself
+his
+history
+hit
+hold
+home
+hope
+hospital
+hot
+hotel
+hour
+house
+how
+however
+huge
+human
+hundred
+husband
+I
+idea
+identify
+if
+image
+imagine
+impact
+important
+improve
+in
+include
+including
+increase
+indeed
+indicate
+individual
+industry
+information
+inside
+instead
+institution
+interest
+interesting
+international
+interview
+into
+investment
+involve
+issue
+it
+item
+its
+itself
+job
+join
+just
+keep
+key
+kid
+kill
+kind
+kitchen
+know
+knowledge
+land
+language
+large
+last
+late
+later
+laugh
+law
+lawyer
+lay
+lead
+leader
+learn
+least
+leave
+left
+leg
+legal
+less
+let
+letter
+level
+lie
+life
+light
+like
+likely
+line
+list
+listen
+little
+live
+local
+long
+look
+lose
+loss
+lot
+love
+low
+machine
+magazine
+main
+maintain
+major
+majority
+make
+man
+manage
+management
+manager
+many
+market
+marriage
+material
+matter
+may
+maybe
+me
+mean
+measure
+media
+medical
+meet
+meeting
+member
+memory
+mention
+message
+method
+middle
+might
+military
+million
+mind
+minute
+miss
+mission
+model
+modern
+moment
+money
+month
+more
+morning
+most
+mother
+mouth
+move
+movement
+movie
+Mr
+Mrs
+much
+music
+must
+my
+myself
+name
+nation
+national
+natural
+nature
+near
+nearly
+necessary
+need
+network
+never
+new
+news
+newspaper
+next
+nice
+night
+no
+none
+nor
+north
+not
+note
+nothing
+notice
+now
+n't
+number
+occur
+of
+off
+offer
+office
+officer
+official
+often
+oh
+oil
+ok
+old
+on
+once
+one
+only
+onto
+open
+operation
+opportunity
+option
+or
+order
+organization
+other
+others
+our
+out
+outside
+over
+own
+owner
+page
+pain
+painting
+paper
+parent
+part
+participant
+particular
+particularly
+partner
+party
+pass
+past
+patient
+pattern
+pay
+peace
+people
+per
+perform
+performance
+perhaps
+period
+person
+personal
+phone
+physical
+pick
+picture
+piece
+place
+plan
+plant
+play
+player
+PM
+point
+police
+policy
+political
+politics
+poor
+popular
+population
+position
+positive
+possible
+power
+practice
+prepare
+present
+president
+pressure
+pretty
+prevent
+price
+private
+probably
+problem
+process
+produce
+product
+production
+professional
+professor
+program
+project
+property
+protect
+prove
+provide
+public
+pull
+purpose
+push
+put
+quality
+question
+quickly
+quite
+race
+radio
+raise
+range
+rate
+rather
+reach
+read
+ready
+real
+reality
+realize
+really
+reason
+receive
+recent
+recently
+recognize
+record
+red
+reduce
+reflect
+region
+relate
+relationship
+religious
+remain
+remember
+remove
+report
+represent
+Republican
+require
+research
+resource
+respond
+response
+responsibility
+rest
+result
+return
+reveal
+rich
+right
+rise
+risk
+road
+rock
+role
+room
+rule
+run
+safe
+same
+save
+say
+scene
+school
+science
+scientist
+score
+sea
+season
+seat
+second
+section
+security
+see
+seek
+seem
+sell
+send
+senior
+sense
+series
+serious
+serve
+service
+set
+seven
+several
+sex
+sexual
+shake
+share
+she
+shoot
+short
+shot
+should
+shoulder
+show
+side
+sign
+significant
+similar
+simple
+simply
+since
+sing
+single
+sister
+sit
+site
+situation
+six
+size
+skill
+skin
+small
+smile
+so
+social
+society
+soldier
+some
+somebody
+someone
+something
+sometimes
+son
+song
+soon
+sort
+sound
+source
+south
+southern
+space
+speak
+special
+specific
+speech
+spend
+sport
+spring
+staff
+stage
+stand
+standard
+star
+start
+state
+statement
+station
+stay
+step
+still
+stock
+stop
+store
+story
+strategy
+street
+strong
+structure
+student
+study
+stuff
+style
+subject
+success
+successful
+such
+suddenly
+suffer
+suggest
+summer
+support
+sure
+surface
+system
+table
+take
+talk
+task
+tax
+teach
+teacher
+team
+technology
+television
+tell
+ten
+tend
+term
+test
+than
+thank
+that
+the
+their
+them
+themselves
+then
+theory
+there
+these
+they
+thing
+think
+third
+this
+those
+though
+thought
+thousand
+threat
+three
+through
+throughout
+throw
+thus
+time
+to
+today
+together
+tonight
+too
+top
+total
+tough
+toward
+town
+trade
+traditional
+training
+travel
+treat
+treatment
+tree
+trial
+trip
+trouble
+true
+truth
+try
+turn
+TV
+two
+type
+under
+understand
+unit
+until
+up
+upon
+us
+use
+usually
+value
+various
+very
+victim
+view
+violence
+visit
+voice
+vote
+wait
+walk
+wall
+want
+war
+watch
+water
+way
+we
+weapon
+wear
+week
+weight
+well
+west
+western
+what
+whatever
+when
+where
+whether
+which
+while
+white
+who
+whole
+whom
+whose
+why
+wide
+wife
+will
+win
+wind
+window
+wish
+with
+within
+without
+woman
+wonder
+word
+work
+worker
+world
+worry
+would
+write
+writer
+wrong
+yard
+yeah
+year
+yes
+yet
+you
+young
+your
+yourself