-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
51 additions
and
25 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
10 changes: 10 additions & 0 deletions
10
exercises/practice/reverse-string/.docs/instructions.append.md
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,10 @@ | ||
# ignore | ||
|
||
## 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". |
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 |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
"authors": [ | ||
"glennj" | ||
], | ||
"contributors": [ | ||
"sshine" | ||
], | ||
"files": { | ||
"solution": [ | ||
"reverse-string.tcl" | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
proc stringReverse {str} { | ||
set rev "" | ||
for {set i [expr {[string length $str] - 1}]} {$i >= 0} {incr i -1} { | ||
append rev [string range $str $i $i] | ||
proc reverse {input {reversed ""}} { | ||
if {$input eq ""} { | ||
return $reversed | ||
} | ||
return $rev | ||
tailcall reverse \ | ||
[string range $input 1 end] \ | ||
[string cat [string index $input 0] $reversed] | ||
} |
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
proc stringReverse {} { | ||
proc reverse {input} { | ||
throw {NOT_IMPLEMENTED} "Implement this procedure." | ||
# Stay away from [string reverse] please. | ||
} |
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