SHARE
TWEET

Word solver

a guest Jul 19th, 2010 42 Never
  1. ;; clojure solver for given problem at
  2. ;; http://programmingpraxis.com/2010/07/13/word-cube
  3.  
  4. (ns cube
  5.   (:use [clojure.contrib.duck-streams :only (read-lines)])
  6.   (:use clojure.set))
  7.  
  8. (defn words-solver [string words-file]
  9.   ;; find middle character
  10.   (let [middle (get string 4)]
  11.     ;; do magic line by line
  12.     (doseq [line (read-lines words-file)]
  13.       (and
  14.         (< 3 (count line))
  15.         (not (empty? (filter #(= middle %) line)))
  16.         (empty? (difference (set line) (set string)))
  17.         (println line) ))
  18. ))
  19.  
  20. ;; usage
  21. (words-solver "ncbcioune" "words.txt")
RAW Paste Data
Top