Skip to content

Commit

Permalink
April / May 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
msszczep committed May 7, 2023
1 parent 46ca372 commit 00477bf
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/clj/lingo.clj
Original file line number Diff line number Diff line change
@@ -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))
32 changes: 32 additions & 0 deletions src/clj/puzzle_2023-05-07.clj
Original file line number Diff line number Diff line change
@@ -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]))

5 changes: 5 additions & 0 deletions src/sh/puzzle_2023-04-30.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 00477bf

Please sign in to comment.