diff options
| author | Noud <noud.aldenhoven@gmail.com> | 2019-06-29 13:13:28 +0200 |
|---|---|---|
| committer | Noud <noud.aldenhoven@gmail.com> | 2019-06-29 13:13:28 +0200 |
| commit | 7e292031380ca16ef4a2f55c6303e29b76d16122 (patch) | |
| tree | 7ab5269f76a25bf2cdf7fef857373b05c2d6186f /challenge-014 | |
| parent | 2afb83c14948f6c18c7f6bd18116582d0541ffd8 (diff) | |
| download | perlweeklychallenge-club-7e292031380ca16ef4a2f55c6303e29b76d16122.tar.gz perlweeklychallenge-club-7e292031380ca16ef4a2f55c6303e29b76d16122.tar.bz2 perlweeklychallenge-club-7e292031380ca16ef4a2f55c6303e29b76d16122.zip | |
Solutions for ch-014 problem 1 and 2 by Noud
Diffstat (limited to 'challenge-014')
| -rw-r--r-- | challenge-014/noud/README | 1 | ||||
| -rw-r--r-- | challenge-014/noud/perl6/ch-1.p6 | 10 | ||||
| -rw-r--r-- | challenge-014/noud/perl6/ch-2.p6 | 35 |
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-014/noud/README b/challenge-014/noud/README new file mode 100644 index 0000000000..0b0970d708 --- /dev/null +++ b/challenge-014/noud/README @@ -0,0 +1 @@ +Solution by Noud diff --git a/challenge-014/noud/perl6/ch-1.p6 b/challenge-014/noud/perl6/ch-1.p6 new file mode 100644 index 0000000000..25d265afd0 --- /dev/null +++ b/challenge-014/noud/perl6/ch-1.p6 @@ -0,0 +1,10 @@ +# Challenge #1 + +# 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. + +my @van_eck = 0, {@_.reverse.grep(@_[*-1], :k)[1] || 0} ... *; + +# Print the first 100 numbers for the Van Eck series. +say @van_eck[^100]; diff --git a/challenge-014/noud/perl6/ch-2.p6 b/challenge-014/noud/perl6/ch-2.p6 new file mode 100644 index 0000000000..73aeb610f8 --- /dev/null +++ b/challenge-014/noud/perl6/ch-2.p6 @@ -0,0 +1,35 @@ +# 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. +# +# For example, +# Pennsylvania + Connecticut = PACT +# Wisconsin + North Dakota = WIND +# Maine + Alabama = MEAL +# California + Louisiana + Massachusetts + Rhode Island = Calamari + +my @usps = ('al', 'ak', 'az', 'ar', 'ca', 'co', 'ct', 'de', 'dc', 'fl', 'ga', + 'hi', 'id', 'il', 'in', 'ia', 'ks', 'ky', 'la', 'me', 'md', 'ma', 'mi', + 'mn', 'ms', 'mo', 'mt', 'ne', 'nv', 'nh', 'ny', 'nc', 'oh', 'ok', 'or', + 'pa', 'ri', 'sc', 'sd', 'tn', 'tx', 'ut', 'vt', 'va', 'wa', 'wv', 'wi', + 'wy'); + + +# Downloaded a bunch of English words from the internet. +my @words = 'words.txt'.IO.words; + +sub usps_word($s) { + # Returns True if argument can be constructed with USPS postal codes. + return ($s.encode.elems % 2 == 0) + && (($s.encode.elems == 0) + || (@usps.first($s.comb[^2].join) + && usps_word($s.comb[2..*].join)) + || False); +} + +# Print largest word that can be created with USPS postal codes. Depending on +# the list of search words, the largest word I could find is "cacogalactia". +say @words.grep({usps_word($_.lc)}).map({($_.encode.elems, $_)}).sort[*-1][1]; |
