🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of n0mn0m

n0mn0m's solution

to Pangram in the F# Track

Published at Nov 05 2020 · 0 comments
Instructions
Test suite
Solution

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. Input will not contain non-ASCII symbols.

Running the tests

To run the tests, run the command dotnet test from within the exercise directory.

Autoformatting the code

F# source code can be formatted with the Fantomas tool.

After installing it with dotnet tool restore, run dotnet fantomas . to format code within the current directory.

Further information

For more detailed information about the F# track, including how to get help if you're having trouble, please visit the exercism.io F# language page.

Source

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

PangramTests.fs

// This file was auto-generated based on version 2.0.0 of the canonical data.

module PangramTests

open FsUnit.Xunit
open Xunit

open Pangram

[<Fact>]
let ``Empty sentence`` () =
    isPangram "" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Perfect lower case`` () =
    isPangram "abcdefghijklmnopqrstuvwxyz" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Only lower case`` () =
    isPangram "the quick brown fox jumps over the lazy dog" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Missing the letter 'x'`` () =
    isPangram "a quick movement of the enemy will jeopardize five gunboats" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Missing the letter 'h'`` () =
    isPangram "five boxing wizards jump quickly at it" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``With underscores`` () =
    isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``With numbers`` () =
    isPangram "the 1 quick brown fox jumps over the 2 lazy dogs" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Missing letters replaced by numbers`` () =
    isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Mixed case and punctuation`` () =
    isPangram "\"Five quacking Zephyrs jolt my wax bed.\"" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Case insensitive`` () =
    isPangram "the quick brown fox jumps over with lazy FX" |> should equal false
module Pangram

let isPangram (input: string): bool =
    input.ToLower()
    |> Seq.filter System.Char.IsLetter
    |> Set.ofSeq
    |> Set.count = 26

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?