Skip to content

Commit

Permalink
Merge pull request YearOfProgramming#127 from igniteflow/master
Browse files Browse the repository at this point in the history
challenge_1 in Python and Go
  • Loading branch information
Remillardj authored Jan 4, 2017
2 parents eda2603 + 961b5ca commit 41fd62e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions challenge_1/go/igniteflow/README.md
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
```
22 changes: 22 additions & 0 deletions challenge_1/go/igniteflow/src/challenge_1.go
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))
}
7 changes: 7 additions & 0 deletions challenge_1/python/igniteflow/README.md
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
25 changes: 25 additions & 0 deletions challenge_1/python/igniteflow/src/challenge_1.py
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)

0 comments on commit 41fd62e

Please sign in to comment.