forked from YearOfProgramming/2017Challenges
-
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.
Merge pull request YearOfProgramming#127 from igniteflow/master
challenge_1 in Python and Go
- Loading branch information
Showing
4 changed files
with
59 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,5 @@ | ||
``` | ||
$ go run src/challenge_1.go | ||
easy as abc | ||
cba sa ysae | ||
``` |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func reverseString(stringToReverse string) string { | ||
// limitations: only works for strings, not UTF-8 | ||
data := []string{} | ||
for i := 0; i < len(stringToReverse); i++ { | ||
data = append([]string{string(stringToReverse[i])}, data...) | ||
} | ||
|
||
return strings.Join(data, "") | ||
} | ||
|
||
func main() { | ||
var stringToReverse string = "easy as abc" | ||
fmt.Println(stringToReverse) | ||
fmt.Println(reverseString(stringToReverse)) | ||
} |
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,7 @@ | ||
Output: | ||
|
||
$ python ./src/challenge_1.py | ||
Before: easy as abc | ||
After: cba sa ysae | ||
|
||
*Note `python` is not required if the file is executable |
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,25 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
#Reverse a String | ||
##Premise | ||
- For this coding challenge, your task is to reverse a string for any given | ||
string input. | ||
Example: Given s = "hello", return "olleh". | ||
- Try to make the solution as short and simple as possible in your respective | ||
language of choice. | ||
""" | ||
|
||
|
||
def reverse_string(string): | ||
return ''.join([string[idx - 1] for idx in range(len(string), 0, -1)]) | ||
|
||
|
||
if __name__ == '__main__': | ||
str_to_reverse = 'easy as abc' | ||
print 'Before: ', str_to_reverse | ||
print 'After: ', reverse_string(str_to_reverse) |