Browse Source

Fix mistakes

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
c1ab86c5ca
  1. 23
      tests/go/prog/correct/fixthemain/main.go
  2. 4
      tests/go/prog/correct/grouping/main.go
  3. 23
      tests/go/prog/correct/isanagram/main.go
  4. 25
      tests/go/prog/correct/pilot/main.go
  5. 9
      tests/go/prog/correct/robottoorigin/main.go
  6. 7
      tests/go/prog/correct/switchcase/main.go

23
tests/go/prog/correct/fixthemain/main.go

@ -1,38 +1,33 @@
package main
import "github.com/01-edu/z01"
import "fmt"
const CLOSE = 0
const OPEN = 1
const (
CLOSE = iota
OPEN
)
type Door struct {
State int
}
func PrintStr(s string) {
for _, r := range s {
z01.PrintRune(r)
}
z01.PrintRune('\n')
}
func CloseDoor(ptrDoor *Door) {
PrintStr("Door Closing...")
fmt.Println("Door Closing...")
ptrDoor.State = CLOSE
}
func OpenDoor(ptrdoor *Door) {
PrintStr("Door Opening...")
fmt.Println("Door Opening...")
ptrdoor.State = OPEN
}
func IsDoorOpened(ptrDoor *Door) bool {
PrintStr("is the Door opened ?")
fmt.Println("is the Door opened ?")
return ptrDoor.State == OPEN
}
func IsDoorClosed(ptrDoor *Door) bool {
PrintStr("is the Door closed ?")
fmt.Println("is the Door closed ?")
return ptrDoor.State == CLOSE
}

4
tests/go/prog/correct/grouping/main.go

@ -45,10 +45,10 @@ func brackets(regexp, text string) {
runes = runes[1 : len(runes)-1]
result := simpleSearch(runes, text)
for i, s := range result {
if !unicode.Is(unicode.Hex_Digit, s[len(s)-1]) {
if !unicode.Is(unicode.Hex_Digit, rune(s[len(s)-1])) {
s = s[:len(s)-1]
}
if !unicode.Is(unicode.Hex_Digit, s[0]) {
if !unicode.Is(unicode.Hex_Digit, rune(s[0])) {
s = s[1:]
}
fmt.Printf("%d: %s\n", i+1, s)

23
tests/go/prog/correct/isanagram/main.go

@ -1,23 +0,0 @@
package main
func IsAnagram(s, t string) bool {
alph := make([]int, 26)
for i := 0; i < len(s); i++ {
if s[i] < 'a' || s[i] > 'z' {
continue
}
alph[s[i]-'a']++
}
for i := 0; i < len(t); i++ {
if t[i] < 'a' || t[i] > 'z' {
continue
}
alph[t[i]-'a']--
}
for i := 0; i < 26; i++ {
if alph[i] != 0 {
return false
}
}
return true
}

25
tests/go/prog/correct/pilot/main.go

@ -1,17 +1,22 @@
package main
import (
"fmt"
import "fmt"
student ".."
)
type Pilot struct {
Name string
Life float32
Age int
Aircraft int
}
func main() {
var donnie student.Pilot
donnie.Name = "Donnie"
donnie.Life = 100.0
donnie.Age = 24
donnie.Aircraft = student.AIRCRAFT1
const Aircraft1 = 1
func main() {
donnie := Pilot{
Name: "Donnie",
Life: 100.0,
Age: 24,
Aircraft: Aircraft1,
}
fmt.Println(donnie)
}

9
tests/go/prog/correct/robottoorigin/main.go

@ -1,6 +1,9 @@
package main
import "fmt"
import (
"fmt"
"os"
)
func solve(s string) bool {
x := 0
@ -22,7 +25,7 @@ func solve(s string) bool {
}
func main() {
if len(args) == 2 {
fmt.Println(solve(args[1]))
if len(os.Args) == 2 {
fmt.Println(solve(os.Args[1]))
}
}

7
tests/go/prog/correct/switchcase/main.go

@ -9,13 +9,14 @@ import (
func main() {
if len(os.Args) == 2 {
s := os.Args[1]
runes := []rune(s)
for i, r := range s {
if unicode.IsLower(r) {
s[i] = unicode.ToUpper(r)
runes[i] = unicode.ToUpper(r)
} else if unicode.IsUpper(r) {
s[i] = unicode.ToLower(r)
runes[i] = unicode.ToLower(r)
}
}
fmt.Println(s)
fmt.Println(string(runes))
}
}

Loading…
Cancel
Save