Exercism v3 launches on Sept 1st 2021. Learn more! 🚀🚀🚀
Avatar of rootulp

rootulp's solution

to Pangram in the Elm Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

Note:

This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Some input will contain non-ASCII symbols.

Elm Installation

Refer to the Exercism help page for Elm installation and learning resources.

Writing the Code

The first time you start an exercise, you'll need to ensure you have the appropriate dependencies installed.

$ elm-package install --yes

Execute the tests with:

$ elm-test

Automatically run tests again when you save changes:

$ elm-test --watch

As you work your way through the test suite, be sure to remove the skip <| calls from each test until you get them all passing!

Source

Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Tests.elm

module Tests exposing (..)

import Expect
import Pangram exposing (isPangram)
import Test exposing (..)


tests : Test
tests =
    describe "Pangram"
        [ test "sentence empty" <|
            \() ->
                Expect.equal False
                    (isPangram "")
        , skip <|
            test "pangram with only lower case" <|
                \() ->
                    Expect.equal True
                        (isPangram "the quick brown fox jumps over the lazy dog")
        , skip <|
            test "missing character 'x'" <|
                \() ->
                    Expect.equal False
                        (isPangram "a quick movement of the enemy will jeopardize five gunboats")
        , skip <|
            test "missing character 'z'" <|
                \() ->
                    Expect.equal False
                        (isPangram "a quick movement of the enemy will jeopardixe five gunboats")
        , skip <|
            test "another missing character 'x'" <|
                \() ->
                    Expect.equal False
                        (isPangram "the quick brown fish jumps over the lazy dog")
        , skip <|
            test "pangram with underscores" <|
                \() ->
                    Expect.equal True
                        (isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog")
        , skip <|
            test "pangram with numbers" <|
                \() ->
                    Expect.equal True
                        (isPangram "the 1 quick brown fox jumps over the 2 lazy dogs")
        , skip <|
            test "missing letters replaced by numbers" <|
                \() ->
                    Expect.equal False
                        (isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")
        , skip <|
            test "pangram with mixed case and punctuation" <|
                \() ->
                    Expect.equal True
                        (isPangram "\"Five quacking Zephyrs jolt my wax bed.\"")
        , skip <|
            test "pangram with non ascii characters" <|
                \() ->
                    Expect.equal True
                        (isPangram "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.")
        ]

elm-package.json

{
    "version": "3.0.0",
    "summary": "Exercism problems in Elm.",
    "repository": "https://github.com/exercism/elm.git",
    "license": "BSD3",
    "source-directories": [
        ".",
        ".."
    ],
    "exposed-modules": [],
    "dependencies": {
        "elm-lang/core": "5.0.0 <= v < 6.0.0",
        "elm-community/elm-test": "4.0.0 <= v < 5.0.0"
    },
    "elm-version": "0.18.0 <= v < 0.19.0"
}
module Pangram exposing (..)

import Set exposing (..)


isPangram: String -> Bool
isPangram sentence =
    String.toUpper sentence
        |> String.toList
        |> Set.fromList
        |> Set.diff alphabet
        |> Set.isEmpty


alphabet: Set Char
alphabet =
    String.toList "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        |> Set.fromList

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?