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

epequeno's solution

to Isogram in the Elm Track

Published at Apr 22 2021 · 1 comment
Test suite

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.

Elm Installation

Refer to the Installing Elm page for information about installing elm.

Writing the Code

The code you have to write is located inside the src/ directory of the exercise. Elm automatically installs packages dependencies the first time you run the tests so we can start by running the tests from the exercise directory with:

$ elm-test

To automatically run tests again when you save changes:

$ elm-test --watch

As you work your way through the tests suite in the file tests/Tests.elm, be sure to remove the skip <| calls from each test until you get them all passing!


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

Submitting Incomplete Solutions

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


module Tests exposing (tests)

import Expect
import Isogram exposing (isIsogram)
import Test exposing (..)

tests : Test
tests =
    describe "Isogram"
        [ test "empty string" <|
            \() ->
                Expect.equal True <| isIsogram ""
        , skip <|
            test "isogram with only lower case characters" <|
                \() ->
                    Expect.equal True <| isIsogram "isogram"
        , skip <|
            test "word with one duplicated character" <|
                \() ->
                    Expect.equal False <| isIsogram "eleven"
        , skip <|
            test "longest reported english isogram" <|
                \() ->
                    Expect.equal True <| isIsogram "subdermatoglyphic"
        , skip <|
            test "word with duplicated character in mixed case" <|
                \() ->
                    Expect.equal False <| isIsogram "Alphabet"
        , skip <|
            test "hypothetical isogrammic word with hyphen" <|
                \() ->
                    Expect.equal True <| isIsogram "thumbscrew-japingly"
        , skip <|
            test "isogram with duplicated non letter character" <|
                \() ->
                    Expect.equal True <| isIsogram "Hjelmqvist-Gryb-Zock-Pfund-Wax"
        , skip <|
            test "made-up name that is an isogram" <|
                \() ->
                    Expect.equal True <| isIsogram "Emily Jung Schwartzkopf"
        , skip <|
            test "duplicated character in the middle" <|
                \() ->
                    Expect.equal False <| isIsogram "accentor"
module Isogram exposing (isIsogram)

isIsogram : String -> Bool
isIsogram sentence =
        |> String.filter Char.isAlpha
        |> String.toLower
        |> String.toList
        |> List.sort
        |> anyRepeated
        |> not

anyRepeated : List Char -> Bool
anyRepeated xs =
    case xs of
        [ a, b ] ->
            a == b

        a :: b :: rest ->
            a == b || anyRepeated (b :: rest)

        _ ->

Community comments

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

I took this approach because I wanted to get more practice writing a recursive solution that uses list pattern matching.

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?