Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Word solver

By: a guest on Jul 19th, 2010  |  syntax: Lisp  |  size: 0.58 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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")