-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tcl/reverse-string: download exercise
- Loading branch information
Showing
7 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"glennj" | ||
], | ||
"files": { | ||
"solution": [ | ||
"reverse-string.tcl" | ||
], | ||
"test": [ | ||
"reverse-string.test" | ||
], | ||
"example": [ | ||
".meta/example.tcl" | ||
] | ||
}, | ||
"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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"track":"tcl","exercise":"reverse-string","id":"b4b3544306de49b0b2e5c0c417c9277f","url":"https://exercism.org/tracks/tcl/exercises/reverse-string","handle":"vpayno","is_requester":true,"auto_approve":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Help | ||
|
||
## Running the tests | ||
|
||
To run the test suite: | ||
```bash | ||
tclsh exercise.test | ||
``` | ||
|
||
## Skipped tests | ||
|
||
Solving an exercise means making all its tests pass. By default, only one | ||
test (the first one) is executed when you run the tests. This is | ||
intentional, as it allows you to focus on just making that one test pass. | ||
Once it passes, you can enable the next test by commenting out or removing | ||
the `skip` command preceding it. | ||
|
||
Alternately, to run all the tests regardless of their "skipped" status: | ||
```bash | ||
RUN_ALL=1 tclsh exercise.test | ||
``` | ||
|
||
## Submitting your solution | ||
|
||
You can submit your solution using the `exercism submit reverse-string.tcl` command. | ||
This command will upload your solution to the Exercism website and print the solution page's URL. | ||
|
||
It's possible to submit an incomplete solution which allows you to: | ||
|
||
- See how others have completed the exercise | ||
- Request help from a mentor | ||
|
||
## Need to get help? | ||
|
||
If you'd like help solving the exercise, check the following pages: | ||
|
||
- The [Tcl track's documentation](https://exercism.org/docs/tracks/tcl) | ||
- The [Tcl track's programming category on the forum](https://forum.exercism.org/c/programming/tcl) | ||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) | ||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) | ||
|
||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. | ||
|
||
Places to look for help for Tcl questions: | ||
|
||
* [Stack Overflow](https://stackoverflow.com/tags/tcl) `tcl` tag. | ||
* check the Resources section of the [Stack Overflow `tcl` tag into page](https://stackoverflow.com/tags/tcl/info). | ||
* raise an issue at the [exercism/tcl](https://github.com/exercism/tcl) repository on GitHub. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Reverse String | ||
|
||
Welcome to Reverse String on Exercism's Tcl Track. | ||
If you need help running the tests or submitting your code, check out `HELP.md`. | ||
|
||
## 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. | ||
|
||
## Instructions | ||
|
||
Your task is to reverse a given string. | ||
|
||
Some examples: | ||
|
||
- Turn `"stressed"` into `"desserts"`. | ||
- Turn `"strops"` into `"sports"`. | ||
- Turn `"racecar"` into `"racecar"`. | ||
|
||
## Tcl-specific instructions | ||
|
||
There are a couple of builtin commands that make this exercise trivial: | ||
|
||
* [`string reverse`](https://www.tcl.tk/man/tcl/TclCmd/string.htm#M43) | ||
* [`lreverse`](https://www.tcl.tk/man/tcl/TclCmd/lreverse.html) | ||
|
||
Try to implement this yourself without using those "cheats". | ||
|
||
## Source | ||
|
||
### Created by | ||
|
||
- @glennj | ||
|
||
### Based on | ||
|
||
Introductory challenge to reverse an input string - https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
proc reverse {input} { | ||
throw {NOT_IMPLEMENTED} "Implement this procedure." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env tclsh | ||
package require tcltest | ||
namespace import ::tcltest::* | ||
source testHelpers.tcl | ||
|
||
############################################################ | ||
source "reverse-string.tcl" | ||
|
||
test reverse-string-1 "an empty string" -body { | ||
reverse "" | ||
} -returnCodes ok -result "" | ||
|
||
skip reverse-string-2 | ||
test reverse-string-2 "a word" -body { | ||
reverse "robot" | ||
} -returnCodes ok -result "tobor" | ||
|
||
skip reverse-string-3 | ||
test reverse-string-3 "a capitalized word" -body { | ||
reverse "Ramen" | ||
} -returnCodes ok -result "nemaR" | ||
|
||
skip reverse-string-4 | ||
test reverse-string-4 "a sentence with punctuation" -body { | ||
reverse "I'm hungry!" | ||
} -returnCodes ok -result "!yrgnuh m'I" | ||
|
||
skip reverse-string-5 | ||
test reverse-string-5 "a palindrome" -body { | ||
reverse "racecar" | ||
} -returnCodes ok -result "racecar" | ||
|
||
skip reverse-string-6 | ||
test reverse-string-6 "an even-sized word" -body { | ||
reverse "drawer" | ||
} -returnCodes ok -result "reward" | ||
|
||
skip reverse-string-7 | ||
test reverse-string-7 "wide characters" -body { | ||
reverse "子猫" | ||
} -returnCodes ok -result "猫子" | ||
|
||
cleanupTests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
############################################################# | ||
# Override some tcltest procs with additional functionality | ||
|
||
# Allow an environment variable to override `skip` | ||
proc skip {patternList} { | ||
if { [info exists ::env(RUN_ALL)] | ||
&& [string is boolean -strict $::env(RUN_ALL)] | ||
&& $::env(RUN_ALL) | ||
} then return else { | ||
uplevel 1 [list ::tcltest::skip $patternList] | ||
} | ||
} | ||
|
||
# Exit non-zero if any tests fail. | ||
# The cleanupTests resets the numTests array, so capture it first. | ||
proc cleanupTests {} { | ||
set failed [expr {$::tcltest::numTests(Failed) > 0}] | ||
uplevel 1 ::tcltest::cleanupTests | ||
if {$failed} then {exit 1} | ||
} |