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

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

@ -1,33 +1,14 @@
package main
import (
"fmt"
"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() {
EvenMsg := "I have an even number of arguments"
OddMsg := "I have an odd number of arguments"
lenOfArg := len(os.Args) - 1
if isEven(lenOfArg) {
printStr(EvenMsg)
if len(os.Args)-1%2 == 0 {
fmt.Println("I have an even number of arguments")
} 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
import (
"fmt"
"os"
"github.com/01-edu/z01"
)
const SIZE = 2048
@ -34,7 +33,7 @@ func main() {
arby[pos]--
case '.':
// print the pointed byte on std output
z01.PrintRune(rune(arby[pos]))
fmt.Printf("%c", rune(arby[pos]))
case '[':
// go to the matching ']' if the pointed byte is 0 (while start)
openBr = 0

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

@ -1,15 +1,15 @@
package main
import "github.com/01-edu/z01"
import "fmt"
func main() {
diff := 'a' - 'A'
for c := 'a'; c <= 'z'; c++ {
if c%2 == 0 {
z01.PrintRune(c - diff)
fmt.Printf("%c", c-diff)
} 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
import "github.com/01-edu/z01"
import "fmt"
func main() {
diff := 'a' - 'A'
for c := 'z'; c >= 'a'; c-- {
if c%2 == 0 {
z01.PrintRune(c)
fmt.Printf("%c", c)
} 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 (
"fmt"
"os"
"github.com/01-edu/z01"
)
func main() {
if len(os.Args) == 2 {
for i := 0; i < len(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 os.Args[1][i+1] == ' ' {
z01.PrintRune('\n')
fmt.Println()
return
}
}
}
}
z01.PrintRune('\n')
} else {
fmt.Println()
}
}

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

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

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

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

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

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

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

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

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

@ -3,13 +3,23 @@ package main
import (
"fmt"
"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() {
if len(os.Args) != 2 || os.Args[1] == "" {
z01.PrintRune('\n')
fmt.Println()
return
}
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
import (
"fmt"
"os"
"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) {
for i := 0; i < x; i++ {
line := ""
@ -28,20 +20,20 @@ func solve(x, y int) {
line += " "
}
}
printLine(line)
fmt.Println(line)
}
}
func main() {
args := os.Args[1:]
if len(args) != 2 {
printLine("Error")
fmt.Println("Error")
return
}
x, _ := strconv.Atoi(args[1])
y, _ := strconv.Atoi(args[0])
if x <= 0 || y <= 0 {
printLine("Error")
fmt.Println("Error")
return
}
solve(x, y)

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

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

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

@ -3,20 +3,18 @@ package main
import (
"fmt"
"os"
"github.com/01-edu/z01"
)
// Prints in standard output the sudoku board
func printBoard(board [][]rune) {
for _, row := range board {
for i, e := range row {
z01.PrintRune(e)
fmt.Printf("%c", e)
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
import (
"fmt"
"os"
"unicode"
"github.com/01-edu/z01"
)
func main() {
if len(os.Args) == 2 {
for _, r := range os.Args[1] {
z01.PrintRune(r)
fmt.Printf("%c", r)
if unicode.IsLetter(r) {
rep := unicode.ToLower(r) - 'a'
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
import (
"fmt"
"os"
"github.com/01-edu/z01"
)
func main() {
@ -22,8 +21,8 @@ func main() {
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
import (
"fmt"
"os"
"github.com/01-edu/z01"
)
func solve(str string) bool {
@ -23,14 +22,14 @@ func solve(str string) bool {
func print(str string) {
for _, v := range str {
z01.PrintRune(v)
fmt.Printf("%c", v)
}
}
func main() {
args := os.Args[1:]
if len(args) != 1 {
z01.PrintRune('\n')
fmt.Println()
return
}
result := solve(args[0])

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

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

Loading…
Cancel
Save