2017年5月7日日曜日

開発環境

Think Perl 6: How to Think Like a Computer Scientist (Laurent Rosenfeld(著)、Allen B. Downey(著)、Oreilly & Associates Inc)のPart 1(Starting with the basics)、Chapter 8(Case Study: Word Play)の Exercise 8-1、8-2、8-3、8-4、8-5、8-6.を取り組んでみる。

Exercise 8-1、8-2、8-3、8-4、8-5、8-6.

コード(Emacs)

#!/usr/bin/env perl6
# -*- coding: utf-8 -*-

say '1.';

for 'words.txt'.IO.lines {
    say $_ if $_.chars > 20;
}

say '2.';

sub has-no-e($word) {
    not $word.index('e').defined;
}

my $count = 0;
my $count0 = 0;
for 'words.txt'.IO.lines {
    if has-no-e($_) {
        # say $_;
        $count0++;
    }
    $count++;
}

say $count0 / $count * 100, '%';

say '3.';

sub avoids($word, $letters) {
    # my $letters = prompt 'enter a string of forbidden letters: ';
    for $letters.comb {
        return False if $word.index($_).defined;
    }
    True;
}

my $letters = 'ae';
for 'words.txt'.IO.lines -> $line {
    my $count0 = 0;
    unless avoids($line, $letters) {
        $count0++;
    }
    $count = $count0;
}
for 'a'..'w' -> $letter1 {
    for ($letter1.ord + 1).chr..'z' -> $letter2 {
        my $letters0 = "$letter1$letter2";
        my $count0 = 0;                    
        for 'words.txt'.IO.lines -> $line {
            unless avoids($line, $letters0) {
                $count0++;
                last if $count0 >= $count;
            }
        }
        if $count0 < $count {
            $letters = $letters0;
            $count = $count0;
        }
    }
}

say $letters;

say '4.';
sub uses-only($word, $letters) {
    for $word.comb {
        return False unless $letters.index($_).defined;
    }
    True;
}

for 'words.txt'.IO.lines {
    say $_ if uses-only($_, 'acefhlo');
}

say '5.';
sub uses-all($word, $letters) {
    for $letters.comb {
        return False unless $word.index($_).defined;
    }
    True;
}

say 'aeiou';
for 'words.txt'.IO.lines {
    say $_ if uses-all($_, 'aeiou');
}
say 'aeiouy';
for 'words.txt'.IO.lines {
    say $_ if uses-all($_, 'aeiouy');
}

say '6.';
sub is_abcedarian($word) {
    for 1..$word.chars - 1 {
        return False unless $word.substr($_ - 1, 1) le $word.substr($_, 1);
    }
    True;
}
$count = 0;
for 'words.txt'.IO.lines {
    $count++ if is_abcedarian($_);
}
say $count;

入出力結果(Terminal, REPL)

