Write a program to generate a rectangular word-search of size 6x9. Words may go downwards, rightwards and diagonally (downwards and to the right), they may also overlap on the board.
The challenge is to include as many different English words as possible from https://www.ef.co.uk/english-resources/english-vocabulary/top-3000-words Your program may select desirable words itself to include. You score 1 point per word included.
For example:
For clarity I've used "." symbols below instead of random letters.
dolphin..
o.....o..
g.....u..
.....ono.
.........
.........
The above word-search contains {'do', 'dog', 'dolphin', 'hi', 'i', 'in', 'no', 'noun', 'on', and 'phi'} so from what is filled in so far scores 10 points.
In the unlikely event of a tie the shortest code size will be used to choose a winner.
-
\$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$DJMcMayhem– DJMcMayhem2018年11月24日 20:37:36 +00:00Commented Nov 24, 2018 at 20:37
-
\$\begingroup\$ Right, I hope those edits have covered everyones issues. Sorry if I missed anyone out. I'll put in a reopen request. \$\endgroup\$alan2here– alan2here2018年11月25日 11:51:44 +00:00Commented Nov 25, 2018 at 11:51
-
\$\begingroup\$ The ptoblem with this challenge is that answers will just consist of printing the optimal wordsearch itself, rather than a program finding the wordsearch. What I'd recommend instead is having the submission take input as a list of words and returning a wordsearch within reasonable time complexity. You could turn it into a test-battery question, where you have a series of test cases and see which submission produces the most compact wordsearchs. \$\endgroup\$Jo King– Jo King2018年11月26日 21:44:17 +00:00Commented Nov 26, 2018 at 21:44
-
\$\begingroup\$ @King Test batteries in this case being several specific subsets of words from the original word list? \$\endgroup\$alan2here– alan2here2018年11月28日 10:58:23 +00:00Commented Nov 28, 2018 at 10:58
-
\$\begingroup\$ Voting to reopen on the condition that you make it just one word search-- two is unnecessary. \$\endgroup\$lirtosiast– lirtosiast2018年12月01日 05:53:04 +00:00Commented Dec 1, 2018 at 5:53
2 Answers 2
Jelly, 20 bytes, score (削除) 53 (削除ここまで) 57
"¦/œḌ=ƥ~ẹμḲ5&Ċd@ṡ»ḲY
Wordsearch:
a d m i s s i o n
h o u s e h o l d
s o m e t h i n g
g e n e r a l l y
p o t e n t i a l
t h e r e f o r e
Words:
admission generally household potential something therefore
general mission
house stair there thing
ally gene here hill hold miss some tent thin
air all due era for hat her ill oil old one pot see set son ten the use
ad ah at do go he hi ie in me ms oh on or so to us
i
Previous
...the dictionary referenced in the question has changed since this was posted so this would drop to a score of 33.
Jelly, 23 bytes, score (削除) 150 154 158 (削除ここまで) 160
"RʂȥḄ0ḣq)÷yḊzIḥẊḥYx »ḲY
Used Python to search for boards; there are, no doubt, higher scores possible though.
The board:
donations
beverages
placement
performed
metallica
thousands
The words:
['a', 'ac', 'ace', 'ae', 'ag', 'age', 'ages', 'al', 'all', 'am', 'an', 'and', 'ar', 'art', 'as', 'at', 'ati', 'au', 'b', 'be', 'beverage', 'beverages', 'bp', 'c', 'ca', 'cd', 'ce', 'cement', 'cf', 'd', 'da', 'das', 'db', 'do', 'don', 'donation', 'donations', 'ds', 'e', 'ec', 'ed', 'ee', 'eh', 'el', 'em', 'en', 'ent', 'er', 'era', 'es', 'et', 'ev', 'eve', 'ever', 'f', 'fa', 'fo', 'for', 'form', 'formed', 'g', 'ge', 'gem', 'h', 'ho', 'i', 'ia', 'ic', 'in', 'io', 'ion', 'l', 'la', 'lace', 'le', 'lee', 'li', 'll', 'ls', 'm', 'me', 'med', 'men', 'ment', 'met', 'meta', 'metal', 'metallic', 'metallica', 'mi', 'min', 'mr', 'mt', 'n', 'na','nat', 'nation', 'nations', 'nd', 'ne', 'nec', 'ns', 'nt', 'nv', 'o', 'oe', 'og', 'ol', 'on', 'ons', 'or', 'ou', 'p', 'pe', 'per', 'perform', 'performed', 'pl', 'place', 'placement', 'pm', 'pp', 'ppm', 'r', 'ra', 'rage', 're', 'rf', 'rl', 'rm', 'rt', 's', 'sa', 'san', 'sand', 'ss', 'st', 'std', 't', 'ta', 'tall', 'td', 'th', 'thou', 'thousand', 'thousands', 'ti', 'tion', 'tions', 'to', 'tr', 'treo', 'u', 'us', 'usa', 'v', 'va', 'var', 've', 'ver']
The search
Note LIMIT_TO_N_BEST_NINES limits the search - lower numbers try fewer boards by never using the lower scoring rows (nine letter words) which will find "good" scores quicker, while higher numbers (up to 909 - the number of 9 letter words in the dictionary) will search more boards (and likely never complete!).
f = open(filePath, 'r')
ws = set(w.replace('\n', '').lower() for w in f.readlines())
def iterSubWords(w, ws):
for l in range(1,len(w)+1):
for s in range(len(w)-l+1):
if w[s:s+l] in ws: yield w[s:s+l]
nines = sorted([w for w in ws if len(w) == 9], key=lambda w:len(tuple(iterSubWords(w, ws))), reverse=1)
def diags(rows):
for rs in range(len(rows)):
yield ''.join(rows[rs + x][x] for x in range(min(len(rows) - rs, len(rows[0]))))
for cs in range(1, len(rows[0])):
yield ''.join(rows[x][cs + x] for x in range(min(len(rows[0]) - cs, len(rows))))
def diagWords(rows, validWords):
for d in diags(rows):
for sw in iterSubWords(d, validWords): yield sw
def allWordsOnBoard(rows, validWords):
r = set()
for row in list(rows) + [''.join(col) for col in zip(*rows)]:
for validWord in iterSubWords(row, validWords): r.add(validWord)
for validWord in diagWords(rows, validWords): r.add(validWord)
return r
from itertools import combinations, permutations
LIMIT_TO_N_BEST_NINES = 107
m = 0
for wl in combinations(nines[:LIMIT_TO_N_BEST_NINES], 6):
fws = allWordsOnBoard(wl, ws)
if len(fws) > m:
for p in permutations(wl):
fws = allWordsOnBoard(p, ws)
if len(fws) > m:
m = len(fws)
print(m, p)
-
\$\begingroup\$ Are all of your examples words? Some of them look like just plain letters of the alphabet ('m', 'n', 'l', etc...). Also, I don't think many of the two letter examples are words either ('aa', 'ht', 'nn', etc...). \$\endgroup\$ouflak– ouflak2018年11月23日 22:53:09 +00:00Commented Nov 23, 2018 at 22:53
-
\$\begingroup\$ I'm using the linked dictionary. \$\endgroup\$Jonathan Allan– Jonathan Allan2018年11月23日 22:55:54 +00:00Commented Nov 23, 2018 at 22:55
-
\$\begingroup\$ This challenge is off to a worrisome start. You're using 'words' from a list that contains many that aren't words in the English language. I'm strictly using English, but none of my words show up in that list! And these are the only two answers so far. \$\endgroup\$ouflak– ouflak2018年11月23日 23:03:33 +00:00Commented Nov 23, 2018 at 23:03
-
\$\begingroup\$ I am following the specification :( \$\endgroup\$Jonathan Allan– Jonathan Allan2018年11月23日 23:06:36 +00:00Commented Nov 23, 2018 at 23:06
-
\$\begingroup\$ Maybe the specification should be edited to remove the specific reference to English? That might make it better.... \$\endgroup\$ouflak– ouflak2018年11月23日 23:07:59 +00:00Commented Nov 23, 2018 at 23:07
Lua, 73 bytes - (削除) 49 (削除ここまで) (削除) 66 (削除ここまで) (削除) 74 (削除ここまで) 75 words
print("abraiders\nscrapings\nsheathers\ncarabiner\nbrahmanis\nrelapsers")
I got the words from another StackExchange question on the Puzzles site. Prints:
abraiders
scrapings
sheathers
carabiner
brahmanis
relapsers
So it's a minimum of eight words each row for 48 words, plus the indefinite article 'a' for 49 words horizontally. Edit: It seems there was an edit to the challenge and there now may be a limit to a list of very specific words and, unlike all of the words forming my list, not all of those words are actually even English. sigh Might just leave this here for posterity.
Edit Words formed horizontally:
i (pronoun 'I')
id
aid
aide
raid
aider
braid
aiders
raider
raiders
braiders
abraiders
la
lap
laps
lapse
elapse
relapse
relapser
relapsers
in
pin
rap
ping
crap
pings
aping
scrap
raping
craping
scraping
scrapings
at
he
eat
her
she
the
eath
heat
hers
heath
sheath
sheathe
sheather
sheathers
a
ab
rab
bin
car
arab
arabi
arabin
arabine
carabine
carabiner
is
ra
rah
man
bra
rahm
brahm
brahma
brahman
brahmani
brahmanis
Words formed vertically:
as
aha
are
ass
era
char
hare
-
\$\begingroup\$ Use the dictionary in the question, all single letters are words for example. \$\endgroup\$Jonathan Allan– Jonathan Allan2018年11月23日 21:19:30 +00:00Commented Nov 23, 2018 at 21:19
-
\$\begingroup\$ Formed my answer before that edit. Darn! \$\endgroup\$ouflak– ouflak2018年11月23日 21:20:48 +00:00Commented Nov 23, 2018 at 21:20
-
\$\begingroup\$ Are there any words vertically in this? \$\endgroup\$alan2here– alan2here2018年11月23日 21:49:40 +00:00Commented Nov 23, 2018 at 21:49
-
\$\begingroup\$ Yes, I've done some reshuffling and am slowly editing the word count to include those. I was going for a maximum along the 9 length row to have the most possible words right from the start. \$\endgroup\$ouflak– ouflak2018年11月23日 21:51:27 +00:00Commented Nov 23, 2018 at 21:51
-
\$\begingroup\$ I think I might need to edit my answer to show all of the possible words. \$\endgroup\$ouflak– ouflak2018年11月23日 21:52:00 +00:00Commented Nov 23, 2018 at 21:52