diff --git a/src/clj/lingo.clj b/src/clj/lingo.clj new file mode 100644 index 0000000..47a452b --- /dev/null +++ b/src/clj/lingo.clj @@ -0,0 +1,43 @@ +(def words + (->> "resources/ospd3.txt" + slurp + clojure.string/split-lines)) + +(defn filter-word-count [n] + (set (filter (comp (partial = n) count) words))) + +(def fives (filter-word-count 5)) +(def sixes (filter-word-count 6)) + +(def lingo-five (group-by first fives)) + +(def lingo-five-count-by-first-letter + (mapv #(vector (key %) (count (val %))) lingo-five)) + +(reverse (sort-by second lingo-five-count-by-first-letter)) + +(def all-fives-frequencies (frequencies (apply str fives))) + +(reverse (sort-by val all-fives-frequencies)) + +(def fives-percentages + (reverse (sort-by last (mapv #(vector (key %) (val %) (float (/ (val %) (count (apply str fives))))) all-fives-frequencies)))) + +(def scoresheet + (apply hash-map (flatten (map (juxt first last) fives-percentages)))) + +(defn calc-score [word] + (->> word + (map char) + (map scoresheet) + (apply +) + (* 100) + Math/floor + int)) + +; highest scores +(take 20 (reverse (sort-by second (map (juxt identity calc-score) fives)))) + +; calculate highest score for each starting letter + +(group-by first (mapv (juxt first identity calc-score) fives)) diff --git a/src/clj/puzzle_2023-05-07.clj b/src/clj/puzzle_2023-05-07.clj new file mode 100644 index 0000000..cbcfb33 --- /dev/null +++ b/src/clj/puzzle_2023-05-07.clj @@ -0,0 +1,32 @@ +; https://www.npr.org/2023/05/07/1174544511/sunday-puzzle-seeing-double +; Think of part of the human body whose name is a compound word like +; fingertip or toenail. Add an N and rearrange the result to get another +; part of the body whose name is also a compound word. What body parts are these? + +(defn clean-up-word [word] + (clojure.string/replace (clojure.string/lower-case word) #"[^a-z]" "")) + +(def body-parts + (->> "resources/body_parts.txt" + slurp + clojure.string/split-lines + (mapv clean-up-word))) + +(defn subanagram? [base compare] + (let [base-frequencies + (merge + (zipmap "abcdefghijklmnopqrstuvwxyz" (repeat 26 0)) + (frequencies base)) + compare-frequencies + (frequencies compare)] + (every? #(<= (compare-frequencies %) + (base-frequencies %)) + (keys compare-frequencies)))) + +(def answer + (for [b body-parts + :let [f (filter (fn [x] (and (= (count x) (dec (count b))) + (subanagram? b x))) body-parts)] + :when (and (not (empty? f)))] + [b f])) + diff --git a/src/sh/puzzle_2023-04-30.sh b/src/sh/puzzle_2023-04-30.sh new file mode 100644 index 0000000..1bd53c3 --- /dev/null +++ b/src/sh/puzzle_2023-04-30.sh @@ -0,0 +1,5 @@ +https://www.npr.org/2023/04/30/1172903467/sunday-puzzle-palindrome-zone + +The "zh" sound can be spelled in many different ways in English — like the "s" in MEASURE; like the "g" in BEIGE; like the "z" in AZURE; like the "j" in MAHARAJAH; and like the "x" in LUXURY as some people pronounce it. The "zh" sound can also be spelled as a "t" in one instance. We know of only one common word this is true of, not counting its derivatives. What word is it? + +grep ' ZH ' cmudict-1.7b.txt | grep T | more