Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add pangram exercise (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored May 7, 2023
1 parent 6ed4087 commit 41e1cda
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,19 @@
],
"difficulty": 2
},
{
"slug": "pangram",
"name": "Pangram",
"uuid": "a646eaf6-3642-4d05-9083-b520699145b3",
"practices": [
"strings"
],
"prerequisites": [
"strings",
"booleans"
],
"difficulty": 2
},
{
"slug": "space-age",
"name": "Space Age",
Expand Down
8 changes: 8 additions & 0 deletions exercises/practice/pangram/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Instructions

Your task is to figure out if a sentence is a pangram.

A pangram is a sentence using every letter of the alphabet at least once.
It is case insensitive, so it doesn't matter if a letter is lower-case (e.g. `k`) or upper-case (e.g. `K`).

For this exercise, a sentence is a pangram if it contains each of the 26 letters in the English alphabet.
16 changes: 16 additions & 0 deletions exercises/practice/pangram/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Introduction

You work for a company that sells fonts through their website.
They'd like to show a different sentence each time someone views a font on their website.
To give a comprehensive sense of the font, the random sentences should use **all** the letters in the English alphabet.

They're running a competition to get suggestions for sentences that they can use.
You're in charge of checking the submissions to see if they are valid.

~~~~exercism/note
Pangram comes from Greek, παν γράμμα, pan gramma, which means "every letter".
The best known English pangram is:
> The quick brown fox jumps over the lazy dog.
~~~~
19 changes: 19 additions & 0 deletions exercises/practice/pangram/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"ErikSchierboom"
],
"files": {
"solution": [
"src/pangram.cljs"
],
"test": [
"test/pangram_test.cljs"
],
"example": [
".meta/src/example.cljs"
]
},
"blurb": "Determine if a sentence is a pangram.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Pangram"
}
12 changes: 12 additions & 0 deletions exercises/practice/pangram/.meta/src/example.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns pangram
(:require [clojure.string :refer [lower-case]]))

(defn- char<= [ch1 ch2] (<= (compare ch1 ch2) 0))

(defn pangram? [input]
(->> input
(into [] (comp (map #(lower-case %))
(filter #(and (char<= \a %) (char<= % \z)))
(distinct)))
count
(= 26)))
33 changes: 33 additions & 0 deletions exercises/practice/pangram/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.

[64f61791-508e-4f5c-83ab-05de042b0149]
description = "empty sentence"

[74858f80-4a4d-478b-8a5e-c6477e4e4e84]
description = "perfect lower case"

[61288860-35ca-4abe-ba08-f5df76ecbdcd]
description = "only lower case"

[6564267d-8ac5-4d29-baf2-e7d2e304a743]
description = "missing the letter 'x'"

[c79af1be-d715-4cdb-a5f2-b2fa3e7e0de0]
description = "missing the letter 'h'"

[d835ec38-bc8f-48e4-9e36-eb232427b1df]
description = "with underscores"

[8cc1e080-a178-4494-b4b3-06982c9be2a8]
description = "with numbers"

[bed96b1c-ff95-45b8-9731-fdbdcb6ede9a]
description = "missing letters replaced by numbers"

[938bd5d8-ade5-40e2-a2d9-55a338a01030]
description = "mixed case and punctuation"

[2577bf54-83c8-402d-a64b-a2c0f7bb213a]
description = "case insensitive"
10 changes: 10 additions & 0 deletions exercises/practice/pangram/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/clojurescript {:mvn/version "1.10.773"}}

:aliases
{:test
{:extra-paths ["test"]
:extra-deps
{olical/cljs-test-runner {:mvn/version "3.8.0"}}
:main-opts ["-m" "cljs-test-runner.main"]}}}
5 changes: 5 additions & 0 deletions exercises/practice/pangram/src/pangram.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns pangram)

(defn pangram? [] ;; <- arglist goes here
;; your code goes here
)
38 changes: 38 additions & 0 deletions exercises/practice/pangram/test/pangram_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(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"))))

0 comments on commit 41e1cda

Please sign in to comment.