Skip to content

Commit

Permalink
add reverse-string (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored Feb 6, 2024
1 parent f1f83fc commit 7d75dda
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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"`.
5 changes: 5 additions & 0 deletions exercises/practice/reverse-string/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions exercises/practice/reverse-string/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions exercises/practice/reverse-string/.meta/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-module(example).

-export([reverse/1]).

reverse(_String) ->
lists:reverse(_String).
39 changes: 39 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions exercises/practice/reverse-string/rebar.config
Original file line number Diff line number Diff line change
@@ -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]}.
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/src/reverse_string.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{application, reverse_string,
[{description, "exercism.io - reverse string"},
{vsn, "0.0.1"},
{modules, []},
{registered, []},
{applications, [kernel,
stdlib]},
{env, []}
]}.
6 changes: 6 additions & 0 deletions exercises/practice/reverse-string/src/reverse_string.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-module(reverse_string).

-export([reverse/1]).

reverse(_String) ->
undefined.
56 changes: 56 additions & 0 deletions exercises/practice/reverse-string/test/reverse_string_tests.erl
Original file line number Diff line number Diff line change
@@ -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))}.

0 comments on commit 7d75dda

Please sign in to comment.