Avatar of 4d47
0
0
Genius
0
0

4d47's solution

to Isogram in the Erlang Track

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

Test versioning

Each problem defines a macro TEST_VERSION in the test file and verifies that the solution defines and exports a function test_version returning that same value.

To make tests pass, add the following to your solution:

-export([test_version/0]).

test_version() ->
  1.

The benefit of this is that reviewers can see against which test version an iteration was written if, for example, a previously posted solution does not solve the current problem or passes current tests.

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

-module(isogram_tests).

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

empty_string_test() ->
    ?assert(isogram:is_isogram("")).

isogram_with_only_lower_case_characters_test() ->
    ?assert(isogram:is_isogram("isogram")).

word_with_one_duplicated_character_test() ->
    ?assertNot(isogram:is_isogram("eleven")).

longest_reported_english_isogram_test() ->
    ?assert(isogram:is_isogram("subdermatoglyphic")).

word_with_duplicated_character_in_mixed_case_test() ->
    ?assertNot(isogram:is_isogram("Alphabet")).

hypothetical_isogrammic_word_with_hyphen_test() ->
    ?assert(isogram:is_isogram("thumbscrew-japingly")).

isogram_with_duplicated_hyphen_test() ->
    ?assert(isogram:is_isogram("six-year-old")).

made_up_name_that_is_an_isogram_test() ->
    ?assert(isogram:is_isogram("Emily Jung Schwartzkopf")).

duplicated_character_in_the_middle_test() ->
    ?assertNot(isogram:is_isogram("accentor")).

version_test() ->
  ?assertMatch(1, isogram:test_version()).
-module(isogram).
-export([is_isogram/1, test_version/0]).


test_version() ->
    1.

is_isogram(String) ->
    S = string:lowercase(String),
    Alphabet = sets:from_list(lists:seq($a, $z)),
    Letters = [ C || C <- S, sets:is_element(C, Alphabet) ],
    length(Letters) == sets:size(sets:from_list(Letters)).

What can you learn from this solution?

A huge amount can be learnt 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 I could read more about to develop my understanding?