Browse Source

Convert last "prog" exercises as functions exercises (intermediate commit)

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
a30dacadb2
  1. 12
      subjects/doppelgangerprog.en.md
  2. 10
      subjects/findprevprimeprog.en.md
  3. 0
      subjects/halfcontest.en.md
  4. 0
      subjects/printrevcomb.en.md
  5. 0
      subjects/reachablenumber.en.md
  6. 28
      subjects/sliceprog.en.md
  7. 0
      tests/go/solutions/printrevcomb/main.go
  8. 0
      tests/go/solutions/printrevcomb/test_printrevcombprog.go
  9. 2
      tests/go/solutions/sliceprog/test_sliceprog.go
  10. 0
      tests/go/test_doppelganger.go
  11. 0
      tests/go/test_findprevprime.go
  12. 0
      tests/go/test_halfcontest.go

12
subjects/doppelgangerprog.en.md

@ -17,18 +17,22 @@ func DoppelGanger(s, substr string) int {
```go
package main
import "fmt"
import (
piscine ".."
"fmt"
)
func main() {
var result int
result = DoppelGanger("aaaaaaa", "a")
result = piscine.DoppelGanger("aaaaaaa", "a")
fmt.Println(result) // 6
result = DoppelGanger("qwerty", "t")
result = piscine.DoppelGanger("qwerty", "t")
fmt.Println(result) // 4
result = DoppelGanger("a", "b")
result = piscine.DoppelGanger("a", "b")
fmt.Println(result) // -1
}
```

10
subjects/findprevprimeprog.en.md

@ -21,11 +21,15 @@ Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import "fmt"
import (
piscine ".."
"fmt"
)
func main() {
fmt.Println(FindPrevPrime(5))
fmt.Println(FindPrevPrime(4))
fmt.Println(piscine.FindPrevPrime(5))
fmt.Println(piscine.FindPrevPrime(4))
}
```

0
subjects/halfcontestprog.en.md → subjects/halfcontest.en.md

0
subjects/printrevcombprog.en.md → subjects/printrevcomb.en.md

0
subjects/reachablenumberprog.en.md → subjects/reachablenumber.en.md

28
subjects/sliceprog.en.md

@ -2,7 +2,7 @@
### Instructions
Write a **function** that replicates the javascript function `slice`.
Write a **function** that replicates the JavaScript function `slice`.
The function receives a slice of strings and one or more integers, and returns a slice of strings. The returned slice is part of the received one but cut from the position indicated in the first int, until the position indicated by the second int.
@ -25,24 +25,28 @@ Here is a possible program to test your function :
```go
package main
import "fmt"
import (
"fmt"
piscine ".."
)
func main(){
a := []string{"coding", "algorithm", "ascii", "package", "golang"}
fmt.Println(Slice(a, 1))
fmt.Println(Slice(a, 2, 4))
fmt.Println(Slice(a, -3))
fmt.Println(Slice(a, -2, -1))
fmt.Println(Slice(a, 2, 0))
fmt.Printf("%#v\n", piscine.Slice(a, 1))
fmt.Printf("%#v\n", piscine.Slice(a, 2, 4))
fmt.Printf("%#v\n", piscine.Slice(a, -3))
fmt.Printf("%#v\n", piscine.Slice(a, -2, -1))
fmt.Printf("%#v\n", piscine.Slice(a, 2, 0))
}
```
```console
student@ubuntu:~/student/test$ go build
student@ubuntu:~/student/test$ ./test
[algorithm ascii package golang]
[ascii package]
[ascii package golang]
[package]
[]
[]string{"algorithm", "ascii", "package", "golang"}
[]string{"ascii", "package"}
[]string{"ascii", "package", "golang"}
[]string{"package"}
[]string(nil)
```

0
tests/go/solutions/printrevcombprog/main.go → tests/go/solutions/printrevcomb/main.go

0
tests/go/solutions/printrevcombprog/test_printrevcombprog.go → tests/go/solutions/printrevcomb/test_printrevcombprog.go

2
tests/go/solutions/sliceprog/test_sliceprog.go

@ -41,6 +41,6 @@ func main() {
}
for _, a := range arr {
z01.Challenge("SliceProg", student.Slice, correct.Slice, a...)
z01.Challenge("Slice", student.Slice, correct.Slice, a...)
}
}

0
tests/go/solutions/doppelgangerprog/test_doppelgangerprog.go → tests/go/test_doppelganger.go

0
tests/go/solutions/findprevprimeprog/test_findprevprimeprog.go → tests/go/test_findprevprime.go

0
tests/go/solutions/halfcontestprog/test_halfcontestprog.go → tests/go/test_halfcontest.go

Loading…
Cancel
Save