diff --git a/common-lisp/README.md b/common-lisp/README.md index 63735e3f..f6d03a68 100644 --- a/common-lisp/README.md +++ b/common-lisp/README.md @@ -365,3 +365,4 @@ Bye. - [difference-of-squares](./difference-of-squares/README.md) - [robot-name](./robot-name/README.md) - [matching-brackets](./matching-brackets/README.md) +- [pangram](./pangram/README.md) diff --git a/common-lisp/pangram/README.md b/common-lisp/pangram/README.md index 4d053f66..7b558169 100644 --- a/common-lisp/pangram/README.md +++ b/common-lisp/pangram/README.md @@ -37,4 +37,9 @@ For this exercise, a sentence is a pangram if it contains each of the 26 letters ### Based on -Wikipedia - https://en.wikipedia.org/wiki/Pangram \ No newline at end of file +Wikipedia - https://en.wikipedia.org/wiki/Pangram +### My Solution + +- [my solution](./pangram.lisp) +- [run-tests script](./run-tests.lisp) +- [run-tests output](./run-tests-lisp.txt) diff --git a/common-lisp/pangram/pangram-test.lisp b/common-lisp/pangram/pangram-test.lisp index af174823..3aa7e9a8 100644 --- a/common-lisp/pangram/pangram-test.lisp +++ b/common-lisp/pangram/pangram-test.lisp @@ -16,48 +16,48 @@ (def-suite* pangram-suite) (test empty-sentence - (let ((sentence "")) - (is-false (pangram:pangramp sentence)))) + (let ((sentence "")) + (is-false (pangram:pangramp sentence)))) (test perfect-lower-case - (let ((sentence "abcdefghijklmnopqrstuvwxyz")) - (is-true (pangram:pangramp sentence)))) + (let ((sentence "abcdefghijklmnopqrstuvwxyz")) + (is-true (pangram:pangramp sentence)))) (test only-lower-case - (let ((sentence "the quick brown fox jumps over the lazy dog")) - (is-true (pangram:pangramp sentence)))) + (let ((sentence "the quick brown fox jumps over the lazy dog")) + (is-true (pangram:pangramp sentence)))) (test missing-the-letter-x - (let ((sentence "a quick movement of the enemy will jeopardize five gunboats")) - (is-false (pangram:pangramp sentence)))) + (let ((sentence "a quick movement of the enemy will jeopardize five gunboats")) + (is-false (pangram:pangramp sentence)))) (test missing-the-letter-h - (let ((sentence "five boxing wizards jump quickly at it")) - (is-false (pangram:pangramp sentence)))) + (let ((sentence "five boxing wizards jump quickly at it")) + (is-false (pangram:pangramp sentence)))) (test with-underscores - (let ((sentence "the_quick_brown_fox_jumps_over_the_lazy_dog")) - (is-true (pangram:pangramp sentence)))) + (let ((sentence "the_quick_brown_fox_jumps_over_the_lazy_dog")) + (is-true (pangram:pangramp sentence)))) (test with-numbers - (let ((sentence "the 1 quick brown fox jumps over the 2 lazy dogs")) - (is-true (pangram:pangramp sentence)))) + (let ((sentence "the 1 quick brown fox jumps over the 2 lazy dogs")) + (is-true (pangram:pangramp sentence)))) (test missing-letters-replaced-by-numbers - (let ((sentence "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")) - (is-false (pangram:pangramp sentence)))) + (let ((sentence "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")) + (is-false (pangram:pangramp sentence)))) (test mixed-case-and-punctuation - (let ((sentence "\"Five quacking Zephyrs jolt my wax bed.\"")) - (is-true (pangram:pangramp sentence)))) + (let ((sentence "\"Five quacking Zephyrs jolt my wax bed.\"")) + (is-true (pangram:pangramp sentence)))) (test case-insensitive - (let ((sentence "the quick brown fox jumps over with lazy FX")) - (is-false (pangram:pangramp sentence)))) + (let ((sentence "the quick brown fox jumps over with lazy FX")) + (is-false (pangram:pangramp sentence)))) (test a-m-and-a-m-are-26-different-characters-but-not-a-pangram - (let ((sentence "abcdefghijklm ABCDEFGHIJKLM")) - (is-false (pangram:pangramp sentence)))) + (let ((sentence "abcdefghijklm ABCDEFGHIJKLM")) + (is-false (pangram:pangramp sentence)))) (defun run-tests (&optional (test-or-suite 'pangram-suite)) "Provides human readable results of test run. Default to entire suite." diff --git a/common-lisp/pangram/pangram.lisp b/common-lisp/pangram/pangram.lisp index 0ce78de2..77c64205 100644 --- a/common-lisp/pangram/pangram.lisp +++ b/common-lisp/pangram/pangram.lisp @@ -4,4 +4,15 @@ (in-package :pangram) -(defun pangramp (sentence)) +(defun pangramp (text) + (setf lcase (string-downcase text)) + (setf lchars (coerce lcase 'list)) + + (eq + (length + (remove-duplicates + (remove-if-not #'alpha-char-p lchars) + ) + ) + 26) + ) diff --git a/common-lisp/pangram/run-tests-lisp.txt b/common-lisp/pangram/run-tests-lisp.txt new file mode 100644 index 00000000..08b541b6 --- /dev/null +++ b/common-lisp/pangram/run-tests-lisp.txt @@ -0,0 +1,71 @@ +Running automated test file(s): + + +=============================================================================== + +Running: clisp ./run-tests.lisp +To load "fiveam": + Load 1 ASDF system: + fiveam +; Loading "fiveam" + + +Running test suite PANGRAM-SUITE + Running test A-M-AND-A-M-ARE-26-DIFFERENT-CHARACTERS-BUT-NOT-A-PANGRAM . + Running test CASE-INSENSITIVE . + Running test MIXED-CASE-AND-PUNCTUATION . + Running test MISSING-LETTERS-REPLACED-BY-NUMBERS . + Running test WITH-NUMBERS . + Running test WITH-UNDERSCORES . + Running test MISSING-THE-LETTER-H . + Running test MISSING-THE-LETTER-X . + Running test ONLY-LOWER-CASE . + Running test PERFECT-LOWER-CASE . + Running test EMPTY-SENTENCE . + Did 11 checks. + Pass: 11 (100%) + Skip: 0 ( 0%) + Fail: 0 ( 0%) + + +real 0m1.898s +user 0m1.792s +sys 0m0.106s + +=============================================================================== + +sblint -v ./pangram.lisp ./pangram-test.lisp ./run-tests.lisp +[INFO] Lint file pangram.lisp +pangram.lisp:9:17: simple-warning: undefined variable: PANGRAM::LCASE +pangram.lisp:8:4: simple-warning: undefined variable: PANGRAM::LCASE +pangram.lisp:14:7: simple-warning: undefined variable: PANGRAM::LCHARS +pangram.lisp:9:4: simple-warning: undefined variable: PANGRAM::LCHARS + +real 0m0.444s +user 0m0.389s +sys 0m0.055s + +=============================================================================== + +lisp-format -verbose -style=llvm -i ./pangram.lisp ./pangram-test.lisp ./run-tests.lisp +Indenting region... +Indenting region...done +Indenting region... +Indenting region...done +Indenting region... +Indenting region...done + +real 0m0.135s +user 0m0.096s +sys 0m0.042s + +=============================================================================== + +Running: misspell . + +real 0m0.025s +user 0m0.022s +sys 0m0.010s + +=============================================================================== + diff --git a/common-lisp/pangram/run-tests.lisp b/common-lisp/pangram/run-tests.lisp new file mode 100644 index 00000000..1badd467 --- /dev/null +++ b/common-lisp/pangram/run-tests.lisp @@ -0,0 +1,7 @@ +(load "~/.clisprc.lisp") + +(load "./pangram-test.lisp") + +(pangram-test:run-tests) + +(quit)