Skip to content

Commit edff34d

Browse files
authored
Add pangram exercise (exercism#322)
1 parent 9035bf0 commit edff34d

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@
387387
"prerequisites": [],
388388
"difficulty": 1
389389
},
390+
{
391+
"slug": "pangram",
392+
"name": "Pangram",
393+
"uuid": "af3484cd-a74a-4a55-a641-5483d25ca006",
394+
"practices": [],
395+
"prerequisites": [],
396+
"difficulty": 3
397+
},
390398
{
391399
"slug": "pop-count",
392400
"name": "Eliud's Eggs",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Instructions
2+
3+
Your task is to figure out if a sentence is a pangram.
4+
5+
A pangram is a sentence using every letter of the alphabet at least once.
6+
It is case insensitive, so it doesn't matter if a letter is lower-case (e.g. `k`) or upper-case (e.g. `K`).
7+
8+
For this exercise, a sentence is a pangram if it contains each of the 26 letters in the English alphabet.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
You work for a company that sells fonts through their website.
4+
They'd like to show a different sentence each time someone views a font on their website.
5+
To give a comprehensive sense of the font, the random sentences should use **all** the letters in the English alphabet.
6+
7+
They're running a competition to get suggestions for sentences that they can use.
8+
You're in charge of checking the submissions to see if they are valid.
9+
10+
~~~~exercism/note
11+
Pangram comes from Greek, παν γράμμα, pan gramma, which means "every letter".
12+
13+
The best known English pangram is:
14+
15+
> The quick brown fox jumps over the lazy dog.
16+
~~~~
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"pangram.rkt"
8+
],
9+
"test": [
10+
"pangram-test.rkt"
11+
],
12+
"example": [
13+
".meta/example.rkt"
14+
]
15+
},
16+
"blurb": "Determine if a sentence is a pangram.",
17+
"source": "Wikipedia",
18+
"source_url": "https://en.wikipedia.org/wiki/Pangram"
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#lang racket
2+
3+
(provide pangram?)
4+
5+
(define alphabet-length
6+
(length (string->list "abcdefghijklmnopqrstuvwxyz")))
7+
8+
(define (pangram? sentence)
9+
(define letters (for/set ([chr sentence]
10+
#:when (char-alphabetic? chr))
11+
(char-downcase chr)))
12+
(eq? (set-count letters) alphabet-length))
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[64f61791-508e-4f5c-83ab-05de042b0149]
13+
description = "empty sentence"
14+
15+
[74858f80-4a4d-478b-8a5e-c6477e4e4e84]
16+
description = "perfect lower case"
17+
18+
[61288860-35ca-4abe-ba08-f5df76ecbdcd]
19+
description = "only lower case"
20+
21+
[6564267d-8ac5-4d29-baf2-e7d2e304a743]
22+
description = "missing the letter 'x'"
23+
24+
[c79af1be-d715-4cdb-a5f2-b2fa3e7e0de0]
25+
description = "missing the letter 'h'"
26+
27+
[d835ec38-bc8f-48e4-9e36-eb232427b1df]
28+
description = "with underscores"
29+
30+
[8cc1e080-a178-4494-b4b3-06982c9be2a8]
31+
description = "with numbers"
32+
33+
[bed96b1c-ff95-45b8-9731-fdbdcb6ede9a]
34+
description = "missing letters replaced by numbers"
35+
36+
[938bd5d8-ade5-40e2-a2d9-55a338a01030]
37+
description = "mixed case and punctuation"
38+
39+
[2577bf54-83c8-402d-a64b-a2c0f7bb213a]
40+
description = "case insensitive"
41+
include = false
42+
43+
[7138e389-83e4-4c6e-8413-1e40a0076951]
44+
description = "a-m and A-M are 26 different characters but not a pangram"
45+
reimplements = "2577bf54-83c8-402d-a64b-a2c0f7bb213a"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#lang racket/base
2+
3+
(require "pangram.rkt")
4+
5+
(module+ test
6+
(require rackunit rackunit/text-ui)
7+
8+
(define suite
9+
(test-suite
10+
"pangram tests"
11+
12+
(test-false "empty sentence"
13+
(pangram? ""))
14+
15+
(test-true "perfect lower case"
16+
(pangram? "abcdefghijklmnopqrstuvwxyz"))
17+
18+
(test-true "only lower case"
19+
(pangram? "the quick brown fox jumps over the lazy dog"))
20+
21+
(test-false "missing the letter 'x'"
22+
(pangram? "a quick movement of the enemy will jeopardize five gunboats"))
23+
24+
(test-false "missing the letter 'h'"
25+
(pangram? "five boxing wizards jump quickly at it"))
26+
27+
(test-true "with underscores"
28+
(pangram? "the_quick_brown_fox_jumps_over_the_lazy_dog"))
29+
30+
(test-true "with numbers"
31+
(pangram? "the 1 quick brown fox jumps over the 2 lazy dogs"))
32+
33+
(test-false "missing letters replaced by numbers"
34+
(pangram? "t7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))
35+
36+
(test-true "mixed case and punctuation"
37+
(pangram? "\"Five quacking Zephyrs jolt my wax bed.\""))
38+
39+
(test-false "a-m and A-M are 26 different characters but not a pangram"
40+
(pangram? "abcdefghijklm ABCDEFGHIJKLM"))))
41+
42+
(run-tests suite))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#lang racket
2+
3+
(provide pangram?)
4+
5+
(define (pangram? sentence)
6+
(error "Not implemented yet"))

0 commit comments

Comments
 (0)