Skip to content

Commit

Permalink
pangram-exercise: Added new exercise. (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimaDovakin committed Jul 18, 2024
1 parent 3b09787 commit 16be8a7
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@
"practices": [],
"prerequisites": [],
"difficulty": 4
},
{
"slug": "pangram",
"name": "Pangram",
"uuid": "aff04ad8-9a9c-47ff-a153-c768c3d0aaf0",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},
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": [
"SimaDovakin"
],
"files": {
"solution": [
"pangram.u"
],
"test": [
"pangram.test.u"
],
"example": [
".meta/examples/pangram.example.u"
]
},
"blurb": "Determine if a sentence is a pangram.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Pangram"
}
18 changes: 18 additions & 0 deletions exercises/practice/pangram/.meta/examples/pangram.example.u
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pangram.isPangram : Text -> Boolean
pangram.isPangram sentence =
pangramNumber = 67108863
sentence
|> toCharList
|> map getPower
|> filter ((!==) None)
|> map (shiftLeft 1 << getOrElse 0)
|> foldLeft or 0
|> (==) pangramNumber


pangram.getPower : Char -> Optional Nat
pangram.getPower = cases
c | (c >= ?A) && (c <= ?Z) -> Some (toNat c - toNat ?A)
c | (c >= ?a) && (c <= ?z) -> Some (toNat c - toNat ?a)
_ -> None

42 changes: 42 additions & 0 deletions exercises/practice/pangram/.meta/testAnnotation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "pangram.isPangram.tests.ex1",
"test_code": "expect (false == isPangram \"\")\n |> Test.label \"empty sentence\""
},
{
"name": "pangram.isPangram.tests.ex2",
"test_code": "expect (true == isPangram \"abcdefghijklmnopqrstuvwxyz\")\n |> Test.label \"perfect lower case\""
},
{
"name": "pangram.isPangram.tests.ex3",
"test_code": "expect (true == isPangram \"the quick brown fox jumps over the lazy dog\")\n |> Test.label \"only lower case\""
},
{
"name": "pangram.isPangram.tests.ex4",
"test_code": "expect (false == isPangram \"a quick movement of the enemy will jeopardize five gunboats\")\n |> Test.label \"missing the letter 'x'\""
},
{
"name": "pangram.isPangram.tests.ex5",
"test_code": "expect (false == isPangram \"five boxing wizards jump quickly at it\")\n |> Test.label \"missing the letter 'h'\""
},
{
"name": "pangram.isPangram.tests.ex6",
"test_code": "expect (true == isPangram \"the_quick_brown_fox_jumps_over_the_lazy_dog\")\n |> Test.label \"with underscores\""
},
{
"name": "pangram.isPangram.tests.ex7",
"test_code": "expect (true == isPangram \"the 1 quick brown fox jumps over the 2 lazy dogs\")\n |> Test.label \"with numbers\""
},
{
"name": "pangram.isPangram.tests.ex8",
"test_code": "expect (false == isPangram \"7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog\")\n |> Test.label \"missing letters replaced by numbers\""
},
{
"name": "pangram.isPangram.tests.ex9",
"test_code": "expect (true == isPangram \"\"Five quacking Zephyrs jolt my wax bed.\"\")\n |> Test.label \"mixed case and punctuation\""
},
{
"name": "pangram.isPangram.tests.ex10",
"test_code": "expect (false == isPangram \"abcdefghijklm ABCDEFGHIJKLM\")\n |> Test.label \"a-m and A-M are 26 different characters but not a pangram\""
}
]
9 changes: 9 additions & 0 deletions exercises/practice/pangram/.meta/testLoader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Testing transcript for pangram exercise

```ucm
.> load ./pangram.u
.> add
.> load ./pangram.test.u
.> add
.> move.term pangram.tests tests
```
45 changes: 45 additions & 0 deletions exercises/practice/pangram/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via 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"
include = false

[7138e389-83e4-4c6e-8413-1e40a0076951]
description = "a-m and A-M are 26 different characters but not a pangram"
reimplements = "2577bf54-83c8-402d-a64b-a2c0f7bb213a"
52 changes: 52 additions & 0 deletions exercises/practice/pangram/pangram.test.u
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pangram.isPangram.tests.ex1 =
expect (false == isPangram "")
|> Test.label "empty sentence"

pangram.isPangram.tests.ex2 =
expect (true == isPangram "abcdefghijklmnopqrstuvwxyz")
|> Test.label "perfect lower case"

pangram.isPangram.tests.ex3 =
expect (true == isPangram "the quick brown fox jumps over the lazy dog")
|> Test.label "only lower case"

pangram.isPangram.tests.ex4 =
expect (false == isPangram "a quick movement of the enemy will jeopardize five gunboats")
|> Test.label "missing the letter 'x'"

pangram.isPangram.tests.ex5 =
expect (false == isPangram "five boxing wizards jump quickly at it")
|> Test.label "missing the letter 'h'"

pangram.isPangram.tests.ex6 =
expect (true == isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog")
|> Test.label "with underscores"

pangram.isPangram.tests.ex7 =
expect (true == isPangram "the 1 quick brown fox jumps over the 2 lazy dogs")
|> Test.label "with numbers"

pangram.isPangram.tests.ex8 =
expect (false == isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")
|> Test.label "missing letters replaced by numbers"

pangram.isPangram.tests.ex9 =
expect (true == isPangram "\"Five quacking Zephyrs jolt my wax bed.\"")
|> Test.label "mixed case and punctuation"

pangram.isPangram.tests.ex10 =
expect (false == isPangram "abcdefghijklm ABCDEFGHIJKLM")
|> Test.label "a-m and A-M are 26 different characters but not a pangram"

test> pangram.tests = runAll [
pangram.isPangram.tests.ex1,
pangram.isPangram.tests.ex2,
pangram.isPangram.tests.ex3,
pangram.isPangram.tests.ex4,
pangram.isPangram.tests.ex5,
pangram.isPangram.tests.ex6,
pangram.isPangram.tests.ex7,
pangram.isPangram.tests.ex8,
pangram.isPangram.tests.ex9,
pangram.isPangram.tests.ex10
]
2 changes: 2 additions & 0 deletions exercises/practice/pangram/pangram.u
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pangram.isPangram : Text -> Boolean
pangram.isPangram sentence = todo "implement isPangram"

0 comments on commit 16be8a7

Please sign in to comment.