15
\$\begingroup\$

Given a list of case-insensitive ASCII letter strings ("words"), output whether the entire list can be found on some four-by-four configuration ("board") of letter squares, in which no square can be used more than once in a word, and in which words are formed by moving from any square to any adjacent square including diagonally.

You do not need to worry that the combination of squares that would allow for the list actually appears in a Boggle game. The words need not be actual words in any language. You should assume that if Q appears on the board, it's on a square of its own (unlike in actual Boggle).

Standard loopholes are banned, standard I/O rules apply, and you're golfing.


In the examples below, a slash signifies a newline.

Truthy examples

  • auuuuooiiaaoiee, euiaaiueeuua, ooouuueee, eueueuoaoa — All are on the board auii/euoa/ueoa/euio
  • swiop, byteba, ceropl, qoiz, aeis, lqoep — All are on the board abcb/rety/poiw/lqzs

Falsy examples

  • swiop, byteba, ceropl, qoiz, aeis, lqoep, wybez — There are fifteen distinct letters (abceilopqrstwyz) and a single word has two bs, so that's the sixteenth square. Thus there's only one e. But the e has nine distinct letters (abcioprtz) adjacent to it, which is impossible.
  • hskcbnzvgfa, lajdnzvfhgs, kajfbmxvshd, ldgckvbsanx — There are sixteen distinct letters (abcdfghjklmnsvxz). Of those, s is adjacent to all of abghkv, v is adjacent to all of bfgksxz, b is adjacent to all of cfmnsv, a is adjacent to all of fjklns, and f is adjacent to all of abghjv. But on an actual board only four squares are adjacent to more than five squares apiece.
\$\endgroup\$
10
  • 6
    \$\begingroup\$ I can understand the challenge clearly and unambiguously. If anyone disagree (and VTC as unclear), consider leaving a comment. \$\endgroup\$
    – DELETE_ME
    Apr 29, 2018 at 2:02
  • 2
    \$\begingroup\$ I wonder if it would be better suited for fastest-code or fastest-algorithm. As code-golf, it may lead to brute-force solutions that run forever and never actually return anything. \$\endgroup\$
    – Arnauld
    Apr 29, 2018 at 10:30
  • 1
    \$\begingroup\$ @Arnauld, I don't like fastest-code challenges, personally, and don't know enough compsci to understand or judge fastest-algorithm challenges. That said, I'm considering making a note in the challenge that no brute-force answer will get the checkmark, even if it's shortest in its language. \$\endgroup\$
    – msh210
    Apr 29, 2018 at 11:25
  • 4
    \$\begingroup\$ Besides that, I too think that the challenge is clearly defined. So, people that have VTC really should share their thoughts. \$\endgroup\$
    – Arnauld
    Apr 29, 2018 at 11:42
  • 4
    \$\begingroup\$ As far as I can see, in general this is a subgraph problem, which is NP complete, so all non-magical answers will need some degree of brute force. \$\endgroup\$
    – Phil H
    May 1, 2018 at 11:32

1 Answer 1

1
\$\begingroup\$

Python 3, 215 bytes

def f(w):b=product(*[set("".join(w))]*16);return any(all(any(all(x-y in[1,-1,4,-4]for x,y in zip(q,q[1:]))for q in product(*[[x for x in range(16)if k[x]==c]for c in a]))for a in w)for k in b)
from itertools import*

Try it online!

This is never going to finish, so I can't really debug it or prove it works. I will try to find constant optimizations / test with reduced test cases, but if you spot a reason it would definitely fail, I will take it down / fix it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.