Advertisement
Guest User

Untitled

a guest
May 25th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns doublets.solver
  2.   (:require [clojure.java.io :as io]
  3.             [clojure.edn :as edn]
  4.             [clojure.data.priority-map :refer :all]))
  5.  
  6. ;(def words (-> "words.edn"
  7.  ;              (io/resource)
  8.  ;              (slurp)
  9.  ;              (read-string)))
  10.  
  11. (def words [ "door"
  12.   "boor"
  13.   "cook"
  14.   "book"
  15.   "look"
  16.   "lock"])
  17.  
  18. (defn dist [word1 word2 & {:keys [n] :or {n 0}}]
  19.   (let [len1 (count word1)
  20.         len2 (count word2)]
  21.     (if (= 0 len1) n
  22.       (if (= 0 len2) n
  23.         (if (or (= 1 len1) (= 1 len2))
  24.           (if (= word1 word2)
  25.             n
  26.             (+ n 1))
  27.           (let [c1 (subs word1 0 1)
  28.                 c2 (subs word2 0 1)
  29.                 r1 (subs word1 1)
  30.                 r2 (subs word2 1)]
  31.             (if (= c1 c2)
  32.               (dist r1 r2 :n n)
  33.               (dist r1 r2 :n (+ n 1)))))))))
  34.  
  35.  
  36. (defn futureCost [goal]
  37.   (let [cand (filter #(= (count %) (count goal)) words)]
  38.   (priority-map (map #(dist % goal) cand))))
  39.  
  40.  
  41.  
  42. (defn doublets [word1 word2]
  43.     "do me"
  44.     )
  45.  
  46. (defn -main []
  47.  
  48.   (print (futureCost "lock") "\n"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement