Skip to content

Commit ddb7f31

Browse files
Add solution for Challenges by betosmith2000 (#235)
* Add solution for Challenge 1 by betosmith2000 * Add solution for Challenge 2 by betosmith2000
1 parent cc38742 commit ddb7f31

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
var a, b int
9+
// Read two integers from standard input
10+
_, err := fmt.Scanf("%d, %d", &a, &b)
11+
if err != nil {
12+
fmt.Println("Error reading input:", err)
13+
return
14+
}
15+
16+
// Call the Sum function and print the result
17+
result := Sum(a, b)
18+
fmt.Println(result)
19+
}
20+
21+
// Sum returns the sum of a and b.
22+
func Sum(a, b int) int {
23+
return a + b;
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
// Read input from standard input
11+
scanner := bufio.NewScanner(os.Stdin)
12+
if scanner.Scan() {
13+
input := scanner.Text()
14+
15+
// Call the ReverseString function
16+
output := ReverseString(input)
17+
18+
// Print the result
19+
fmt.Println(output)
20+
}
21+
}
22+
23+
// ReverseString returns the reversed string of s.
24+
func ReverseString(s string) string {
25+
runes := []rune(s)
26+
t := len(runes)
27+
28+
for i:= 0; i < t/2; i++ {
29+
runes[i], runes[t-1-i] = runes[t-1-i], runes[i]
30+
}
31+
return string(runes)
32+
}

0 commit comments

Comments
 (0)