You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Letter Boxed游戏求解器相邻字母同集合检测异常问题排查

Letter Boxed游戏求解器的相邻字母规则问题

问题背景

我正在开发纽约时报Letter Boxed游戏的求解器,游戏核心规则之一是:生成的单词中,相邻字母不能来自同一字母集合。

当前实现代码

我用以下代码实现该逻辑:

with open ("words_alpha.txt", "r") as initialWords:
  for line in initialWords:
    exclusive = True
    notAdjacent = True
    
    for a in alphabet:
      if a in line:
        exclusive = False
    
    selected = [char for char in line]
    for s in selected:
      if s in left and selected[selected.index(s) + 1] in left:
        notAdjacent = False
      if s in top and selected[selected.index(s) + 1] in top:
        notAdjacent = False
      if s in right and selected[selected.index(s) + 1] in right:
        notAdjacent = False
      if s in bottom and selected[selected.index(s) + 1] in bottom:
        notAdjacent = False

    if exclusive and notAdjacent and len(line) > 4:
      words.append(line.strip("\n"))

存在的问题

程序运气好时能通关,但有时会生成含相邻字母来自同一集合的单词,需要重新生成解决方案。

无效示例

输入内容:

Enter the words on the left: lum
Enter the words on the right: rac
Enter the words on the top: top
Enter the words on the bottom: ind
What is the target number of words? 5

输出的无效解决方案:

['lait', 'triturator', 'roman', 'nonman', 'nonproduction']

可见,单词triturator中存在相邻字母来自同一集合的情况,违反了游戏规则。

内容的提问来源于stack exchange,提问作者arastoof

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 07:52:38