🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of quigonjeff

quigonjeff's solution

to Pangram in the Emacs Lisp Track

Published at Jun 27 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.el

;;; pagram-test.el --- Tests for Pangram (exercism)

;;; Commentary:
;; Common test data version: 1.3.0 d79e13e

;;; Code:

(load-file "pangram.el")

(ert-deftest sentence-empty ()
  (should (equal nil (is-pangram ""))))

(ert-deftest recognizes-a-perfect-lower-case-pangram ()
  (should (equal t (is-pangram "abcdefghijklmnopqrstuvwxyz"))))

(ert-deftest  pangram-with-only-lower-case ()
  (should (equal t (is-pangram "the quick brown fox jumps over the lazy dog"))))

(ert-deftest missing-character-x ()
  (should (equal nil (is-pangram "a quick movement of the enemy will jeopardize five gunboats"))))

(ert-deftest missing-another-character-eg-h ()
  (should (equal nil (is-pangram "five boxing wizards jump quickly at it"))))

(ert-deftest  pangram-with-underscores ()
  (should (equal t (is-pangram "the_quick_brown_fox_jumps_over_the_lazy_dog"))))

(ert-deftest  pangram-with-numbers ()
  (should (equal t (is-pangram "the 1 quick brown fox jumps over the 2 lazy dogs"))))

(ert-deftest  missing-letters-replaced-by-numbers ()
  (should (equal nil (is-pangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))))

(ert-deftest  pangram-with-mixed-case-and-punctuation ()
  (should (equal t (is-pangram "\"Five quacking Zephyrs jolt my wax bed.\""))))

(ert-deftest  upper-and-lower-case-versions-of-the-same-character-should-not-be-counted-separately ()
  (should (equal nil (is-pangram "the quick brown fox jumps over with lazy FX"))))

(provide 'pangram-test)
;;; pagram-test.el ends here
;;; pangram.el --- Pangram (exercism)

;;; Commentary:

;;; Code:
(defun vector-forall (v &optional ini fin)
  (unless ini (setq ini 0))
  (unless fin (setq fin (length v)))
  (cond
   ((>= ini fin) t)
   ((null (elt v ini)) nil)
   (t (vector-forall v (1+ ini) fin))))

(defun is-pangram (sentence)
  (let* ((s1 (downcase sentence))
         (l1 (split-string s1 "[^a-z]"))
         (s2 (apply #'concat l1))
         (l2 (string-to-list s2))
         (v1 (make-vector 26 nil)))
    (dolist (c l2) (aset v1 (- c ?a) t))
    (vector-forall v1)))

(provide 'pangram)
;;; pangram.el ends here

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?