Browse Source

Use "fmt.Print*" instead of "z01.PrintRune" for our implementations

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
9f94254a1e
  1. 8
      tests/go/prog/addprimesum/main.go
  2. 27
      tests/go/prog/boolean/main.go
  3. 5
      tests/go/prog/brainfuck/main.go
  4. 8
      tests/go/prog/displayalpham/main.go
  5. 8
      tests/go/prog/displayalrevm/main.go
  6. 8
      tests/go/prog/firstword/main.go
  7. 6
      tests/go/prog/fprime/main.go
  8. 14
      tests/go/prog/hiddenp/main.go
  9. 20
      tests/go/prog/nbrconvertalpha/main.go
  10. 4
      tests/go/prog/onlya/main.go
  11. 4
      tests/go/prog/onlyz/main.go
  12. 28
      tests/go/prog/piglatin/main.go
  13. 16
      tests/go/prog/printchessboard/main.go
  14. 6
      tests/go/prog/printdigits/main.go
  15. 8
      tests/go/prog/printhex/main.go
  16. 8
      tests/go/prog/raid2/main.go
  17. 9
      tests/go/prog/repeatalpha/main.go
  18. 7
      tests/go/prog/rot13/main.go
  19. 7
      tests/go/prog/uniqueoccurences/main.go
  20. 6
      tests/go/prog/ztail/main.go

8
tests/go/prog/addprimesum/main.go

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"github.com/01-edu/z01"
) )
func isPrime(nb int) bool { func isPrime(nb int) bool {
@ -31,14 +29,12 @@ func isPrime(nb int) bool {
func main() { func main() {
if len(os.Args) != 2 { if len(os.Args) != 2 {
z01.PrintRune('0') fmt.Println("0")
z01.PrintRune('\n')
} else { } else {
argument, _ := strconv.Atoi(os.Args[1]) argument, _ := strconv.Atoi(os.Args[1])
if argument < 0 { if argument < 0 {
z01.PrintRune('0') fmt.Println("0")
z01.PrintRune('\n')
} else { } else {
result := 0 result := 0
for ; argument >= 0; argument-- { for ; argument >= 0; argument-- {

27
tests/go/prog/boolean/main.go

@ -1,33 +1,14 @@
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/01-edu/z01"
) )
func printStr(str string) {
arrayStr := []rune(str)
for i := 0; i < len(arrayStr); i++ {
z01.PrintRune(arrayStr[i])
}
z01.PrintRune('\n')
}
func isEven(nbr int) bool {
return nbr%2 == 0
}
func main() { func main() {
EvenMsg := "I have an even number of arguments" if len(os.Args)-1%2 == 0 {
OddMsg := "I have an odd number of arguments" fmt.Println("I have an even number of arguments")
lenOfArg := len(os.Args) - 1
if isEven(lenOfArg) {
printStr(EvenMsg)
} else { } else {
printStr(OddMsg) fmt.Println("I have an odd number of arguments")
} }
} }

5
tests/go/prog/brainfuck/main.go

@ -1,9 +1,8 @@
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/01-edu/z01"
) )
const SIZE = 2048 const SIZE = 2048
@ -34,7 +33,7 @@ func main() {
arby[pos]-- arby[pos]--
case '.': case '.':
// print the pointed byte on std output // print the pointed byte on std output
z01.PrintRune(rune(arby[pos])) fmt.Printf("%c", rune(arby[pos]))
case '[': case '[':
// go to the matching ']' if the pointed byte is 0 (while start) // go to the matching ']' if the pointed byte is 0 (while start)
openBr = 0 openBr = 0

8
tests/go/prog/displayalpham/main.go

@ -1,15 +1,15 @@
package main package main
import "github.com/01-edu/z01" import "fmt"
func main() { func main() {
diff := 'a' - 'A' diff := 'a' - 'A'
for c := 'a'; c <= 'z'; c++ { for c := 'a'; c <= 'z'; c++ {
if c%2 == 0 { if c%2 == 0 {
z01.PrintRune(c - diff) fmt.Printf("%c", c-diff)
} else { } else {
z01.PrintRune(c) fmt.Printf("%c", c)
} }
} }
z01.PrintRune('\n') fmt.Println()
} }

8
tests/go/prog/displayalrevm/main.go

@ -1,15 +1,15 @@
package main package main
import "github.com/01-edu/z01" import "fmt"
func main() { func main() {
diff := 'a' - 'A' diff := 'a' - 'A'
for c := 'z'; c >= 'a'; c-- { for c := 'z'; c >= 'a'; c-- {
if c%2 == 0 { if c%2 == 0 {
z01.PrintRune(c) fmt.Printf("%c", c)
} else { } else {
z01.PrintRune(c - diff) fmt.Printf("%c", c-diff)
} }
} }
z01.PrintRune('\n') fmt.Println()
} }

8
tests/go/prog/firstword/main.go

@ -3,26 +3,22 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"github.com/01-edu/z01"
) )
func main() { func main() {
if len(os.Args) == 2 { if len(os.Args) == 2 {
for i := 0; i < len(os.Args[1]); i++ { for i := 0; i < len(os.Args[1]); i++ {
if os.Args[1][i] != ' ' { if os.Args[1][i] != ' ' {
z01.PrintRune(rune(os.Args[1][i])) fmt.Printf("%c", rune(os.Args[1][i]))
if i != len(os.Args[1])-1 { if i != len(os.Args[1])-1 {
if os.Args[1][i+1] == ' ' { if os.Args[1][i+1] == ' ' {
z01.PrintRune('\n') fmt.Println()
return return
} }
} }
} }
} }
z01.PrintRune('\n')
} else {
fmt.Println() fmt.Println()
} }
} }

6
tests/go/prog/fprime/main.go

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"github.com/01-edu/z01"
) )
func fprime(value int) { func fprime(value int) {
@ -19,13 +17,13 @@ func fprime(value int) {
value = value / divisionIterator value = value / divisionIterator
if value > 1 { if value > 1 {
z01.PrintRune('*') fmt.Print("*")
} }
divisionIterator-- divisionIterator--
} }
divisionIterator++ divisionIterator++
} }
z01.PrintRune('\n') fmt.Println()
} }
func main() { func main() {

14
tests/go/prog/hiddenp/main.go

@ -1,9 +1,8 @@
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/01-edu/z01"
) )
func main() { func main() {
@ -15,13 +14,11 @@ func main() {
second := os.Args[2] second := os.Args[2]
if first == "" { if first == "" {
z01.PrintRune('1') fmt.Println("1")
z01.PrintRune('\n')
return return
} }
if second == "" { if second == "" {
z01.PrintRune('0') fmt.Println("0")
z01.PrintRune('\n')
return return
} }
@ -47,9 +44,8 @@ func main() {
} }
if count == len(first) { if count == len(first) {
z01.PrintRune('1') fmt.Println("1")
} else { } else {
z01.PrintRune('0') fmt.Println("0")
} }
z01.PrintRune('\n')
} }

20
tests/go/prog/nbrconvertalpha/main.go

@ -1,15 +1,15 @@
package main package main
import ( import (
"fmt"
"os" "os"
"strconv" "strconv"
"unicode"
"github.com/01-edu/z01"
) )
func IsNumeric(str string) bool { func IsNumeric(s string) bool {
for i := 0; i < len(str); i++ { for _, r := range s {
if !(str[i] >= '0' && str[i] <= '9') { if !unicode.IsDigit(r) {
return false return false
} }
} }
@ -28,18 +28,18 @@ func main() {
if number <= 26 && number >= 1 && !boole { if number <= 26 && number >= 1 && !boole {
number += 96 number += 96
z01.PrintRune(rune(number)) fmt.Printf("%c", rune(number))
} else if number <= 26 && number >= 1 && boole { } else if number <= 26 && number >= 1 && boole {
number += 64 number += 64
z01.PrintRune(rune(number)) fmt.Printf("%c", rune(number))
} else { } else {
z01.PrintRune(' ') fmt.Print(" ")
} }
} else { } else {
if !(arguments[i] == "--upper" && i == 0) { if !(arguments[i] == "--upper" && i == 0) {
z01.PrintRune(' ') fmt.Print(" ")
} }
} }
} }
z01.PrintRune('\n') fmt.Println()
} }

4
tests/go/prog/onlya/main.go

@ -1,7 +1,7 @@
package main package main
import "github.com/01-edu/z01" import "fmt"
func main() { func main() {
z01.PrintRune('a') fmt.Print("a")
} }

4
tests/go/prog/onlyz/main.go

@ -1,7 +1,7 @@
package main package main
import "github.com/01-edu/z01" import "fmt"
func main() { func main() {
z01.PrintRune('z') fmt.Print("z")
} }

28
tests/go/prog/piglatin/main.go

@ -3,13 +3,23 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"github.com/01-edu/z01"
) )
func firstNotVowel(letters []rune) int {
index := 0
for i := 0; i < len(letters); i++ {
if letters[i] == 'a' || letters[i] == 'e' || letters[i] == 'i' || letters[i] == 'o' || letters[i] == 'u' ||
letters[i] == 'A' || letters[i] == 'E' || letters[i] == 'I' || letters[i] == 'O' || letters[i] == 'U' {
return index
}
index++
}
return 0
}
func main() { func main() {
if len(os.Args) != 2 || os.Args[1] == "" { if len(os.Args) != 2 || os.Args[1] == "" {
z01.PrintRune('\n') fmt.Println()
return return
} }
letters := []rune(os.Args[1]) letters := []rune(os.Args[1])
@ -25,15 +35,3 @@ func main() {
} }
} }
} }
func firstNotVowel(letters []rune) int {
index := 0
for i := 0; i < len(letters); i++ {
if letters[i] == 'a' || letters[i] == 'e' || letters[i] == 'i' || letters[i] == 'o' || letters[i] == 'u' ||
letters[i] == 'A' || letters[i] == 'E' || letters[i] == 'I' || letters[i] == 'O' || letters[i] == 'U' {
return index
}
index++
}
return 0
}

16
tests/go/prog/printchessboard/main.go

@ -1,19 +1,11 @@
package main package main
import ( import (
"fmt"
"os" "os"
"strconv" "strconv"
"github.com/01-edu/z01"
) )
func printLine(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 += " "
} }
} }
printLine(line) fmt.Println(line)
} }
} }
func main() { func main() {
args := os.Args[1:] args := os.Args[1:]
if len(args) != 2 { if len(args) != 2 {
printLine("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 {
printLine("Error") fmt.Println("Error")
return return
} }
solve(x, y) solve(x, y)

6
tests/go/prog/printdigits/main.go

@ -1,10 +1,10 @@
package main package main
import "github.com/01-edu/z01" import "fmt"
func main() { func main() {
for i := '0'; i <= '9'; i++ { for i := '0'; i <= '9'; i++ {
z01.PrintRune(i) fmt.Printf("%c", i)
} }
z01.PrintRune('\n') fmt.Println()
} }

8
tests/go/prog/printhex/main.go

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"github.com/01-edu/z01"
) )
func printBase(nbr int, base string) { func printBase(nbr int, base string) {
@ -19,18 +17,18 @@ func printBase(nbr int, base string) {
nbr = nbr / baseSize nbr = nbr / baseSize
} }
for j := len(result) - 1; j >= 0; j-- { for j := len(result) - 1; j >= 0; j-- {
z01.PrintRune(result[j]) fmt.Printf("%c", result[j])
} }
} }
func main() { func main() {
if len(os.Args) != 2 { if len(os.Args) != 2 {
z01.PrintRune('\n') fmt.Println()
} else { } else {
nbr, _ := strconv.Atoi(os.Args[1]) nbr, _ := strconv.Atoi(os.Args[1])
if nbr != 0 { if nbr != 0 {
printBase(nbr, "0123456789abcdef") printBase(nbr, "0123456789abcdef")
z01.PrintRune('\n') fmt.Println()
} else { } else {
fmt.Println(0) fmt.Println(0)
} }

8
tests/go/prog/raid2/main.go

@ -3,20 +3,18 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"github.com/01-edu/z01"
) )
// Prints in standard output the sudoku board // Prints in standard output the sudoku board
func printBoard(board [][]rune) { func printBoard(board [][]rune) {
for _, row := range board { for _, row := range board {
for i, e := range row { for i, e := range row {
z01.PrintRune(e) fmt.Printf("%c", e)
if i != len(row)-1 { if i != len(row)-1 {
z01.PrintRune(' ') fmt.Print(" ")
} }
} }
z01.PrintRune('\n') fmt.Println()
} }
} }

9
tests/go/prog/repeatalpha/main.go

@ -1,23 +1,22 @@
package main package main
import ( import (
"fmt"
"os" "os"
"unicode" "unicode"
"github.com/01-edu/z01"
) )
func main() { func main() {
if len(os.Args) == 2 { if len(os.Args) == 2 {
for _, r := range os.Args[1] { for _, r := range os.Args[1] {
z01.PrintRune(r) fmt.Printf("%c", r)
if unicode.IsLetter(r) { if unicode.IsLetter(r) {
rep := unicode.ToLower(r) - 'a' rep := unicode.ToLower(r) - 'a'
for i := 0; i < int(rep); i++ { for i := 0; i < int(rep); i++ {
z01.PrintRune(r) fmt.Printf("%c", r)
} }
} }
} }
z01.PrintRune('\n') fmt.Println()
} }
} }

7
tests/go/prog/rot13/main.go

@ -1,9 +1,8 @@
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/01-edu/z01"
) )
func main() { func main() {
@ -22,8 +21,8 @@ func main() {
r += 13 r += 13
} }
} }
z01.PrintRune(r) fmt.Printf("%c", r)
} }
z01.PrintRune('\n') fmt.Println()
} }
} }

7
tests/go/prog/uniqueoccurences/main.go

@ -1,9 +1,8 @@
package main package main
import ( import (
"fmt"
"os" "os"
"github.com/01-edu/z01"
) )
func solve(str string) bool { func solve(str string) bool {
@ -23,14 +22,14 @@ func solve(str string) bool {
func print(str string) { func print(str string) {
for _, v := range str { for _, v := range str {
z01.PrintRune(v) fmt.Printf("%c", v)
} }
} }
func main() { func main() {
args := os.Args[1:] args := os.Args[1:]
if len(args) != 1 { if len(args) != 1 {
z01.PrintRune('\n') fmt.Println()
return return
} }
result := solve(args[0]) result := solve(args[0])

6
tests/go/prog/ztail/main.go

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"github.com/01-edu/z01"
) )
func numberOfBytes(args []string) (int, []string) { func numberOfBytes(args []string) (int, []string) {
@ -77,11 +75,11 @@ func main() {
} }
for _, c := range read { for _, c := range read {
z01.PrintRune(rune(c)) fmt.Printf("%c", rune(c))
} }
if j < len(files)-1 { if j < len(files)-1 {
z01.PrintRune('\n') fmt.Println()
} }
fi.Close() fi.Close()

Loading…
Cancel
Save