Browse Source

Update exercises, imports

content-update
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 ```console
student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test student@ubuntu:~/[[ROOT]]/test$ ./test | cat -e
1230123 1230123$
student@ubuntu:~/[[ROOT]]/test$ student@ubuntu:~/[[ROOT]]/test$
``` ```

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

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

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

@ -1,6 +1,6 @@
package correct package correct
import "github.com/01-edu/z01" import "fmt"
const size = 8 const size = 8
@ -44,13 +44,13 @@ func printQueens() {
for y < size { for y < size {
if board[x][y] { if board[x][y] {
// We have found a queen, let's print her y // We have found a queen, let's print her y
z01.PrintRune(rune(y) + '1') fmt.Printf("%c", rune(y)+'1')
} }
y++ y++
} }
x++ 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 // 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 package correct
import ( import (
"fmt"
"os" "os"
"strconv" "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) { func solve(x, y int) {
for i := 0; i < x; i++ { for i := 0; i < x; i++ {
line := "" line := ""
@ -28,20 +20,20 @@ func solve(x, y int) {
line += " " line += " "
} }
} }
printLineCh(line) fmt.Println(line)
} }
} }
func main() { func main() {
args := os.Args[1:] args := os.Args[1:]
if len(args) != 2 { if len(args) != 2 {
printLineCh("Error") fmt.Println("Error")
return return
} }
x, _ := strconv.Atoi(args[1]) x, _ := strconv.Atoi(args[1])
y, _ := strconv.Atoi(args[0]) y, _ := strconv.Atoi(args[0])
if x <= 0 || y <= 0 { if x <= 0 || y <= 0 {
printLineCh("Error") fmt.Println("Error")
return return
} }
solve(x, y) solve(x, y)

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

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

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

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

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

@ -1,9 +1,8 @@
package correct package correct
import ( import (
"fmt"
"sort" "sort"
"github.com/01-edu/z01"
) )
func intToDigits(n int) (digits []int) { func intToDigits(n int) (digits []int) {
@ -20,12 +19,13 @@ func intToDigits(n int) (digits []int) {
func PrintNbrInOrder(n int) { func PrintNbrInOrder(n int) {
if n == 0 { if n == 0 {
z01.PrintRune('0') fmt.Print("0")
return return
} }
digits := intToDigits(n) digits := intToDigits(n)
sort.Ints(digits) sort.Ints(digits)
for _, i := range 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 package correct
import "github.com/01-edu/z01" import "fmt"
func drawLine(x int, str string) { func drawLine(x int, s string) {
strConverted := []rune(str) beg := s[0]
beg := strConverted[0] med := s[1]
med := strConverted[1] end := s[2]
end := strConverted[2]
if x >= 1 { if x >= 1 {
z01.PrintRune(beg) fmt.Printf("%c", beg)
} }
if x > 2 { if x > 2 {
for i := 0; i < (x - 2); i++ { for i := 0; i < (x - 2); i++ {
z01.PrintRune(med) fmt.Printf("%c", med)
} }
} }
if x > 1 { if x > 1 {
z01.PrintRune(end) fmt.Printf("%c", end)
} }
z01.PrintRune('\n') fmt.Println()
} }
func printTheLines(x, y int, strBeg, strMed, strEnd string) { func printTheLines(x, y int, strBeg, strMed, strEnd string) {

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

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

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

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

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

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

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

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

4
tests/go/prog/test_tetrisoptimizer.go

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

Loading…
Cancel
Save