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

n0mn0m's solution

to Isogram in the F# Track

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

Determine if a word or phrase is an isogram.

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

  • lumberjacks
  • background
  • downstream
  • six-year-old

The word isograms, however, is not an isogram, because the s repeats.

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/Isogram

IsogramTests.fs

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

module IsogramTests

open FsUnit.Xunit
open Xunit

open Isogram

[<Fact>]
let ``Empty string`` () =
    isIsogram "" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Isogram with only lower case characters`` () =
    isIsogram "isogram" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Word with one duplicated character`` () =
    isIsogram "eleven" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Word with one duplicated character from the end of the alphabet`` () =
    isIsogram "zzyzx" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Longest reported english isogram`` () =
    isIsogram "subdermatoglyphic" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Word with duplicated character in mixed case`` () =
    isIsogram "Alphabet" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Word with duplicated character in mixed case, lowercase first`` () =
    isIsogram "alphAbet" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Hypothetical isogrammic word with hyphen`` () =
    isIsogram "thumbscrew-japingly" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Hypothetical word with duplicated character following hyphen`` () =
    isIsogram "thumbscrew-jappingly" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Isogram with duplicated hyphen`` () =
    isIsogram "six-year-old" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Made-up name that is an isogram`` () =
    isIsogram "Emily Jung Schwartzkopf" |> should equal true

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Duplicated character in the middle`` () =
    isIsogram "accentor" |> should equal false

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Same first and last characters`` () =
    isIsogram "angola" |> should equal false
module Isogram

let isIsogram (str: string) =
    str.ToLowerInvariant()
    |> Seq.filter System.Char.IsLetter
    |> Seq.countBy (fun c -> c)
    |> Seq.forall (fun (_, x) -> x = 1)

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?