Created
August 2, 2014 13:46
-
-
Save nathell/c8cf4108b0264911bd52 to your computer and use it in GitHub Desktop.
Solution of Polish Scrabble riddle at http://trzeciblank.wordpress.com/2014/07/31/zagadka-piecioliterowce/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns trzeciblank | |
(:require [clojure.string :as string] | |
[clojure.java.io :as io] | |
[clojure.set :refer :all])) | |
(def piatki (set (line-seq (io/reader "/home/nathell/scrabble/w5.txt")))) | |
(defn kandydaci [slowo] | |
(for [i (range 5) x "abcdefghijklmnoprstuwyząćęłńóśźż" | |
:let [kand (str (subs slowo 0 i) x (subs slowo (inc i)))] | |
:when (piatki kand)] | |
kand)) | |
(defn szukaj | |
([slowo] (szukaj #{slowo} #{})) | |
([slowa widziane] | |
(if (empty? slowa) | |
widziane | |
(let [slowo (first slowa) | |
reszta (disj slowa slowo) | |
widziane (conj widziane slowo) | |
nowe (difference (set (kandydaci slowo)) widziane)] | |
(recur (union nowe reszta) widziane))))) | |
(print (string/join " " (map string/upper-case (sort (difference piatki (szukaj "blank")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment