mirror of https://github.com/01-edu/public.git
Browse Source
The goal: printing the alphabet from a chosen letter and going around all the letters.pull/686/head
3 changed files with 104 additions and 0 deletions
@ -0,0 +1,33 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
) |
||||
|
||||
func printAnswer(letter rune) { |
||||
answer := []rune{} |
||||
for i := letter; i <= 'z'; i++ { |
||||
answer = append(answer, i) |
||||
} |
||||
for j := 'a'; j < letter; j++ { |
||||
answer = append(answer, j) |
||||
} |
||||
fmt.Println(string(answer)) |
||||
} |
||||
|
||||
func main() { |
||||
if len(os.Args) == 2 { |
||||
letter := os.Args[1] |
||||
if len(letter) == 1 { |
||||
letterConverted := []rune(letter) |
||||
if letterConverted[0] >= 'a' && letterConverted[0] <= 'z' { |
||||
printAnswer(letterConverted[0]) |
||||
} |
||||
} else { |
||||
fmt.Println() |
||||
} |
||||
} else { |
||||
fmt.Println() |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"lib" |
||||
"strings" |
||||
) |
||||
|
||||
func main() { |
||||
table := string{} |
||||
table = append(table, "A") |
||||
table = append(table, "a") |
||||
table = append(table, "b") |
||||
table = append(table, "c") |
||||
table = append(table, "d") |
||||
table = append(table, "e") |
||||
table = append(table, "f") |
||||
table = append(table, "g") |
||||
table = append(table, "h") |
||||
table = append(table, "i") |
||||
table = append(table, "j") |
||||
table = append(table, "k") |
||||
table = append(table, "l") |
||||
table = append(table, "m") |
||||
table = append(table, "n") |
||||
table = append(table, "o") |
||||
table = append(table, "p") |
||||
table = append(table, "q") |
||||
table = append(table, "r") |
||||
table = append(table, "s") |
||||
table = append(table, "t") |
||||
table = append(table, "u") |
||||
table = append(table, "v") |
||||
table = append(table, "w") |
||||
table = append(table, "x") |
||||
table = append(table, "y") |
||||
table = append(table, "z") |
||||
table = append(table, "Z") |
||||
table = append(table, "2 arguments") |
||||
table = append(table, "4 arguments so invalid") |
||||
|
||||
for _, s := range table { |
||||
lib.ChallengeMain("printrot", strings.Fields(s)...) |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
## printrot |
||||
|
||||
### Instructions |
||||
|
||||
Write a program that takes a lower case letter and goes around in order to display the whole alphabet starting from |
||||
this letter on a single line. |
||||
|
||||
A line is a sequence of characters preceding the [end of line](https://en.wikipedia.org/wiki/Newline) character (`'\n'`). |
||||
|
||||
If the input is invalid the program prints a newline (`'\n'`). |
||||
|
||||
### Usage |
||||
|
||||
```console |
||||
student@ubuntu:~/[[ROOT]]/test$ go build |
||||
student@ubuntu:~/[[ROOT]]/test$ ./test "abc" |
||||
|
||||
student@ubuntu:~/[[ROOT]]/test$ ./test "a" |
||||
abcdefghijklmnopqrstuvwxyz |
||||
student@ubuntu:~/[[ROOT]]/test$ ./test "g" |
||||
ghijklmnopqrstuvwxyzabcdef |
||||
student@ubuntu:~/[[ROOT]]/test$ ./test "a" "a" |
||||
|
||||
student@ubuntu:~/[[ROOT]]/test$ ./test "A" |
||||
|
||||
student@ubuntu:~/[[ROOT]]/test$ |
||||
``` |
Loading…
Reference in new issue