public
Created

  • Download Gist
naive-search.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use v5.14;
use Sort::Key::Top 'nkeytopsort';
 
sub sort_letters {
my @letters = split '', $_[0];
join '', sort @letters;
}
 
sub can_make {
my ($letters, $word) = @_;
$word = join '.*', sort split '', $word;
$letters =~ qr{$word};
}
 
say "Reading words from dictionary...";
open my $dict, '<', '/usr/share/dict/words';
chomp( my @WORDS = map lc, grep length($_) <= 9, <$dict> );
 
say "Scoring microcombinations...";
my %SCORE; $SCORE{ sort_letters($_) }++ for @WORDS;
my @GOOD = nkeytopsort { $SCORE{$_} } -40 => keys %SCORE;
 
say "Generating candidate answers...";
my %CANDIDATES;
for my $x (@GOOD)
{
for my $y (@GOOD)
{
for my $z (@GOOD)
{
my $letters = sort_letters substr("$x$y$z", 0, 8);
$CANDIDATES{$letters}++;
}
}
}
my @VERYGOOD = nkeytopsort { $SCORE{$_} } -40 => keys %CANDIDATES;
 
say "Finding best candidate answer...";
my %RESULTS = map {
my $letters = $_;
my @can_make = grep can_make($letters, $_), @WORDS;
say " $letters - ", scalar(@can_make);
$letters => \@can_make;
} @VERYGOOD;
my ($BEST) = nkeytopsort { scalar @{$RESULTS{$_}} } -1 => @VERYGOOD;
 
say "BEST: $BEST";
say for sort @{$RESULTS{$BEST}};
output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
Reading words from dictionary...
Scoring microcombinations...
Generating candidate answers...
Finding best candidate answer...
aceeinrs - 195
'aeelnns - 100
aeeinrst - 285
aadeelnn - 92
aegimnrs - 320
eeeinrst - 144
adeeegnr - 134
aaceelst - 139
aopprsst - 152
eeiimnst - 118
aenoprst - 398
eilmopst - 268
aeimprst - 405
adelopst - 336
aeginprs - 315
aaepprst - 177
aeeilmst - 259
abdeelno - 192
adeeilmr - 236
aeoprsst - 313
aeelprss - 212
aceenrst - 275
aeoprrst - 274
adeeelrs - 150
eeeilmrs - 116
aefmorst - 296
adeimrst - 384
abdeerst - 275
abdeinrs - 361
adeelprs - 269
aeeimrst - 288
aceinost - 285
einoprst - 344
aaceenrs - 132
eginoprs - 255
aeeegrst - 151
eeiinnst - 74
eeeilrst - 129
aeinprst - 426
aeginrst - 378
BEST: aeinprst
a
a
air
airs
an
ani
anise
ant
ante
antes
anti
antis
ants
ape
apes
apr
apse
apt
apter
ar
are
ares
ares
aries
arise
arisen
art
art
artie
arts
as
as
asp
aspen
aspen
aspire
aster
astern
astir
at
at
ate
ats
e
e
ear
earn
earns
earp
ears
east
east
eat
eats
entrap
entraps
er
era
eras
erin
eris
erna
ernst
es
es
eta
etna
i
i
ian
in
in
ina
inapt
inept
inert
ines
ins
insert
inset
instep
inter
inters
ir
ira
iran
irate
ire
is
it
it
its
n
n
na
nair
nap
nape
napes
napier
naps
napster
nastier
nat
nate
ne
near
nears
neat
nest
net
nets
ni
nip
nips
nit
nita
nite
niter
nites
nits
np
p
p
pa
pa
pain
paine
pains
paint
painter
painters
paints
pair
pairs
pan
pan
pane
panes
panier
paniers
pans
pant
pantie
panties
pantries
pants
par
pare
parent
parents
pares
paris
pars
parse
parsi
part
parties
parts
pas
past
paste
pastern
pastier
pat
pat
pate
pate
pates
patine
pats
pea
pear
pears
peas
peat
pei
pen
pena
penis
pens
pent
per
persia
persian
pert
pertain
pertains
pest
pet
petra
pets
pi
pie
pier
piers
pies
pin
pine
pines
pins
pint
pinter
pints
pirate
pirates
pis
pisa
pit
pita
pits
praise
prate
prates
prensa
pres
pries
priest
print
prints
pt
r
r
ra
rae
rain
rains
raise
ran
rant
rants
rap
rape
rapes
rapine
rapist
raps
rapt
rasp
rat
rate
rates
rats
re
re
reap
reaps
rein
reins
reis
rena
rent
rents
rep
rep
repaint
repaints
repast
reps
resin
rest
retain
retains
retina
retinas
rinse
rip
ripe
ripen
ripens
ripest
rips
rise
risen
rita
rite
rites
rn
rs
rte
s
s
saint
san
sane
saner
sap
sap
sapient
sari
sat
sat
sate
satin
satire
se
sea
sean
sear
seat
sen
sent
sepia
sept
septa
sera
set
set
si
sian
sin
sine
sip
sir
sire
siren
sit
sitar
site
sn
snap
snare
snip
snipe
sniper
snit
spa
spain
span
spar
spare
spat
spate
spear
spent
spin
spine
spinet
spire
spirea
spit
spite
sprain
sprat
sprint
sprint
sprite
sprite
sr
st
stain
stair
stan
star
stare
stein
stein
step
stern
stern
sterna
stine
stir
strain
strap
strep
strip
stripe
t
t
ta
taine
tan
tans
tap
tape
taper
tapers
tapes
tapir
tapirs
taps
tar
tare
tares
tarp
tarps
tars
tea
tear
tears
teas
ten
tens
teri
tern
terns
ti
ti
tia
tie
tier
tiers
ties
tin
tina
tine
tines
tins
tip
tips
tire
tires
train
trains
traipse
tran
trap
traps
tries
trina
trip
tripe
trips
ts
tsar

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.