Browse Source

Update exercises, imports

pull/533/head
Xavier Petit 4 years ago committed by xpetit
parent
commit
529a13d15d
  1. 4
      subjects/printnbrinorder.en.md
  2. 11
      tests/go/func/broken/correct/printnbrbase.go
  3. 6
      tests/go/func/correct/eightqueens.go
  4. 16
      tests/go/func/correct/printchessboard.go
  5. 11
      tests/go/func/correct/printcomb.go
  6. 29
      tests/go/func/correct/printmemory.go
  7. 8
      tests/go/func/correct/printnbrinorder.go
  8. 19
      tests/go/func/correct/raid1a.go
  9. 19
      tests/go/func/correct/raid1b.go
  10. 19
      tests/go/func/correct/raid1c.go
  11. 19
      tests/go/func/correct/raid1d.go
  12. 19
      tests/go/func/correct/raid1e.go
  13. 4
      tests/go/prog/test_tetrisoptimizer.go

4
subjects/printnbrinorder.en.md

@ -34,7 +34,7 @@ And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
1230123
student@ubuntu:~/[[ROOT]]/test$ ./test | cat -e
1230123$
student@ubuntu:~/[[ROOT]]/test$
```

11
tests/go/func/broken/correct/printnbrbase.go

@ -1,6 +1,6 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func PrintNbrBase(n int, base string) {
if validBase(base) {
@ -8,17 +8,16 @@ func PrintNbrBase(n int, base string) {
sign := 1
rbase := []rune(base)
if n < 0 {
z01.PrintRune('-')
fmt.Print("-")
sign = -1
}
if n < length && n >= 0 {
z01.PrintRune(rbase[n])
fmt.Printf("%c", rbase[n])
} else {
PrintNbrBase(sign*(n/length), base)
z01.PrintRune(rbase[sign*(n%length)])
fmt.Printf("%c", rbase[sign*(n%length)])
}
} else {
z01.PrintRune('N')
z01.PrintRune('V')
fmt.Print("NV")
}
}

6
tests/go/func/correct/eightqueens.go

@ -1,6 +1,6 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
const size = 8
@ -44,13 +44,13 @@ func printQueens() {
for y < size {
if board[x][y] {
// We have found a queen, let's print her y
z01.PrintRune(rune(y) + '1')
fmt.Printf("%c", rune(y)+'1')
}
y++
}
x++
}
z01.PrintRune('\n')
fmt.Println()
}
// tryX tries, for a given x (column) to find a y (row) so that the queen on (x, y) is a part

16
tests/go/func/correct/printchessboard.go

@ -1,19 +1,11 @@
package correct
import (
"fmt"
"os"
"strconv"
"github.com/01-edu/z01"
)
func printLineCh(str string) {
for _, c := range str {
z01.PrintRune(c)
}
z01.PrintRune('\n')
}
func solve(x, y int) {
for i := 0; i < x; i++ {
line := ""
@ -28,20 +20,20 @@ func solve(x, y int) {
line += " "
}
}
printLineCh(line)
fmt.Println(line)
}
}
func main() {
args := os.Args[1:]
if len(args) != 2 {
printLineCh("Error")
fmt.Println("Error")
return
}
x, _ := strconv.Atoi(args[1])
y, _ := strconv.Atoi(args[0])
if x <= 0 || y <= 0 {
printLineCh("Error")
fmt.Println("Error")
return
}
solve(x, y)

11
tests/go/func/correct/printcomb.go

@ -1,19 +1,16 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func PrintComb() {
for i := '0'; i <= '7'; i++ {
for j := i + 1; j <= '8'; j++ {
for k := j + 1; k <= '9'; k++ {
z01.PrintRune(rune(i))
z01.PrintRune(rune(j))
z01.PrintRune(rune(k))
fmt.Printf("%c%c%c", i, j, k)
if i < '7' {
z01.PrintRune(rune(','))
z01.PrintRune(rune(' '))
fmt.Printf(", ")
} else {
z01.PrintRune(rune('\n'))
fmt.Println()
}
}
}

29
tests/go/func/correct/printmemory.go

@ -1,9 +1,8 @@
package correct
import (
"fmt"
"unicode"
"github.com/01-edu/z01"
)
func printBase(nbr int) int {
@ -28,7 +27,7 @@ func printBase(nbr int) int {
i = 2
}
for j := i - 1; j >= 0; j-- {
z01.PrintRune(result[j])
fmt.Printf("%c", result[j])
a++
}
return a
@ -41,42 +40,42 @@ func printLine(arr [10]int, start int) {
for a < start+16 && a < size {
if a%4 == 0 && a != 0 {
z01.PrintRune('\n')
fmt.Println()
}
b = 8 - printBase(arr[a])
for aux != b {
if b == 6 {
z01.PrintRune('0')
fmt.Print("0")
}
if aux == 1 {
z01.PrintRune(' ')
fmt.Print(" ")
}
if b < 6 {
z01.PrintRune('0')
fmt.Print("0")
}
aux++
}
z01.PrintRune(' ')
fmt.Print(" ")
aux = 0
a++
}
z01.PrintRune('\n')
fmt.Println()
c := start
for c < start+16 && c < size {
if unicode.IsPrint(rune(arr[c])) {
z01.PrintRune(rune(arr[c]))
fmt.Printf("%c", rune(arr[c]))
} else {
z01.PrintRune('.')
fmt.Print(".")
}
c++
}
z01.PrintRune('\n')
fmt.Println()
}
func PrintMemory(arr [10]int) {
func PrintMemory(a [10]int) {
i := 0
for i < len(arr) {
printLine(arr, i)
for i < len(a) {
printLine(a, i)
i += 16
}
}

8
tests/go/func/correct/printnbrinorder.go

@ -1,9 +1,8 @@
package correct
import (
"fmt"
"sort"
"github.com/01-edu/z01"
)
func intToDigits(n int) (digits []int) {
@ -20,12 +19,13 @@ func intToDigits(n int) (digits []int) {
func PrintNbrInOrder(n int) {
if n == 0 {
z01.PrintRune('0')
fmt.Print("0")
return
}
digits := intToDigits(n)
sort.Ints(digits)
for _, i := range digits {
z01.PrintRune(rune(i) + '0')
fmt.Printf("%c", rune(i)+'0')
}
fmt.Println()
}

19
tests/go/func/correct/raid1a.go

@ -1,24 +1,23 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func drawLine(x int, str string) {
strConverted := []rune(str)
beg := strConverted[0]
med := strConverted[1]
end := strConverted[2]
func drawLine(x int, s string) {
beg := s[0]
med := s[1]
end := s[2]
if x >= 1 {
z01.PrintRune(beg)
fmt.Printf("%c", beg)
}
if x > 2 {
for i := 0; i < (x - 2); i++ {
z01.PrintRune(med)
fmt.Printf("%c", med)
}
}
if x > 1 {
z01.PrintRune(end)
fmt.Printf("%c", end)
}
z01.PrintRune('\n')
fmt.Println()
}
func printTheLines(x, y int, strBeg, strMed, strEnd string) {

19
tests/go/func/correct/raid1b.go

@ -1,24 +1,23 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func drawLineRaid1b(x int, str string) {
strConverted := []rune(str)
beg := strConverted[0]
med := strConverted[1]
end := strConverted[2]
func drawLineRaid1b(x int, s string) {
beg := s[0]
med := s[1]
end := s[2]
if x >= 1 {
z01.PrintRune(beg)
fmt.Printf("%c", beg)
}
if x > 2 {
for i := 0; i < (x - 2); i++ {
z01.PrintRune(med)
fmt.Printf("%c", med)
}
}
if x > 1 {
z01.PrintRune(end)
fmt.Printf("%c", end)
}
z01.PrintRune('\n')
fmt.Println()
}
func Raid1b(x, y int) {

19
tests/go/func/correct/raid1c.go

@ -1,24 +1,23 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func drawLineRaid1c(x int, str string) {
strConverted := []rune(str)
beg := strConverted[0]
med := strConverted[1]
end := strConverted[2]
func drawLineRaid1c(x int, s string) {
beg := s[0]
med := s[1]
end := s[2]
if x >= 1 {
z01.PrintRune(beg)
fmt.Printf("%c", beg)
}
if x > 2 {
for i := 0; i < (x - 2); i++ {
z01.PrintRune(med)
fmt.Printf("%c", med)
}
}
if x > 1 {
z01.PrintRune(end)
fmt.Printf("%c", end)
}
z01.PrintRune('\n')
fmt.Println()
}
func Raid1c(x, y int) {

19
tests/go/func/correct/raid1d.go

@ -1,24 +1,23 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func drawLineRaid1d(x int, str string) {
strConverted := []rune(str)
beg := strConverted[0]
med := strConverted[1]
end := strConverted[2]
func drawLineRaid1d(x int, s string) {
beg := s[0]
med := s[1]
end := s[2]
if x >= 1 {
z01.PrintRune(beg)
fmt.Printf("%c", beg)
}
if x > 2 {
for i := 0; i < (x - 2); i++ {
z01.PrintRune(med)
fmt.Printf("%c", med)
}
}
if x > 1 {
z01.PrintRune(end)
fmt.Printf("%c", end)
}
z01.PrintRune('\n')
fmt.Println()
}
func Raid1d(x, y int) {

19
tests/go/func/correct/raid1e.go

@ -1,24 +1,23 @@
package correct
import "github.com/01-edu/z01"
import "fmt"
func drawLineRaid1e(x int, str string) {
strConverted := []rune(str)
beg := strConverted[0]
med := strConverted[1]
end := strConverted[2]
func drawLineRaid1e(x int, s string) {
beg := s[0]
med := s[1]
end := s[2]
if x >= 1 {
z01.PrintRune(beg)
fmt.Printf("%c", beg)
}
if x > 2 {
for i := 0; i < (x - 2); i++ {
z01.PrintRune(med)
fmt.Printf("%c", med)
}
}
if x > 1 {
z01.PrintRune(end)
fmt.Printf("%c", end)
}
z01.PrintRune('\n')
fmt.Println()
}
func Raid1e(x, y int) {

4
tests/go/prog/test_tetrisoptimizer.go

@ -28,8 +28,7 @@ type (
tetromino [3]vect
)
// load a tetromino composed of the rune r in the map s
// example :
// load a tetromino composed of the rune r in the map s, example :
//
// read(`......
// ......
@ -40,7 +39,6 @@ type (
// `,
// 'X',
// ) == tetromino{{-2, 1}, {-1, 1}, {0, 1}}
func read(s string, r rune) (t tetromino) {
var origin vect
i := 0

Loading…
Cancel
Save