Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of Samyual

Samyual's solution

to Isogram in the Erlang Track

Published at Feb 23 2021 · 1 comment
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 tests

In order to run the tests, issue the following command from the exercise directory:

For running the tests provided, rebar3 is used as it is the official build and dependency management tool for erlang now. Please refer to the tracks installation instructions on how to do that.

In order to run the tests, you can issue the following command from the exercise directory.

$ rebar3 eunit

Questions?

For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.

Source

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

Submitting Incomplete Solutions

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

isogram_tests.erl

%% Generated with 'testgen v0.2.0'
%% Revision 1 of the exercises generator was used
%% https://github.com/exercism/problem-specifications/raw/42dd0cea20498fd544b152c4e2c0a419bb7e266a/exercises/isogram/canonical-data.json
%% This file is automatically generated from the exercises canonical data.

-module(isogram_tests).

-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").




'1_empty_string_test_'() ->
    {"empty string", ?_assert(isogram:is_isogram([]))}.

'2_isogram_with_only_lower_case_characters_test_'() ->
    {"isogram with only lower case characters",
     ?_assert(isogram:is_isogram("isogram"))}.

'3_word_with_one_duplicated_character_test_'() ->
    {"word with one duplicated character",
     ?_assertNot(isogram:is_isogram("eleven"))}.

'4_word_with_one_duplicated_character_from_the_end_of_the_alphabet_test_'() ->
    {"word with one duplicated character from "
     "the end of the alphabet",
     ?_assertNot(isogram:is_isogram("zzyzx"))}.

'5_longest_reported_english_isogram_test_'() ->
    {"longest reported english isogram",
     ?_assert(isogram:is_isogram("subdermatoglyphic"))}.

'6_word_with_duplicated_character_in_mixed_case_test_'() ->
    {"word with duplicated character in mixed "
     "case",
     ?_assertNot(isogram:is_isogram("Alphabet"))}.

'7_word_with_duplicated_character_in_mixed_case_lowercase_first_test_'() ->
    {"word with duplicated character in mixed "
     "case, lowercase first",
     ?_assertNot(isogram:is_isogram("alphAbet"))}.

'8_hypothetical_isogrammic_word_with_hyphen_test_'() ->
    {"hypothetical isogrammic word with hyphen",
     ?_assert(isogram:is_isogram("thumbscrew-japingly"))}.

'9_hypothetical_word_with_duplicated_character_following_hyphen_test_'() ->
    {"hypothetical word with duplicated character "
     "following hyphen",
     ?_assertNot(isogram:is_isogram("thumbscrew-jappingly"))}.

'10_isogram_with_duplicated_hyphen_test_'() ->
    {"isogram with duplicated hyphen",
     ?_assert(isogram:is_isogram("six-year-old"))}.

'11_made_up_name_that_is_an_isogram_test_'() ->
    {"made-up name that is an isogram",
     ?_assert(isogram:is_isogram("Emily Jung Schwartzkopf"))}.

'12_duplicated_character_in_the_middle_test_'() ->
    {"duplicated character in the middle",
     ?_assertNot(isogram:is_isogram("accentor"))}.

'13_same_first_and_last_characters_test_'() ->
    {"same first and last characters",
     ?_assertNot(isogram:is_isogram("angola"))}.
-module(isogram).

-export([is_isogram/1]).


is_isogram(Phrase) ->
  Sanitized = [X || X <- string:lowercase(Phrase), $a =< X, X =< $z],
  length(Sanitized) == sets:size(sets:from_list(Sanitized)).

Community comments

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

very nice !

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?