diff --git a/config.json b/config.json index ecd7a058..f20ce532 100644 --- a/config.json +++ b/config.json @@ -961,6 +961,14 @@ "practices": [], "prerequisites": [], "difficulty": 1 + }, + { + "slug": "reverse-string", + "name": "Reverse String", + "uuid": "9400fc2a-b3e8-4982-883b-a2d574a1d7ee", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ], "foregone": [ diff --git a/exercises/practice/reverse-string/.docs/instructions.md b/exercises/practice/reverse-string/.docs/instructions.md new file mode 100644 index 00000000..0ff4198e --- /dev/null +++ b/exercises/practice/reverse-string/.docs/instructions.md @@ -0,0 +1,9 @@ +# Instructions + +Your task is to reverse a given string. + +Some examples: + +- Turn `"stressed"` into `"desserts"`. +- Turn `"strops"` into `"sports"`. +- Turn `"racecar"` into `"racecar"`. diff --git a/exercises/practice/reverse-string/.docs/introduction.md b/exercises/practice/reverse-string/.docs/introduction.md new file mode 100644 index 00000000..02233e07 --- /dev/null +++ b/exercises/practice/reverse-string/.docs/introduction.md @@ -0,0 +1,5 @@ +# Introduction + +Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming. + +For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance. diff --git a/exercises/practice/reverse-string/.meta/config.json b/exercises/practice/reverse-string/.meta/config.json new file mode 100644 index 00000000..17149328 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "src/reverse_string.erl" + ], + "test": [ + "test/reverse_string_tests.erl" + ], + "example": [ + ".meta/example.erl" + ] + }, + "blurb": "Reverse a given string.", + "source": "Introductory challenge to reverse an input string", + "source_url": "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb" +} diff --git a/exercises/practice/reverse-string/.meta/example.erl b/exercises/practice/reverse-string/.meta/example.erl new file mode 100644 index 00000000..77e46c68 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/example.erl @@ -0,0 +1,6 @@ +-module(example). + +-export([reverse/1]). + +reverse(_String) -> + lists:reverse(_String). diff --git a/exercises/practice/reverse-string/.meta/tests.toml b/exercises/practice/reverse-string/.meta/tests.toml new file mode 100644 index 00000000..0d87a26c --- /dev/null +++ b/exercises/practice/reverse-string/.meta/tests.toml @@ -0,0 +1,39 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[c3b7d806-dced-49ee-8543-933fd1719b1c] +description = "an empty string" + +[01ebf55b-bebb-414e-9dec-06f7bb0bee3c] +description = "a word" + +[0f7c07e4-efd1-4aaa-a07a-90b49ce0b746] +description = "a capitalized word" + +[71854b9c-f200-4469-9f5c-1e8e5eff5614] +description = "a sentence with punctuation" + +[1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c] +description = "a palindrome" + +[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c] +description = "an even-sized word" + +[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2] +description = "wide characters" + +[93d7e1b8-f60f-4f3c-9559-4056e10d2ead] +description = "grapheme cluster with pre-combined form" +include = false + +[1028b2c1-6763-4459-8540-2da47ca512d9] +description = "grapheme clusters" +include = false \ No newline at end of file diff --git a/exercises/practice/reverse-string/rebar.config b/exercises/practice/reverse-string/rebar.config new file mode 100644 index 00000000..db5d9076 --- /dev/null +++ b/exercises/practice/reverse-string/rebar.config @@ -0,0 +1,30 @@ +%% Erlang compiler options +{erl_opts, [debug_info, warnings_as_errors]}. + +{deps, [{erl_exercism, "0.1.2"}]}. + +{dialyzer, [ + {warnings, [underspecs, no_return]}, + {get_warnings, true}, + {plt_apps, top_level_deps}, % top_level_deps | all_deps + {plt_extra_apps, []}, + {plt_location, local}, % local | "/my/file/name" + {plt_prefix, "rebar3"}, + {base_plt_apps, [stdlib, kernel, crypto]}, + {base_plt_location, global}, % global | "/my/file/name" + {base_plt_prefix, "rebar3"} +]}. + +%% eunit:test(Tests) +{eunit_tests, []}. +%% Options for eunit:test(Tests, Opts) +{eunit_opts, [verbose]}. + +%% == xref == + +{xref_warnings, true}. + +%% xref checks to run +{xref_checks, [undefined_function_calls, undefined_functions, + locals_not_used, exports_not_used, + deprecated_function_calls, deprecated_functions]}. diff --git a/exercises/practice/reverse-string/src/reverse_string.app.src b/exercises/practice/reverse-string/src/reverse_string.app.src new file mode 100644 index 00000000..14253b2c --- /dev/null +++ b/exercises/practice/reverse-string/src/reverse_string.app.src @@ -0,0 +1,9 @@ +{application, reverse_string, + [{description, "exercism.io - reverse string"}, + {vsn, "0.0.1"}, + {modules, []}, + {registered, []}, + {applications, [kernel, + stdlib]}, + {env, []} + ]}. diff --git a/exercises/practice/reverse-string/src/reverse_string.erl b/exercises/practice/reverse-string/src/reverse_string.erl new file mode 100644 index 00000000..5c2b8df4 --- /dev/null +++ b/exercises/practice/reverse-string/src/reverse_string.erl @@ -0,0 +1,6 @@ +-module(reverse_string). + +-export([reverse/1]). + +reverse(_String) -> + undefined. diff --git a/exercises/practice/reverse-string/test/reverse_string_tests.erl b/exercises/practice/reverse-string/test/reverse_string_tests.erl new file mode 100644 index 00000000..d2818475 --- /dev/null +++ b/exercises/practice/reverse-string/test/reverse_string_tests.erl @@ -0,0 +1,56 @@ +-module(reverse_string_tests). + +-include_lib("erl_exercism/include/exercism.hrl"). +-include_lib("eunit/include/eunit.hrl"). + + + + +'1_reverse_an_empty_string_test_'() -> + Input = "", + Expected = "", + {"reverse an empty string", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}. + +'2_reverse_a_word_test_'() -> + Input = "robot", + Expected = "tobor", + {"reverse a word", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}. + +'3_reverse_a_capitalized_word_test_'() -> + Input = "Ramen", + Expected = "nemaR", + {"reverse a capitalized word", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}. + +'4_reverse_a_sentence_with_punctuation_test_'() -> + Input = "I'm hungry!", + Expected = "!yrgnuh m'I", + {"reverse a sentence with punctuation", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}. + +'5_reverse_a_palindrome_test_'() -> + Input = "racecar", + Expected = "racecar", + {"reverse a palindrome", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}. + +'6_reverse_an_even_sized_word_test_'() -> + Input = "drawer", + Expected = "reward", + {"reverse an even-sized word", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}. + +'7_reverse_wide_characters_test_'() -> + Input = "子猫", + Expected = "猫子", + {"reverse wide characters", + ?_assertEqual(Expected, + reverse_string:reverse(Input))}.