Skip to content

Commit b445356

Browse files
committed
pangram-exercise: Added new exercise.
1 parent 3b09787 commit b445356

File tree

10 files changed

+219
-0
lines changed

10 files changed

+219
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@
398398
"practices": [],
399399
"prerequisites": [],
400400
"difficulty": 4
401+
},
402+
{
403+
"slug": "pangram",
404+
"name": "Pangram",
405+
"uuid": "aff04ad8-9a9c-47ff-a153-c768c3d0aaf0",
406+
"practices": [],
407+
"prerequisites": [],
408+
"difficulty": 1
401409
}
402410
]
403411
},
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+
"SimaDovakin"
4+
],
5+
"files": {
6+
"solution": [
7+
"pangram.u"
8+
],
9+
"test": [
10+
"pangram.test.u"
11+
],
12+
"example": [
13+
".meta/examples/pangram.example.u"
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pangram.isPangram : Text -> Boolean
2+
pangram.isPangram sentence =
3+
pangramNumber = 67108863
4+
sentence
5+
|> toCharList
6+
|> map getPower
7+
|> filter ((!==) None)
8+
|> map (shiftLeft 1 << getOrElse 0)
9+
|> foldLeft or 0
10+
|> (==) pangramNumber
11+
12+
13+
pangram.getPower : Char -> Optional Nat
14+
pangram.getPower = cases
15+
c | (c >= ?A) && (c <= ?Z) -> Some (toNat c - toNat ?A)
16+
c | (c >= ?a) && (c <= ?z) -> Some (toNat c - toNat ?a)
17+
_ -> None
18+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"name": "pangram.isPangram.tests.ex1",
4+
"test_code": "expect (false == isPangram \"\")\n |> Test.label \"empty sentence\""
5+
},
6+
{
7+
"name": "pangram.isPangram.tests.ex2",
8+
"test_code": "expect (true == isPangram \"abcdefghijklmnopqrstuvwxyz\")\n |> Test.label \"perfect lower case\""
9+
},
10+
{
11+
"name": "pangram.isPangram.tests.ex3",
12+
"test_code": "expect (true == isPangram \"the quick brown fox jumps over the lazy dog\")\n |> Test.label \"only lower case\""
13+
},
14+
{
15+
"name": "pangram.isPangram.tests.ex4",
16+
"test_code": "expect (false == isPangram \"a quick movement of the enemy will jeopardize five gunboats\")\n |> Test.label \"missing the letter 'x'\""
17+
},
18+
{
19+
"name": "pangram.isPangram.tests.ex5",
20+
"test_code": "expect (false == isPangram \"five boxing wizards jump quickly at it\")\n |> Test.label \"missing the letter 'h'\""
21+
},
22+
{
23+
"name": "pangram.isPangram.tests.ex6",
24+
"test_code": "expect (true == isPangram \"the_quick_brown_fox_jumps_over_the_lazy_dog\")\n |> Test.label \"with underscores\""
25+
},
26+
{
27+
"name": "pangram.isPangram.tests.ex7",
28+
"test_code": "expect (true == isPangram \"the 1 quick brown fox jumps over the 2 lazy dogs\")\n |> Test.label \"with numbers\""
29+
},
30+
{
31+
"name": "pangram.isPangram.tests.ex8",
32+
"test_code": "expect (false == isPangram \"7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog\")\n |> Test.label \"missing letters replaced by numbers\""
33+
},
34+
{
35+
"name": "pangram.isPangram.tests.ex9",
36+
"test_code": "expect (true == isPangram \"\"Five quacking Zephyrs jolt my wax bed.\"\")\n |> Test.label \"mixed case and punctuation\""
37+
},
38+
{
39+
"name": "pangram.isPangram.tests.ex10",
40+
"test_code": "expect (false == isPangram \"abcdefghijklm ABCDEFGHIJKLM\")\n |> Test.label \"a-m and A-M are 26 different characters but not a pangram\""
41+
}
42+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Testing transcript for pangram exercise
2+
3+
```ucm
4+
.> load ./pangram.u
5+
.> add
6+
.> load ./pangram.test.u
7+
.> add
8+
.> move.term pangram.tests tests
9+
```
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
pangram.isPangram.tests.ex1 =
2+
expect (false == isPangram "")
3+
|> Test.label "empty sentence"
4+
5+
pangram.isPangram.tests.ex2 =
6+
expect (true == isPangram "abcdefghijklmnopqrstuvwxyz")
7+
|> Test.label "perfect lower case"
8+
9+
pangram.isPangram.tests.ex3 =
10+
expect (true == isPangram "the quick brown fox jumps over the lazy dog")
11+
|> Test.label "only lower case"
12+
13+
pangram.isPangram.tests.ex4 =
14+
expect (false == isPangram "a quick movement of the enemy will jeopardize five gunboats")
15+
|> Test.label "missing the letter 'x'"
16+
17+
pangram.isPangram.tests.ex5 =
18+
expect (false == isPangram "five boxing wizards jump quickly at it")
19+
|> Test.label "missing the letter 'h'"
20+
21+
pangram.isPangram.tests.ex6 =
22+
expect (true == isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog")
23+
|> Test.label "with underscores"
24+
25+
pangram.isPangram.tests.ex7 =
26+
expect (true == isPangram "the 1 quick brown fox jumps over the 2 lazy dogs")
27+
|> Test.label "with numbers"
28+
29+
pangram.isPangram.tests.ex8 =
30+
expect (false == isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")
31+
|> Test.label "missing letters replaced by numbers"
32+
33+
pangram.isPangram.tests.ex9 =
34+
expect (true == isPangram "\"Five quacking Zephyrs jolt my wax bed.\"")
35+
|> Test.label "mixed case and punctuation"
36+
37+
pangram.isPangram.tests.ex10 =
38+
expect (false == isPangram "abcdefghijklm ABCDEFGHIJKLM")
39+
|> Test.label "a-m and A-M are 26 different characters but not a pangram"
40+
41+
test> pangram.tests = runAll [
42+
pangram.isPangram.tests.ex1,
43+
pangram.isPangram.tests.ex2,
44+
pangram.isPangram.tests.ex3,
45+
pangram.isPangram.tests.ex4,
46+
pangram.isPangram.tests.ex5,
47+
pangram.isPangram.tests.ex6,
48+
pangram.isPangram.tests.ex7,
49+
pangram.isPangram.tests.ex8,
50+
pangram.isPangram.tests.ex9,
51+
pangram.isPangram.tests.ex10
52+
]

exercises/practice/pangram/pangram.u

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pangram.isPangram : Text -> Boolean
2+
pangram.isPangram sentence = todo "implement isPangram"

0 commit comments

Comments
 (0)