# Honeycomb Scramble

A cluster of 7 letters is formed by a center letter and the 6 letters surrounding it. Find clusters that match these clues when unscrambled:

1. flat cooking pan
2. wave gently
3. betrayal
4. spicy condiment
5. long-necked mammal
6. swirling windstorm
7. something permanently attached

## Solution

(ns word-solver.core
(:require [clojure.math.combinatorics :as c]
[clojure.string :as str]
[clojure.java.io :as io]))

;; Encode the board with this offset so that for a center cell [x, y]:
;;   1. the two characters _above_ the center cell are [x-1, y] and [x-1, y+1]
;;   2. the two characters _below_ the center cell are [x+1, y-1] and [x+1, y]
(def board
[[\0 \0 \0 \F \I \X \Y]
[\0 \0 \A \F \R \U \T]
[\0 \L \G \E \T \F \L]
[\D \E \D \O \R \E \J]
[\I \R \T \N \A \T \0]
[\M \A \D \O \S \0 \0]
[\S \U \M \L \0 \0 \0]])

(def dict (set (line-seq (io/reader "/usr/share/dict/words"))))

;; x = row, y = col
(->> [[(dec x) y]
[(dec x) (inc y)]
[x (inc y)]
[x (dec y)]
[(inc x) y]
[x y]
[(inc x) (dec y)]]
(map #(get-in board %))))

(defn words [letters]
(->> (vec (c/permutations letters))
(map (comp str/lower-case str/join))))

(defn match? [word]
(contains? dict word))

(defn run []
(-> (for [i (range 7)
j (range 7)]
(filter match? (words (adj board [i j]))))
flatten
set))

(run)

;; #{"senator" "odorant" "mustard" "glidder" "griddle" "treason" "dimer"
;;   "tornado" "seatron" "saum" "fluty" "maris" "fixture" "flutter"
;;   "readmit" "giraffe" "noreast" "durmast" "mould" "donator" "ergoted"
;;   "rosetan" "simar" "masu"}

Edit