From 08b3df53e0d63630750c60a1b44f586139c288c1 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Fri, 26 Jun 2020 13:25:14 +0200 Subject: [PATCH] Improve range & reverse subjects & correct implementations --- go/tests/prog/range_prog/main.go | 11 ++++++++--- go/tests/prog/reverserange_prog/main.go | 11 ++++++++--- subjects/range/README.md | 16 +++++----------- subjects/reverserange/README.md | 16 +++++----------- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/go/tests/prog/range_prog/main.go b/go/tests/prog/range_prog/main.go index b035d6ae..a65297e6 100644 --- a/go/tests/prog/range_prog/main.go +++ b/go/tests/prog/range_prog/main.go @@ -14,11 +14,16 @@ func main() { } a, err := strconv.Atoi(os.Args[1]) if err != nil { - panic("ERROR: " + err.Error()) + fmt.Println(err) + return } b, err := strconv.Atoi(os.Args[2]) if err != nil { - panic("ERROR: " + err.Error()) + fmt.Println(err) + return + } + for _, i := range lib.IntRange(a, b) { + fmt.Print(i) } - fmt.Println(lib.IntRange(a, b)) + fmt.Println() } diff --git a/go/tests/prog/reverserange_prog/main.go b/go/tests/prog/reverserange_prog/main.go index b035d6ae..05a7cbec 100644 --- a/go/tests/prog/reverserange_prog/main.go +++ b/go/tests/prog/reverserange_prog/main.go @@ -14,11 +14,16 @@ func main() { } a, err := strconv.Atoi(os.Args[1]) if err != nil { - panic("ERROR: " + err.Error()) + fmt.Println(err) + return } b, err := strconv.Atoi(os.Args[2]) if err != nil { - panic("ERROR: " + err.Error()) + fmt.Println(err) + return + } + for _, i := range lib.IntRange(b, a) { + fmt.Print(i) } - fmt.Println(lib.IntRange(a, b)) + fmt.Println() } diff --git a/subjects/range/README.md b/subjects/range/README.md index 3c9fa9a0..4820bc5c 100644 --- a/subjects/range/README.md +++ b/subjects/range/README.md @@ -2,13 +2,7 @@ ### Instructions -Write a program which must: - -- **Allocate (with `make`)** a slice of integers. - -- Fill it with consecutive values that begins at the first argument and end at the second argument (Including the values of thoses arguments !). - -- That prints the slice. +Write a program that takes two numbers as arguments and prints the consecutive values that begins at the first number and end at the second number (including the values of those numbers !). Errors should be handled. @@ -19,12 +13,12 @@ If the number of arguments is different from 2 the program prints nothing. ```console student@ubuntu:~/range$ go build student@ubuntu:~/range$ ./range 1 3 -[1 2 3] +1 2 3 student@ubuntu:~/range$ ./range -1 2 | cat -e -[-1 0 1 2]$ +-1 0 1 2$ student@ubuntu:~/range$ ./range 0 0 -[0] -student@ubuntu:~/reverserange$ ./reverserange 0 nan | cat -e +0 +student@ubuntu:~/range$ ./range 0 nan | cat -e strconv.Atoi: parsing "nan": invalid syntax$ student@ubuntu:~/range$ ``` diff --git a/subjects/reverserange/README.md b/subjects/reverserange/README.md index f05529af..4d962475 100644 --- a/subjects/reverserange/README.md +++ b/subjects/reverserange/README.md @@ -2,13 +2,7 @@ ### Instructions -Write a program which must: - -- **Allocate (with `make`)** a slice of integers. - -- Fill it with consecutive values that begins at the second argument and end at the first argument (Including the values of thoses arguments !). - -- That prints the slice. +Write a program that takes two numbers as arguments and prints the consecutive values that begins at the second number and end at the first number (including the values of those numbers !). Errors should be handled. @@ -19,13 +13,13 @@ If the number of arguments is different from 2 the program prints nothing. ```console student@ubuntu:~/reverserange$ go build student@ubuntu:~/reverserange$ ./reverserange 1 3 -[3 2 1] +3 2 1 student@ubuntu:~/reverserange$ ./reverserange -1 2 | cat -e -[2 1 0 -1]$ +2 1 0 -1$ student@ubuntu:~/reverserange$ ./reverserange 0 0 -[0] +0 student@ubuntu:~/reverserange$ ./reverserange 0 -3 -[-3 -2 -1 0] +-3 -2 -1 0 student@ubuntu:~/reverserange$ ./reverserange 0 nan | cat -e strconv.Atoi: parsing "nan": invalid syntax$ student@ubuntu:~/reverserange$