Browse Source

Improve range & reverse subjects & correct implementations

content-update
Xavier Petit 4 years ago
parent
commit
08b3df53e0
No known key found for this signature in database
GPG Key ID: CA3F2B17E25ABD26
  1. 11
      go/tests/prog/range_prog/main.go
  2. 11
      go/tests/prog/reverserange_prog/main.go
  3. 16
      subjects/range/README.md
  4. 16
      subjects/reverserange/README.md

11
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()
}

11
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()
}

16
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$
```

16
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$

Loading…
Cancel
Save