Avatar of joebutler2

joebutler2's solution

to Pangram in the Clojure Track

Published at Jul 10 2020 · 0 comments
Instructions
Test suite
Solution

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

Source

Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

pangram_test.clj

(ns pangram-test
  (:require [clojure.test :refer [is deftest]]
            [pangram :refer [pangram?]]))

(deftest empty-sentence
  (is (false? (pangram? ""))))

(deftest lowercase-pangram
  (is (pangram? "the quick brown fox jumps over the lazy dog")))

(deftest missing-character-x
  (is
   (false?
    (pangram? "a quick movement of the enemy will jeopardize five gunboats"))))

(deftest another-missing-character-x
  (is
   (false?
    (pangram? "the quick brown fish jumps over the lazy dog"))))

(deftest with-underscores
  (is (pangram? "the_quick_brown_fox_jumps_over_the_lazy_dog")))

(deftest with-numbers
  (is (pangram? "the 1 quick brown fox jumps over the 2 lazy dogs")))

(deftest missing-letters-replaced-by-numbers
  (is
   (false?
    (pangram? "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))))

(deftest mixed-case-and-punctuation
  (is (pangram? "\"Five quacking Zephyrs jolt my wax bed.\"")))

(deftest upper-and-lower-not-counted-separately
  (is
   (false?
    (pangram? "the quick brown fox jumps over with lazy FX"))))
(ns pangram)

(def ^:const alphabet
  (into #{} (re-seq #"." "abcdefghijklmnopqrstuvwxyz")))


(defn pangram? [text]
  (= alphabet (->> text
                   clojure.string/lower-case
                   (re-seq #"[a-z]")
                   (reduce (fn [acc word] (conj acc word)) #{}))))

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?