$ ./sample1.pl
1.
counterdemonstrations
hyperaggressivenesses
microminiaturizations
2.
33.0738342%
3.
ae
4.
aa
aah
aal
ace
ache
achoo
ae
aff
ah
aha
ahchoo
ala
alae
alcohol
ale
alec
alee
alef
alfa
alfalfa
all
allele
allheal
aloe
aloha
aloof
cacao
cache
caeca
caecal
cafe
caleche
calf
call
calla
ceca
cecal
cee
cell
cella
cellae
cello
chafe
chaff
chalah
chaleh
challah
chef
chela
chelae
cholla
clach
clef
cloaca
cloacae
cloacal
cloche
coach
coal
coala
coalhole
coca
coccal
cochlea
cochleae
coco
cocoa
coff
coffee
coffle
coho
col
cola
cole
coo
cooch
cooee
coof
cool
each
eche
echo
ecole
eel
ef
eff
efface
eh
el
elf
ell
fa
face
faecal
fall
fallal
falloff
feal
fecal
fee
feel
fell
fella
fellah
felloe
feoff
feoffee
flea
fleche
flee
fleece
fleech
floc
floe
foal
focal
foe
foh
fool
ha
haaf
hae
hah
halala
halalah
hale
half
hall
hallah
hallel
hallo
halloa
halloo
halo
haole
he
heal
heel
hell
hellhole
hello
ho
hoe
hole
holla
hollo
holloa
holloo
hooch
hoof
la
lac
lace
lall
lea
leach
leaf
leal
lech
lee
leech
lo
loach
loaf
loca
local
locale
loch
loco
locofoco
loll
loo
loof
loofa
loofah
oaf
oca
oe
of
off
offal
oh
oho
ole
olea
oleo
olla
ooh
5.
aeiou
aboideau
aboideaus
aboideaux
aboiteau
aboiteaus
aboiteaux
abstemious
abstemiously
accentuation
accentuations
accountabilities
accountancies
accoutering
adulteration
adulterations
adventitious
adventitiously
adventitiousness
adventitiousnesses
aerobium
aeronautic
aeronautical
aeronautically
aeronautics
agouties
ambidextrous
ambidextrously
antibourgeois
anticonsumer
antievolution
antievolutionary
antihomosexual
antireligious
antirevolutionary
antisubversion
antituberculosis
antiunemployment
armouries
arsenious
assiduousness
assiduousnesses
atrociousness
atrociousnesses
attenuation
attenuations
auctioned
auctioneer
auctioneers
auditioned
auditories
augmentation
augmentations
aureoling
authentication
authentications
authoritative
authoritatively
authorities
authorize
authorized
authorizes
autobiographer
autobiographers
autobiographies
autocracies
autogamies
autogenies
automobile
automobiles
automotive
autonomies
autopsied
autopsies
autotomies
autotypies
avoidupoises
beautification
beautifications
belabouring
bivouacked
boundaries
buoyancies
businesswoman
calamitousness
calamitousnesses
carnivorousness
carnivorousnesses
cauliflower
cauliflowers
cauterization
cauterizations
cautioned
cautiousness
cautiousnesses
chemotherapeutic
chemotherapeutical
chivalrousness
chivalrousnesses
coeducation
coeducational
coeducations
coequating
communicable
communicate
communicated
communicates
communicative
conceptualize
conceptualized
conceptualizes
conceptualizing
consequential
constabularies
continuance
continuances
contumacies
copulative
copulatives
countenancing
counteraccusation
counteraccusations
counteracting
counteraggression
counteraggressions
counterarguing
counterattacking
counterbalancing
countercampaign
countercampaigns
counterclaim
counterclaims
countercomplaint
countercomplaints
counterdemonstration
counterdemonstrations
counterguerrila
counterinflationary
countermanding
counterpropagation
counterpropagations
counterraid
counterraids
counterrallies
counterretaliation
counterretaliations
counterstrategies
demagogueries
denunciation
denunciations
deputation
deputations
desquamation
desquamations
devaluation
devaluations
dialogue
dialogued
dialogues
disadvantageous
discontinuance
discontinuances
discourage
discouraged
discouragement
discouragements
discourages
documentaries
documentation
documentations
edacious
education
educational
educations
efficacious
ejaculation
ejaculations
elucidation
elucidations
emasculatation
emasculatations
emulation
emulations
emulsification
emulsifications
enamouring
encouraging
enumeration
enumerations
enunciation
enunciations
equation
equations
equatorial
equivocal
equivocate
equivocated
equivocates
equivocating
equivocation
equivocations
eulogia
eulogiae
eulogias
euphoria
euphorias
evacuation
evacuations
evaluation
evaluations
evolutionary
excommunicate
excommunicated
excommunicates
excommunicating
excommunication
excommunications
exhaustion
exhaustions
exhumation
exhumations
expurgation
expurgations
extenuation
extenuations
extracommunity
extraconstitutional
exudation
exudations
facetious
facetiously
fastiduousness
fastiduousnesses
filamentous
fluoridate
fluoridated
fluoridates
fountained
fumatories
functionaries
gelatinous
genitourinary
graciousness
graciousnesses
gregarious
gregariously
gregariousness
gregariousnesses
gubernatorial
hallucinogen
hallucinogenic
hallucinogens
harmoniousness
harmoniousnesses
hippopotamuses
housecleaning
housecleanings
housemaid
housemaids
housewarming
housewarmings
hyperanxious
hypercautious
hyperfastidious
ignoramuses
importunate
incommensurate
incommunicable
inconsequential
inconsequentially
inconsumable
inoculate
inoculated
inoculates
insecuration
insecurations
insouciance
insouciances
instantaneous
instantaneously
institutionalize
instrumentation
instrumentations
insubordinate
insupportable
insurmounable
intercommunal
interinstitutional
intermolecular
intermountain
interpopulation
intravenous
intravenously
jalousie
jalousies
jealousies
lasciviousness
lasciviousnesses
leukopenia
liquefaction
liquefactions
loquacities
magnanimousness
magnanimousnesses
malfunctioned
malnourished
mendacious
mendaciously
menstruation
menstruations
miaoued
microminiature
microminiatures
microminiaturized
miscellaneous
miscellaneously
miscellaneousness
miscellaneousnesses
modularities
modularized
mortuaries
mountaineer
mountaineered
mountaineering
mountaineers
multidenominational
multidimensional
multidirectional
multimillionaire
multimodalities
nefarious
nefariouses
nefariously
neurological
neurologically
neuropathies
neurotically
neutralization
neutralizations
nitrosurea
noncommunicable
noncumulative
noneducational
nonindustrialized
nonintellectual
obduracies
obituaries
occupancies
ossuaries
ostentatious
ostentatiously
outbeaming
outbleating
outcapering
outcaviled
outcavilled
outcheating
outdistance
outdistanced
outdistances
outdreaming
outeating
outfeasting
outgained
outhearing
outlawries
outleaping
outlearning
outpainted
outpatient
outpatients
outraise
outraised
outraises
outreaching
outreading
outrivaled
outrivalled
outsailed
outspeaking
outswearing
outwaited
outwearied
outwearies
outwearing
outwearying
overambitious
overanxious
overarousing
overcautious
overeducating
overenthusiastic
overexhausting
overfatigue
overfatigued
overfatigues
overfatiguing
overhauling
overparticular
overqualified
overregulating
overregulation
overregulations
oversaturating
overstimulate
overstimulated
overstimulates
overstimulating
overvaluing
pandemonium
pandemoniums
pasteurization
pasteurizations
peculatation
peculatations
perambulation
perambulations
perpetuation
perpetuations
perspicacious
persuasion
persuasions
pertinacious
perturbation
perturbations
plutocracies
pneumonia
popularities
popularize
popularized
popularizes
portraiture
portraitures
postrevolutionary
preauthorize
preauthorized
preauthorizes
preauthorizing
precarious
precariously
precariousness
precariousnesses
precaution
precautionary
precautions
preimmunization
preimmunizations
preinoculate
preinoculated
preinoculates
preinoculating
preinoculation
preoccupation
preoccupations
prepublication
prerevolutionary
pressurization
pressurizations
proteinuria
purgatories
putrefaction
putrefactions
questionable
questionnaire
questionnaires
questionniare
questionniares
radionuclide
radionuclides
rapaciousness
rapaciousnesses
rearousing
recapitulation
recapitulations
recirculation
recirculations
recuperation
recuperations
reevaluation
reevaluations
reformulating
refutation
refutations
regulation
regulations
regurgitation
regurgitations
reinoculate
reinoculated
reinoculates
reinoculating
rejuvenation
rejuvenations
remuneration
remunerations
renunciation
renunciations
repopulating
repudiation
repudiations
repudiator
repudiators
reputation
reputations
resuscitation
resuscitations
resuscitator
resuscitators
revolutionaries
revolutionary
sacrilegious
sacrilegiously
sautoire
sautoires
savourier
savouries
savouriest
scabiouses
sequoia
sequoias
simultaneous
simultaneously
simultaneousness
simultaneousnesses
somersaulting
spaciousness
spaciousnesses
speculation
speculations
stupefaction
stupefactions
subatmospheric
subcategories
subequatorial
suboceanic
subordinate
subordinated
subordinates
subpoenaing
sudatories
superambitious
superpatriot
superpatriotic
superpatriotism
superpatriotisms
superpatriots
tambourine
tambourines
tenacious
tenaciously
thiourea
thioureas
ulceration
ulcerations
ultraviolet
unaccompanied
unauthorized
unavoidable
uncomplimentary
unconscionable
unconventional
unconventionally
uncooperative
uncoordinated
undemocratic
undomesticated
unemotional
unequivocal
unequivocally
unforgivable
unidirectional
unintentional
unintentionally
unmotivated
unnojectionable
unnoticeable
unobtainable
unorganized
unpopularities
unprofessional
unprofitable
unquestionable
unquestionably
unreasoning
unsophisticated
veracious
vexatious
vicariousness
vicariousnesses
villianousness
villianousnesses
vituperation
vituperations
vivaciousness
vivaciousnesses
vocabularies
voraciousness
voraciousnesses
warehousing
aeiouy
abstemiously
adventitiously
aeronautically
ambidextrously
antievolutionary
antirevolutionary
antiunemployment
authoritatively
autotypies
buoyancies
counterinflationary
evolutionary
extracommunity
facetiously
genitourinary
gregariously
hyperanxious
hypercautious
hyperfastidious
inconsequentially
instantaneously
intravenously
mendaciously
miscellaneously
nefariously
neurologically
neurotically
ostentatiously
outwearying
postrevolutionary
precariously
precautionary
prerevolutionary
revolutionary
sacrilegiously
simultaneously
tenaciously
uncomplimentary
unconventionally
unequivocally
unintentionally
unquestionably
6.
596
$

0 コメント:

コメントを投稿

Comments on Google+: