Browse Source

🎵 Le reEEEfactOOOOr est touJOUUUrs plUUS fOOORT 🎶

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
cb053ae190
  1. 2
      docs/addition_of_exercise_draft.md
  2. 2
      go/lib/is/is.go
  3. 20
      go/lib/lib.go
  4. 25
      go/tests/addprimesum/correct/main.go
  5. 24
      go/tests/addprimesum/main.go
  6. 5
      go/tests/any/main.go
  7. 3
      go/tests/appendrange/main.go
  8. 17
      go/tests/balancedstring/correct/main.go
  9. 9
      go/tests/basicjoin/main.go
  10. 4
      go/tests/brackets/correct/main.go
  11. 11
      go/tests/collatzcountdown/main.go
  12. 4
      go/tests/comcheck/correct/main.go
  13. 38
      go/tests/compact/main.go
  14. 6
      go/tests/compare/main.go
  15. 8
      go/tests/concat/main.go
  16. 4
      go/tests/costumeprofit/correct/main.go
  17. 31
      go/tests/costumeprofit/main.go
  18. 7
      go/tests/countdown/correct/main.go
  19. 34
      go/tests/countif/main.go
  20. 12
      go/tests/displaya/main.go
  21. 10
      go/tests/displayalpham/correct/main.go
  22. 10
      go/tests/displayalrevm/correct/main.go
  23. 11
      go/tests/displayfirstparam/main.go
  24. 10
      go/tests/displaylastparam/main.go
  25. 11
      go/tests/displayz/main.go
  26. 5
      go/tests/divmod/main.go
  27. 63
      go/tests/doop/correct/main.go
  28. 6
      go/tests/doppelganger/main.go
  29. 12
      go/tests/eightqueens/main.go
  30. 19
      go/tests/enigma/main.go
  31. 24
      go/tests/expandstr/correct/main.go
  32. 9
      go/tests/fib/main.go
  33. 13
      go/tests/fibonacci/main.go
  34. 3
      go/tests/findnextprime/main.go
  35. 4
      go/tests/findprevprime/main.go
  36. 15
      go/tests/firstword/correct/main.go
  37. 8
      go/tests/game23/main.go
  38. 21
      go/tests/gcd/correct/main.go
  39. 6
      go/tests/gcd/main.go
  40. 2
      go/tests/grouping/correct/main.go
  41. 10
      go/tests/issorted/main.go
  42. 7
      go/tests/itoa/main.go
  43. 18
      go/tests/map/main.go
  44. 47
      go/tests/nbrconvertalpha/correct/main.go
  45. 31
      go/tests/piglatin/correct/main.go
  46. 5
      go/tests/printalphabet/correct/main.go
  47. 21
      go/tests/printbits/main.go
  48. 4
      go/tests/printchessboard/correct/main.go
  49. 30
      go/tests/printchessboard/main.go
  50. 5
      go/tests/printcomb/main.go
  51. 11
      go/tests/printcomb2/main.go
  52. 5
      go/tests/printdigits/correct/main.go
  53. 27
      go/tests/printhex/correct/main.go
  54. 9
      go/tests/printhex/main.go
  55. 12
      go/tests/printmemory/main.go
  56. 9
      go/tests/printnbr/main.go
  57. 2
      go/tests/printprogramname/main.go
  58. 18
      go/tests/printrevcomb/correct/main.go
  59. 5
      go/tests/printreversealphabet/correct/main.go
  60. 9
      go/tests/printstr/main.go
  61. 7
      go/tests/printwordstables/main.go
  62. 5
      go/tests/priorprime/main.go
  63. 29
      go/tests/range/correct/main.go
  64. 2
      go/tests/reachablenumber/main.go
  65. 4
      go/tests/rectangle/correct/main.go
  66. 2
      go/tests/recursivefactorial/main.go
  67. 4
      go/tests/recursivepower/main.go
  68. 4
      go/tests/reduceint/main.go
  69. 36
      go/tests/reverserange/correct/main.go
  70. 34
      go/tests/reversestrcap/correct/main.go
  71. 3
      go/tests/reversestrcap/main.go
  72. 36
      go/tests/revivethreenums/main.go
  73. 10
      go/tests/revwstr/correct/main.go
  74. 2
      go/tests/romannumbers/correct/main.go
  75. 4
      go/tests/rostring/correct/main.go
  76. 36
      go/tests/rotatevowels/correct/main.go
  77. 12
      go/tests/rotatevowels/main.go
  78. 94
      go/tests/rpncalc/correct/main.go
  79. 8
      go/tests/slice/main.go
  80. 22
      go/tests/sortwordarr/main.go
  81. 6
      go/tests/split/main.go
  82. 17
      go/tests/splitwhitespaces/main.go
  83. 3
      go/tests/sqrt/main.go
  84. 12
      go/tests/strlen/main.go
  85. 4
      go/tests/swap/main.go
  86. 5
      go/tests/switchcase/correct/main.go
  87. 4
      go/tests/tabmult/correct/main.go
  88. 11
      go/tests/tolower/main.go
  89. 13
      go/tests/toupper/main.go
  90. 16
      go/tests/trimatoi/main.go
  91. 6
      go/tests/ultimatedivmod/main.go
  92. 4
      go/tests/ultimatepointone/main.go
  93. 33
      go/tests/union/correct/main.go
  94. 24
      go/tests/union/main.go
  95. 28
      go/tests/uniqueoccurences/correct/main.go
  96. 35
      go/tests/unmatch/main.go
  97. 27
      go/tests/wdmatch/correct/main.go
  98. 2
      subjects/balancedstring.en.md
  99. 2
      subjects/displaya.en.md
  100. 2
      subjects/displayfirstparam.en.md
  101. Some files were not shown because too many files changed in this diff diff.show_more

2
docs/addition_of_exercise_draft.md

@ -50,7 +50,7 @@ Write a program that takes a positive `int` and displays its prime factors, foll
- Factors must be displayed in ascending order and separated by `*`. <span style="color:#ff3234">(formating requirement) </span> - Factors must be displayed in ascending order and separated by `*`. <span style="color:#ff3234">(formating requirement) </span>
- If the number of parameters is different from 1, the program displays a newline. <span style="color:#ff3234">(special case requirement, this case will need to be tested)</span> - If the number of arguments is different from 1, the program displays a newline. <span style="color:#ff3234">(special case requirement, this case will need to be tested)</span>
- The input, when there is one, will always be valid. <span style="color:#ff3234">(Clarification on what the tester will do, hence giving the student guidelines on the cases to be handled, the tests have to reflect this instruction as well)</span> - The input, when there is one, will always be valid. <span style="color:#ff3234">(Clarification on what the tester will do, hence giving the student guidelines on the cases to be handled, the tests have to reflect this instruction as well)</span>

2
go/lib/is/is.go

@ -25,7 +25,7 @@ func Lower(s string) bool {
func Upper(s string) bool { func Upper(s string) bool {
for _, r := range s { for _, r := range s {
if !(r >= 'A' && r <= 'Z') { if !unicode.IsUpper(r) {
return false return false
} }
} }

20
go/lib/lib.go

@ -150,11 +150,10 @@ func RandRune() rune {
r := table.R32[rand.Intn(len(table.R32))] r := table.R32[rand.Intn(len(table.R32))]
n := uint32(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1)) n := uint32(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1))
return rune(r.Lo + n*r.Stride) return rune(r.Lo + n*r.Stride)
} else {
r := table.R16[rand.Intn(len(table.R16))]
n := uint16(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1))
return rune(r.Lo + n*r.Stride)
} }
r := table.R16[rand.Intn(len(table.R16))]
n := uint16(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1))
return rune(r.Lo + n*r.Stride)
} }
// RandStr returns a string with l random characters taken from chars. // RandStr returns a string with l random characters taken from chars.
@ -407,4 +406,17 @@ func ChallengeMain(exercise string, args ...string) {
} }
} }
// GCD returns greatest common divisor of a and b.
func GCD(a, b int) int {
for a != b {
if a > b {
a -= b
} else {
b -= a
}
}
return a
}
// TODO: check unhandled errors on all solutions (it should contains "ERROR" on the first line to prove we correctly handle the error) // TODO: check unhandled errors on all solutions (it should contains "ERROR" on the first line to prove we correctly handle the error)
// TODO: remove the number of rand functions, refactor test cases (aka "table")

25
go/tests/addprimesum/correct/main.go

@ -4,28 +4,9 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
)
func isPrime(nb int) bool {
if nb <= 0 || nb == 1 {
return false
}
if nb <= 3 {
return true
}
if nb%2 == 0 || nb%3 == 0 {
return false
}
i := 5 "github.com/01-edu/public/go/lib/is"
for i*i <= nb { )
if nb%i == 0 || nb%(i+2) == 0 {
return false
}
i += 6
}
return true
}
func main() { func main() {
if len(os.Args) != 2 { if len(os.Args) != 2 {
@ -38,7 +19,7 @@ func main() {
} else { } else {
result := 0 result := 0
for ; argument >= 0; argument-- { for ; argument >= 0; argument-- {
if isPrime(argument) { if is.Prime(argument) {
result += argument result += argument
} }
} }

24
go/tests/addprimesum/main.go

@ -4,36 +4,16 @@ import (
"strconv" "strconv"
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
"github.com/01-edu/public/go/lib/is"
) )
func isAPrime(nb int) bool {
if nb <= 0 || nb == 1 {
return false
}
if nb <= 3 {
return true
}
if nb%2 == 0 || nb%3 == 0 {
return false
}
i := 5
for i*i <= nb {
if nb%i == 0 || nb%(i+2) == 0 {
return false
}
i += 6
}
return true
}
func main() { func main() {
// adds random numbers // adds random numbers
table := lib.MultRandIntBetween(1, 10000) table := lib.MultRandIntBetween(1, 10000)
// fill with all prime numbers between 0 and 100 // fill with all prime numbers between 0 and 100
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
if isAPrime(i) { if is.Prime(i) {
table = append(table, i) table = append(table, i)
} }
} }

5
go/tests/any/main.go

@ -6,13 +6,12 @@ import (
"github.com/01-edu/public/go/lib/is" "github.com/01-edu/public/go/lib/is"
) )
func any(f func(string) bool, arr []string) bool { func any(f func(string) bool, a []string) bool {
for _, el := range arr { for _, el := range a {
if f(el) { if f(el) {
return true return true
} }
} }
return false return false
} }

3
go/tests/appendrange/main.go

@ -8,15 +8,12 @@ import (
func appendRange(min, max int) []int { func appendRange(min, max int) []int {
size := max - min size := max - min
answer := []int{} answer := []int{}
if size <= 0 { if size <= 0 {
return nil return nil
} }
for i := min; i < max; i++ { for i := min; i < max; i++ {
answer = append(answer, i) answer = append(answer, i)
} }
return answer return answer
} }

17
go/tests/balancedstring/correct/main.go

@ -6,12 +6,11 @@ import (
) )
func solve(str string) int { func solve(str string) int {
var count int = 0 var count, countC, countD int
var countC, countD int for _, r := range str {
for i := 0; i < len(str); i++ { if r == 'C' {
if str[i] == 'C' {
countC++ countC++
} else if str[i] == 'D' { } else if r == 'D' {
countD++ countD++
} }
if countC == countD { if countC == countD {
@ -25,10 +24,8 @@ func solve(str string) int {
func main() { func main() {
args := os.Args[1:] args := os.Args[1:]
if len(args) != 1 { if len(args) == 1 {
fmt.Println() result := solve(args[0])
return fmt.Println(result)
} }
result := solve(args[0])
fmt.Println(result)
} }

9
go/tests/basicjoin/main.go

@ -1,15 +1,14 @@
package main package main
import ( import (
"strings"
"./student" "./student"
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func basicJoin(a []string) (b string) { func basicJoin(elems []string) string {
for _, s := range a { return strings.Join(elems, "")
b += s
}
return b
} }
func main() { func main() {

4
go/tests/brackets/correct/main.go

@ -6,10 +6,10 @@ import (
) )
func matchBrackets(exp string) bool { func matchBrackets(exp string) bool {
rn := []rune(exp) runes := []rune(exp)
var opened []rune var opened []rune
ptr := -1 ptr := -1
for _, c := range rn { for _, c := range runes {
if c == '(' || c == '[' || c == '{' { if c == '(' || c == '[' || c == '{' {
opened = append(opened, c) opened = append(opened, c)
ptr++ ptr++

11
go/tests/collatzcountdown/main.go

@ -25,12 +25,11 @@ func collatzCountdown(start int) int {
} }
func main() { func main() {
args := []int{lib.RandIntBetween(-6, 20)} args := append(lib.MultRandIntBetween(2, 20),
args = append(args, -5, 0) lib.RandIntBetween(-6, 20),
for i := 0; i < 20; i++ { -5,
args = append(args, lib.RandIntBetween(2, 20)) 0,
} )
for _, v := range args { for _, v := range args {
lib.Challenge("CollatzCountdown", student.CollatzCountdown, collatzCountdown, v) lib.Challenge("CollatzCountdown", student.CollatzCountdown, collatzCountdown, v)
} }

4
go/tests/comcheck/correct/main.go

@ -8,9 +8,9 @@ import (
func main() { func main() {
safeWords := []string{"01", "galaxy", "galaxy 01"} safeWords := []string{"01", "galaxy", "galaxy 01"}
count := 0 count := 0
for i := 1; i < len(os.Args); i++ { for _, arg := range os.Args[1:] {
for _, s := range safeWords { for _, s := range safeWords {
if os.Args[i] == s { if s == arg {
count++ count++
} }
} }

38
go/tests/compact/main.go

@ -24,43 +24,43 @@ func main() {
arg := [][]string{{"hello", "", "hi", "", "salut", "", ""}} arg := [][]string{{"hello", "", "hi", "", "salut", "", ""}}
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
n := lib.RandIntBetween(5, 20) // random size of the slice n := lib.RandIntBetween(5, 20)
orig := make([]string, n) // slice with the original value orig := make([]string, n)
num_pos := lib.RandIntBetween(1, n-1) // random number of positions to be written numPos := lib.RandIntBetween(1, n-1)
for i := 0; i < num_pos; i++ { for i := 0; i < numPos; i++ {
word := lib.RandWords() // random string value word := lib.RandWords()
rand_pos := lib.RandIntBetween(0, n-1) // random position in the slice randPos := lib.RandIntBetween(0, n-1)
orig[rand_pos] = word orig[randPos] = word
} }
arg = append(arg, orig) arg = append(arg, orig)
} }
for _, v := range arg { for _, v := range arg {
sli_sol := make([]string, len(arg)) // slice to apply the solution function solSlice := make([]string, len(arg))
sli_stu := make([]string, len(arg)) // slice to apply the student function stuSlice := make([]string, len(arg))
copy(sli_sol, v) copy(solSlice, v)
copy(sli_stu, v) copy(stuSlice, v)
sol_size := compact(&sli_sol) solSize := compact(&solSlice)
stu_size := student.Compact(&sli_stu) stuSize := student.Compact(&stuSlice)
if !reflect.DeepEqual(sli_stu, sli_sol) { if !reflect.DeepEqual(stuSlice, solSlice) {
lib.Fatalf("Produced slice: %v, instead of %v\n", lib.Fatalf("Produced slice: %v, instead of %v\n",
sli_stu, stuSlice,
sli_sol, solSlice,
) )
} }
if sol_size != stu_size { if solSize != stuSize {
lib.Fatalf("%s(%v) == %v instead of %v\n", lib.Fatalf("%s(%v) == %v instead of %v\n",
"Compact", "Compact",
v, v,
sli_stu, stuSlice,
sli_sol, solSlice,
) )
} }
} }

6
go/tests/compare/main.go

@ -7,10 +7,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func compare(a, b string) int {
return strings.Compare(a, b)
}
func main() { func main() {
type node struct { type node struct {
s string s string
@ -49,6 +45,6 @@ func main() {
) )
for _, arg := range table { for _, arg := range table {
lib.Challenge("Compare", student.Compare, compare, arg.s, arg.toCompare) lib.Challenge("Compare", student.Compare, strings.Compare, arg.s, arg.toCompare)
} }
} }

8
go/tests/concat/main.go

@ -1,14 +1,12 @@
package main package main
import ( import (
"fmt"
"./student" "./student"
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func concat(a, b string) string {
return a + b
}
func main() { func main() {
table := [][]string{} table := [][]string{}
@ -21,6 +19,6 @@ func main() {
[]string{"Hello!", " How are you?"}, []string{"Hello!", " How are you?"},
) )
for _, arg := range table { for _, arg := range table {
lib.Challenge("Concat", student.Concat, concat, arg[0], arg[1]) lib.Challenge("Concat", student.Concat, fmt.Sprint, arg[0], arg[1])
} }
} }

4
go/tests/costumeprofit/correct/main.go

@ -26,7 +26,7 @@ func max(numbers ...int) int {
return max return max
} }
func Costume_profit(a, b, c, d, e, f int) int { func costumeProfit(a, b, c, d, e, f int) int {
if d == min(a, b, c, d) { if d == min(a, b, c, d) {
return d * max(e, f) return d * max(e, f)
} }
@ -51,5 +51,5 @@ func main() {
e, _ := strconv.Atoi(args[4]) e, _ := strconv.Atoi(args[4])
f, _ := strconv.Atoi(args[5]) f, _ := strconv.Atoi(args[5])
fmt.Println(Costume_profit(a, b, c, d, e, f)) fmt.Println(costumeProfit(a, b, c, d, e, f))
} }

31
go/tests/costumeprofit/main.go

@ -6,30 +6,15 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
type node struct {
A, B, C, D, E, F int
}
func main() { func main() {
table := []node{}
for i := 0; i < 25; i++ { for i := 0; i < 25; i++ {
a := lib.RandIntBetween(0, 1000) lib.ChallengeMain("costumeprofit",
b := lib.RandIntBetween(0, 1000) strconv.Itoa(lib.RandIntBetween(0, 1000)),
c := lib.RandIntBetween(0, 1000) strconv.Itoa(lib.RandIntBetween(0, 1000)),
d := lib.RandIntBetween(0, 1000) strconv.Itoa(lib.RandIntBetween(0, 1000)),
e := lib.RandIntBetween(0, 1000) strconv.Itoa(lib.RandIntBetween(0, 1000)),
f := lib.RandIntBetween(0, 1000) strconv.Itoa(lib.RandIntBetween(0, 1000)),
table = append(table, node{a, b, c, d, e, f}) strconv.Itoa(lib.RandIntBetween(0, 1000)),
} )
for _, arg := range table {
a := strconv.Itoa(arg.A)
b := strconv.Itoa(arg.B)
c := strconv.Itoa(arg.C)
d := strconv.Itoa(arg.D)
e := strconv.Itoa(arg.E)
f := strconv.Itoa(arg.F)
lib.ChallengeMain("costumeprofit", a, b, c, d, e, f)
} }
} }

7
go/tests/countdown/correct/main.go

@ -3,10 +3,5 @@ package main
import "fmt" import "fmt"
func main() { func main() {
count := 9 fmt.Println(9876543210)
for count != -1 {
fmt.Print(count)
count--
}
fmt.Println()
} }

34
go/tests/countif/main.go

@ -6,9 +6,9 @@ import (
"github.com/01-edu/public/go/lib/is" "github.com/01-edu/public/go/lib/is"
) )
func countIf(f func(string) bool, arr []string) int { func countIf(f func(string) bool, a []string) int {
counter := 0 counter := 0
for _, el := range arr { for _, el := range a {
if f(el) { if f(el) {
counter++ counter++
} }
@ -21,8 +21,8 @@ func main() {
functions := []func(string) bool{is.Digit, is.Lower, is.Upper} functions := []func(string) bool{is.Digit, is.Lower, is.Upper}
type node struct { type node struct {
f func(string) bool f func(string) bool
arr []string a []string
} }
table := []node{} table := []node{}
@ -30,46 +30,46 @@ func main() {
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
function := functions[lib.RandIntBetween(0, len(functions)-1)] function := functions[lib.RandIntBetween(0, len(functions)-1)]
val := node{ val := node{
f: function, f: function,
arr: lib.MultRandWords(), a: lib.MultRandWords(),
} }
table = append(table, val) table = append(table, val)
} }
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
val := node{ val := node{
f: is.Digit, f: is.Digit,
arr: lib.MultRandDigit(), a: lib.MultRandDigit(),
} }
table = append(table, val) table = append(table, val)
} }
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
val := node{ val := node{
f: is.Lower, f: is.Lower,
arr: lib.MultRandLower(), a: lib.MultRandLower(),
} }
table = append(table, val) table = append(table, val)
} }
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
val := node{ val := node{
f: is.Upper, f: is.Upper,
arr: lib.MultRandUpper(), a: lib.MultRandUpper(),
} }
table = append(table, val) table = append(table, val)
} }
table = append(table, table = append(table,
node{ node{
f: is.Digit, f: is.Digit,
arr: []string{"Hello", "how", "are", "you"}, a: []string{"Hello", "how", "are", "you"},
}, },
node{ node{
f: is.Digit, f: is.Digit,
arr: []string{"This", "is", "4", "you"}, a: []string{"This", "is", "4", "you"},
}, },
) )
for _, arg := range table { for _, arg := range table {
lib.Challenge("CountIf", student.CountIf, countIf, arg.f, arg.arr) lib.Challenge("CountIf", student.CountIf, countIf, arg.f, arg.a)
} }
} }

12
go/tests/displaya/main.go

@ -7,14 +7,14 @@ import (
) )
func main() { func main() {
table := append(lib.MultRandWords(), "dsfda") table := append(lib.MultRandWords(),
table = append(table, "") "dsfda",
table = append(table, "1") "",
table = append(table, "1") "1",
"1",
)
for _, s := range table { for _, s := range table {
lib.ChallengeMain("displaya", strings.Fields(s)...) lib.ChallengeMain("displaya", strings.Fields(s)...)
} }
lib.ChallengeMain("displaya", "1", "a") lib.ChallengeMain("displaya", "1", "a")
} }

10
go/tests/displayalpham/correct/main.go

@ -3,13 +3,5 @@ package main
import "fmt" import "fmt"
func main() { func main() {
diff := 'a' - 'A' fmt.Println("aBcDeFgHiJkLmNoPqRsTuVwXyZ")
for c := 'a'; c <= 'z'; c++ {
if c%2 == 0 {
fmt.Printf("%c", c-diff)
} else {
fmt.Printf("%c", c)
}
}
fmt.Println()
} }

10
go/tests/displayalrevm/correct/main.go

@ -3,13 +3,5 @@ package main
import "fmt" import "fmt"
func main() { func main() {
diff := 'a' - 'A' fmt.Println("zYxWvUtSrQpOnMlKjIhGfEdCbA")
for c := 'z'; c >= 'a'; c-- {
if c%2 == 0 {
fmt.Printf("%c", c)
} else {
fmt.Printf("%c", c-diff)
}
}
fmt.Println()
} }

11
go/tests/displayfirstparam/main.go

@ -7,11 +7,12 @@ import (
) )
func main() { func main() {
table := append(lib.MultRandWords(), " ") table := append(lib.MultRandWords(),
table = append(table, "1") " ",
table = append(table, "1 2") "1",
table = append(table, "1 2 3") "1 2",
"1 2 3",
)
for _, s := range table { for _, s := range table {
lib.ChallengeMain("displayfirstparam", strings.Fields(s)...) lib.ChallengeMain("displayfirstparam", strings.Fields(s)...)
} }

10
go/tests/displaylastparam/main.go

@ -7,10 +7,12 @@ import (
) )
func main() { func main() {
table := append(lib.MultRandWords(), " ") table := append(lib.MultRandWords(),
table = append(table, "1") " ",
table = append(table, "1 2") "1",
"1 2",
"1 2 3",
)
for _, s := range table { for _, s := range table {
lib.ChallengeMain("displaylastparam", strings.Fields(s)...) lib.ChallengeMain("displaylastparam", strings.Fields(s)...)
} }

11
go/tests/displayz/main.go

@ -7,11 +7,12 @@ import (
) )
func main() { func main() {
table := append(lib.MultRandWords(), "dsfdz") table := append(lib.MultRandWords(),
table = append(table, "") "dsfdz",
table = append(table, "1") "",
table = append(table, "1") "1",
"1",
)
for _, s := range table { for _, s := range table {
lib.ChallengeMain("displayz", strings.Fields(s)...) lib.ChallengeMain("displayz", strings.Fields(s)...)
} }

5
go/tests/divmod/main.go

@ -5,11 +5,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func DivMod(a, b int, div, mod *int) {
*div = a / b
*mod = a % b
}
func main() { func main() {
i := 0 i := 0
for i < lib.SliceLen { for i < lib.SliceLen {

63
go/tests/doop/correct/main.go

@ -8,50 +8,51 @@ import (
func main() { func main() {
if len(os.Args) == 4 { if len(os.Args) == 4 {
var result int a, err := strconv.Atoi(os.Args[1])
firstArg, err := strconv.Atoi(os.Args[1])
if err != nil { if err != nil {
fmt.Println(0) fmt.Println(0)
return return
} }
b, err := strconv.Atoi(os.Args[3])
operator := os.Args[2] if err != nil {
secondArg, err1 := strconv.Atoi(os.Args[3])
if err1 != nil {
fmt.Println(0) fmt.Println(0)
return return
} }
operator := os.Args[2]
if secondArg == 0 && operator == "/" { switch operator {
fmt.Println("No division by 0") case "+":
return result := a + b
} else if secondArg == 0 && operator == "%" { if (result > a) != (b > 0) {
fmt.Println("No modulo by 0")
return
} else if operator == "+" {
result = firstArg + secondArg
if !((result > firstArg) == (secondArg > 0)) {
fmt.Println(0) fmt.Println(0)
return } else {
fmt.Println(result)
} }
} else if operator == "-" { case "-":
result = firstArg - secondArg result := a - b
if !((result < firstArg) == (secondArg > 0)) { if (result < a) != (b > 0) {
fmt.Println(0) fmt.Println(0)
return } else {
fmt.Println(result)
} }
} else if operator == "/" { case "*":
result = firstArg / secondArg result := a * b
} else if operator == "*" { if a != 0 && (result/a != b) {
result = firstArg * secondArg
if firstArg != 0 && (result/firstArg != secondArg) {
fmt.Println(0) fmt.Println(0)
return } else {
fmt.Println(result)
}
case "/":
if b == 0 {
fmt.Println("No division by 0")
} else {
fmt.Println(a / b)
}
case "%":
if b == 0 {
fmt.Println("No modulo by 0")
} else {
fmt.Println(a % b)
} }
} else if operator == "%" {
result = firstArg % secondArg
} }
fmt.Println(result)
} }
} }

6
go/tests/doppelganger/main.go

@ -7,10 +7,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func doppelGanger(s, substr string) int {
return strings.LastIndex(s, substr)
}
type node struct { type node struct {
big, little string big, little string
} }
@ -52,6 +48,6 @@ func main() {
} }
for _, arg := range table { for _, arg := range table {
lib.Challenge("DoppelGanger", student.DoppelGanger, doppelGanger, arg.big, arg.little) lib.Challenge("DoppelGanger", student.DoppelGanger, strings.LastIndex, arg.big, arg.little)
} }
} }

12
go/tests/eightqueens/main.go

@ -43,17 +43,13 @@ func goodSquare(x, y int) bool {
} }
func printQueens() { func printQueens() {
x := 0 for x := 0; x < size; x++ {
for x < size { for y := 0; y < size; y++ {
y := 0
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
fmt.Printf("%c", rune(y)+'1') fmt.Printf("%c", rune(y)+'1')
} }
y++
} }
x++
} }
fmt.Println() fmt.Println()
} }
@ -61,8 +57,7 @@ func printQueens() {
// 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
// of the solution to the problem // of the solution to the problem
func tryX(x int) { func tryX(x int) {
y := 0 for y := 0; y < size; y++ {
for y < size {
if goodSquare(x, y) { if goodSquare(x, y) {
// Since the square is good for the queen, let's put one on it: // Since the square is good for the queen, let's put one on it:
board[x][y] = true board[x][y] = true
@ -79,7 +74,6 @@ func tryX(x int) {
// remove the queen of the board, to try other y values // remove the queen of the board, to try other y values
board[x][y] = false board[x][y] = false
} }
y++
} }
} }

19
go/tests/enigma/main.go

@ -5,19 +5,8 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
// this function will put a in c; c in d; d in b and b in a
func Enigma(a ***int, b *int, c *******int, d ****int) {
valc := *******c
*******c = ***a
vald := ****d
****d = valc
valb := *b
*b = vald
***a = valb
}
// Helper function used in the test for checking the function Enigma() // Helper function used in the test for checking the function Enigma()
func decript(a ***int, b *int, c *******int, d ****int) { func decrypt(a ***int, b *int, c *******int, d ****int) {
vala := ***a vala := ***a
***a = *******c ***a = *******c
valb := *b valb := *b
@ -28,7 +17,7 @@ func decript(a ***int, b *int, c *******int, d ****int) {
} }
func main() { func main() {
args := append([]int, lib.MultRandIntBetween(2, 20)...) args := lib.MultRandIntBetween(2, 20)
aval := args[0] aval := args[0]
x := args[0] x := args[0]
@ -58,7 +47,7 @@ func main() {
d := &n d := &n
student.Enigma(a, b, c, d) student.Enigma(a, b, c, d)
decript(a, b, c, d) decrypt(a, b, c, d)
if aval != ***a { if aval != ***a {
lib.Fatalf("Expected ***a = %d instead of %d\n", lib.Fatalf("Expected ***a = %d instead of %d\n",
@ -85,5 +74,3 @@ func main() {
) )
} }
} }
// TODO: remove all those pointers...

24
go/tests/expandstr/correct/main.go

@ -6,29 +6,19 @@ import (
"strings" "strings"
) )
func deleteExtraSpaces(arr []string) []string { func deleteExtraSpaces(a []string) (res []string) {
var res []string for _, v := range a {
for _, v := range arr {
if v != "" { if v != "" {
res = append(res, v) res = append(res, v)
} }
} }
return res return
} }
func main() { func main() {
if len(os.Args) != 2 { if len(os.Args) == 2 {
fmt.Println() arg := strings.Split(os.Args[1], " ")
os.Exit(0) arg = deleteExtraSpaces(arg)
fmt.Println(strings.Join(arg, " "))
} }
arg := strings.Split(os.Args[1], " ")
arg = deleteExtraSpaces(arg)
for i, v := range arg {
fmt.Print(v)
if i < len(arg)-1 {
fmt.Print(" ")
}
}
fmt.Println()
} }

9
go/tests/fib/main.go

@ -13,21 +13,18 @@ func fib(n int) int {
t2 := 1 t2 := 1
for i := 2; i <= n; i++ { for i := 2; i <= n; i++ {
t1 += t2 t1 += t2
tmp := t1 t1, t2 = t2, t1
t1 = t2
t2 = tmp
} }
return t2 return t2
} }
func main() { func main() {
table := []int{ table := append(lib.MultRandIntBetween(-100, 150),
20, 20,
0, 0,
9, 9,
2, 2,
} )
table = append(table, lib.MultRandIntBetween(-100, 150)...)
for _, arg := range table { for _, arg := range table {
lib.Challenge("Fib", student.Fib, fib, arg) lib.Challenge("Fib", student.Fib, fib, arg)
} }

13
go/tests/fibonacci/main.go

@ -5,22 +5,21 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func fibonacci(value int) int { func fibonacci(i int) int {
if value < 0 { if i < 0 {
return -1 return -1
} }
if value == 0 { if i == 0 {
return 0 return 0
} }
if value == 1 { if i == 1 {
return 1 return 1
} }
return Fibonacci(value-1) + Fibonacci(value-2) return fibonacci(i-1) + fibonacci(i-2)
} }
func main() { func main() {
table := append( table := append(lib.MultRandIntBetween(0, 25),
lib.MultRandIntBetween(0, 25),
4, 4,
5, 5,
-5, -5,

3
go/tests/findnextprime/main.go

@ -14,8 +14,7 @@ func findNextPrime(nb int) int {
} }
func main() { func main() {
table := append( table := append(lib.MultRandIntBetween(-1000000, 1000000),
lib.MultRandIntBetween(-1000000, 1000000),
0, 0,
1, 1,
2, 2,

4
go/tests/findprevprime/main.go

@ -17,8 +17,8 @@ func findPrevPrime(nb int) int {
} }
func main() { func main() {
a := append(lib.MultRandIntBetween(0, 99999), 5, 4, 1) elems := append(lib.MultRandIntBetween(0, 99999), 5, 4, 1)
for _, elem := range a { for _, elem := range elems {
lib.Challenge("FindPrevPrime", student.FindPrevPrime, findPrevPrime, elem) lib.Challenge("FindPrevPrime", student.FindPrevPrime, findPrevPrime, elem)
} }
} }

15
go/tests/firstword/correct/main.go

@ -3,22 +3,11 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
) )
func main() { func main() {
if len(os.Args) == 2 { if len(os.Args) == 2 {
for i := 0; i < len(os.Args[1]); i++ { fmt.Println(strings.Split(strings.TrimSpace(os.Args[1]), " ")[0])
if 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] == ' ' {
fmt.Println()
return
}
}
}
}
fmt.Println()
} }
} }

8
go/tests/game23/main.go

@ -12,11 +12,11 @@ func game23(a, b int) int {
if a == b { if a == b {
return 0 return 0
} }
if Game23(a*2, b) != -1 { if game23(a*2, b) != -1 {
return 1 + Game23(a*2, b) return 1 + game23(a*2, b)
} }
if Game23(a*3, b) != -1 { if game23(a*3, b) != -1 {
return 1 + Game23(a*3, b) return 1 + game23(a*3, b)
} }
return -1 return -1
} }

21
go/tests/gcd/correct/main.go

@ -4,23 +4,14 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
)
// Greatest common divisor "github.com/01-edu/public/go/lib"
func gcd(num1, num2 int) int { )
for i := num1; i > 0; i-- {
if num1%i == 0 && num2%i == 0 {
return i
}
}
return 1
}
func main() { func main() {
if len(os.Args) != 3 { if len(os.Args) == 3 {
return a, _ := strconv.Atoi(os.Args[1])
b, _ := strconv.Atoi(os.Args[2])
fmt.Println(lib.GCD(a, b))
} }
v1, _ := strconv.Atoi(os.Args[1])
v2, _ := strconv.Atoi(os.Args[2])
fmt.Println(gcd(v1, v2))
} }

6
go/tests/gcd/main.go

@ -15,9 +15,9 @@ func main() {
{"11", "77"}, {"11", "77"},
} }
for i := 0; i < 25; i++ { for i := 0; i < 25; i++ {
number1 := strconv.Itoa(lib.RandIntBetween(1, 100000)) a := strconv.Itoa(lib.RandIntBetween(1, 100000))
number2 := strconv.Itoa(lib.RandIntBetween(1, 100)) b := strconv.Itoa(lib.RandIntBetween(1, 100))
args = append(args, []string{number1, number2}) args = append(args, []string{a, b})
} }
for _, v := range args { for _, v := range args {
lib.ChallengeMain("gcd", v...) lib.ChallengeMain("gcd", v...)

2
go/tests/grouping/correct/main.go

@ -25,7 +25,7 @@ func simpleSearch(runes []rune, text string) []string {
exp := string(runes) exp := string(runes)
var result []string var result []string
if !(strings.ContainsRune(exp, '|')) { if !strings.ContainsRune(exp, '|') {
helper := []string{exp} helper := []string{exp}
result = append(singleSearch(helper, text)) result = append(singleSearch(helper, text))
} else { } else {

10
go/tests/issorted/main.go

@ -7,18 +7,18 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func isSorted(f func(int, int) int, arr []int) bool { func isSorted(f func(int, int) int, a []int) bool {
ascendingOrdered := true ascendingOrdered := true
descendingOrdered := true descendingOrdered := true
for i := 1; i < len(arr); i++ { for i := 1; i < len(a); i++ {
if !(f(arr[i-1], arr[i]) >= 0) { if f(a[i-1], a[i]) < 0 {
ascendingOrdered = false ascendingOrdered = false
} }
} }
for i := 1; i < len(arr); i++ { for i := 1; i < len(a); i++ {
if !(f(arr[i-1], arr[i]) <= 0) { if f(a[i-1], a[i]) > 0 {
descendingOrdered = false descendingOrdered = false
} }
} }

7
go/tests/itoa/main.go

@ -7,13 +7,8 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func itoa(i int) string {
return strconv.Itoa(i)
}
func main() { func main() {
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
arg := lib.RandIntBetween(-2000000000, 2000000000) lib.Challenge("Itoa", student.Itoa, strconv.Itoa, lib.RandInt())
lib.Challenge("Itoa", student.Itoa, itoa, arg)
} }
} }

18
go/tests/map/main.go

@ -10,7 +10,7 @@ func isPositive(i int) bool {
return i > 0 return i > 0
} }
func isNegative0(i int) bool { func isNegative(i int) bool {
return i < 0 return i < 0
} }
@ -25,11 +25,11 @@ func _map(f func(int) bool, a []int) []bool {
} }
func main() { func main() {
functions := []func(int) bool{isPositive, isNegative0, is.Prime} functions := []func(int) bool{isPositive, isNegative, is.Prime}
type node struct { type node struct {
f func(int) bool f func(int) bool
arr []int a []int
} }
table := []node{} table := []node{}
@ -37,18 +37,18 @@ func main() {
for i := 0; i < 15; i++ { for i := 0; i < 15; i++ {
function := functions[lib.RandIntBetween(0, len(functions)-1)] function := functions[lib.RandIntBetween(0, len(functions)-1)]
val := node{ val := node{
f: function, f: function,
arr: lib.MultRandIntBetween(-1000000, 1000000), a: lib.MultRandIntBetween(-1000000, 1000000),
} }
table = append(table, val) table = append(table, val)
} }
table = append(table, node{ table = append(table, node{
f: is.Prime, f: is.Prime,
arr: []int{1, 2, 3, 4, 5, 6}, a: []int{1, 2, 3, 4, 5, 6},
}) })
for _, arg := range table { for _, arg := range table {
lib.Challenge("Map", student.Map, _map, arg.f, arg.arr) lib.Challenge("Map", student.Map, _map, arg.f, arg.a)
} }
} }

47
go/tests/nbrconvertalpha/correct/main.go

@ -4,41 +4,28 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"unicode"
) )
func IsNumeric(s string) bool {
for _, r := range s {
if !unicode.IsDigit(r) {
return false
}
}
return true
}
func main() { func main() {
arguments := os.Args[1:] args := os.Args[1:]
for i := range arguments { if len(args) == 0 {
if IsNumeric(arguments[i]) { return
number, _ := strconv.Atoi(arguments[i]) }
boole := false var upper bool
if os.Args[1] == "--upper" { if args[0] == "--upper" {
boole = true upper = true
} args = args[1:]
}
if number <= 26 && number >= 1 && !boole { for _, arg := range args {
number += 96 if nb, err := strconv.Atoi(arg); err != nil || nb < 1 || nb > 26 {
fmt.Printf("%c", rune(number)) fmt.Print(" ")
} else if number <= 26 && number >= 1 && boole {
number += 64
fmt.Printf("%c", rune(number))
} else {
fmt.Print(" ")
}
} else { } else {
if !(arguments[i] == "--upper" && i == 0) { if upper {
fmt.Print(" ") nb += 'A' - 1
} else {
nb += 'a' - 1
} }
fmt.Printf("%c", rune(nb))
} }
} }
fmt.Println() fmt.Println()

31
go/tests/piglatin/correct/main.go

@ -3,35 +3,18 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
) )
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] == "" {
fmt.Println()
return return
} }
letters := []rune(os.Args[1]) s := os.Args[1]
switch letters[0] { vowel := strings.IndexAny(s, "aeiouAEIOU")
case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U': if vowel == -1 {
fmt.Print(os.Args[1] + "ay\n") fmt.Println("No vowels")
default: } else {
start := firstNotVowel(letters) fmt.Println(string(s[vowel:]) + string(s[:vowel]) + "ay")
if start == 0 {
fmt.Println("No vowels")
} else {
fmt.Print(string(letters[start:]) + string(letters[:start]) + "ay\n")
}
} }
} }

5
go/tests/printalphabet/correct/main.go

@ -3,8 +3,5 @@ package main
import "fmt" import "fmt"
func main() { func main() {
for r := 'a'; r <= 'z'; r++ { fmt.Println("abcdefghijklmnopqrstuvwxyz")
fmt.Print(r)
}
fmt.Println()
} }

21
go/tests/printbits/main.go

@ -8,18 +8,19 @@ import (
) )
func main() { func main() {
var arg []string var args []string
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
arg = append(arg, strconv.Itoa(lib.RandIntBetween(0, 255))) args = append(args, strconv.Itoa(lib.RandIntBetween(0, 255)))
} }
arg = append(arg, "") args = append(args,
arg = append(arg, "a") "",
arg = append(arg, "bc") "a",
arg = append(arg, "def") "bc",
arg = append(arg, "notanumber") "def",
arg = append(arg, lib.RandBasic()) "notanumber",
lib.RandBasic(),
for _, v := range arg { )
for _, v := range args {
lib.ChallengeMain("printbits", strings.Fields(v)...) lib.ChallengeMain("printbits", strings.Fields(v)...)
} }
} }

4
go/tests/printchessboard/correct/main.go

@ -34,7 +34,7 @@ func main() {
y, _ := strconv.Atoi(args[0]) y, _ := strconv.Atoi(args[0])
if x <= 0 || y <= 0 { if x <= 0 || y <= 0 {
fmt.Println("Error") fmt.Println("Error")
return } else {
solve(x, y)
} }
solve(x, y)
} }

30
go/tests/printchessboard/main.go

@ -7,23 +7,21 @@ import (
) )
func main() { func main() {
table := [][]string{} table := [][]string{
{"0", "0"},
table = append(table, {"1", "2"},
[]string{"0", "0"}, {"2"},
[]string{"1", "2"}, {"0"},
[]string{"2"}, {"3", "3"},
[]string{"0"}, {"1", "5"},
[]string{"3", "3"}, {"5", "1"},
[]string{"1", "5"}, {"4", "3"},
[]string{"5", "1"}, }
[]string{"4", "3"},
)
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
number1 := strconv.Itoa(lib.RandIntBetween(1, 200)) table = append(table, []string{
number2 := strconv.Itoa(lib.RandIntBetween(1, 200)) strconv.Itoa(lib.RandIntBetween(1, 200)),
table = append(table, []string{number1, number2}) strconv.Itoa(lib.RandIntBetween(1, 200)),
})
} }
for _, v := range table { for _, v := range table {

5
go/tests/printcomb/main.go

@ -13,13 +13,12 @@ func printComb() {
for k := j + 1; k <= '9'; k++ { for k := j + 1; k <= '9'; k++ {
fmt.Printf("%c%c%c", i, j, k) fmt.Printf("%c%c%c", i, j, k)
if i < '7' { if i < '7' {
fmt.Printf(", ") fmt.Print(", ")
} else {
fmt.Println()
} }
} }
} }
} }
fmt.Println()
} }
func main() { func main() {

11
go/tests/printcomb2/main.go

@ -8,18 +8,13 @@ import (
) )
func printComb2() { func printComb2() {
a := 0 for a := 0; a <= 98; a++ {
b := 1 for b := a + 1; b <= 99; b++ {
for a <= 98 {
b = a + 1
for b <= 99 {
fmt.Printf("%.2d %.2d", a, b) fmt.Printf("%.2d %.2d", a, b)
if !(a == 98 && b == 99) { if a != 98 || b != 99 {
fmt.Print(", ") fmt.Print(", ")
} }
b++
} }
a++
} }
fmt.Println() fmt.Println()
} }

5
go/tests/printdigits/correct/main.go

@ -3,8 +3,5 @@ package main
import "fmt" import "fmt"
func main() { func main() {
for i := '0'; i <= '9'; i++ { fmt.Println("0123456789")
fmt.Printf("%c", i)
}
fmt.Println()
} }

27
go/tests/printhex/correct/main.go

@ -6,31 +6,12 @@ import (
"strconv" "strconv"
) )
func printBase(nbr int, base string) {
var result []rune
typeBase := []rune(base)
baseSize := len(base)
pos := 0
for nbr > 0 {
pos = nbr % baseSize
result = append(result, typeBase[pos])
nbr = nbr / baseSize
}
for j := len(result) - 1; j >= 0; j-- {
fmt.Printf("%c", result[j])
}
}
func main() { func main() {
if len(os.Args) != 2 { if len(os.Args) == 2 {
fmt.Println() if i, err := strconv.Atoi(os.Args[1]); err == nil && i > 0 {
} else { fmt.Printf("%x\n", i)
nbr, _ := strconv.Atoi(os.Args[1])
if nbr != 0 {
printBase(nbr, "0123456789abcdef")
fmt.Println()
} else { } else {
fmt.Println(0) fmt.Println("ERROR")
} }
} }
} }

9
go/tests/printhex/main.go

@ -8,21 +8,18 @@ import (
) )
func main() { func main() {
var table []string table := []string{
table = append(table,
" ", " ",
"123 132 1", "123 132 1",
"1 5", "1 5",
"0", "0",
) }
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
table = append(table, strconv.Itoa(lib.RandIntBetween(-1000, 2000000000))) table = append(table, strconv.Itoa(lib.RandIntBetween(-1000, lib.MaxInt)))
} }
for i := 0; i < 15; i++ { for i := 0; i < 15; i++ {
table = append(table, strconv.Itoa(i)) table = append(table, strconv.Itoa(i))
} }
for _, s := range table { for _, s := range table {
lib.ChallengeMain("printhex", strings.Fields(s)...) lib.ChallengeMain("printhex", strings.Fields(s)...)
} }

12
go/tests/printmemory/main.go

@ -36,8 +36,8 @@ func printBase(nbr int) int {
return a return a
} }
func printLine(arr [10]int, start int) { func printLine(elems [10]int, start int) {
size := len(arr) size := len(elems)
a := start a := start
var aux, b int var aux, b int
@ -45,7 +45,7 @@ func printLine(arr [10]int, start int) {
if a%4 == 0 && a != 0 { if a%4 == 0 && a != 0 {
fmt.Println() fmt.Println()
} }
b = 8 - printBase(arr[a]) b = 8 - printBase(elems[a])
for aux != b { for aux != b {
if b == 6 { if b == 6 {
fmt.Print("0") fmt.Print("0")
@ -65,8 +65,8 @@ func printLine(arr [10]int, start int) {
fmt.Println() 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(elems[c])) {
fmt.Printf("%c", rune(arr[c])) fmt.Printf("%c", rune(elems[c]))
} else { } else {
fmt.Print(".") fmt.Print(".")
} }
@ -93,7 +93,7 @@ func main() {
lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table) lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table)
} }
table2 := [10]int{104, 101, 108, 108, 111, 16, 21, 42} table2 := [10]int{104, 101, 108, 108, 111, 16, 21, 42}
lib.Challenge("PrintMemory", student.PrintMemory, correct.PrintMemory, table2) lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table2)
} }
// TODO: this can be simplified a lot // TODO: this can be simplified a lot

9
go/tests/printnbr/main.go

@ -7,18 +7,13 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func printNbr(n int) {
fmt.Print(n)
}
func main() { func main() {
table := append( table := append(lib.MultRandInt(),
lib.MultRandInt(),
lib.MinInt, lib.MinInt,
lib.MaxInt, lib.MaxInt,
0, 0,
) )
for _, arg := range table { for _, arg := range table {
lib.Challenge("PrintNbr", student.PrintNbr, printNbr, arg) lib.Challenge("PrintNbr", student.PrintNbr, fmt.Print, arg)
} }
} }

2
go/tests/printprogramname/main.go

@ -15,7 +15,7 @@ func test(newName string) {
} }
b, err := exec.Command("./" + name).CombinedOutput() b, err := exec.Command("./" + name).CombinedOutput()
if err != nil { if err != nil {
lib.Fatalln(b) lib.Fatalln(string(b))
} }
if string(b) != name+"\n" { if string(b) != name+"\n" {
lib.Fatalln("Failed to print the program name") lib.Fatalln("Failed to print the program name")

18
go/tests/printrevcomb/correct/main.go

@ -3,19 +3,15 @@ package main
import "fmt" import "fmt"
func main() { func main() {
for a := 9; a >= 2; { for a := 9; a >= 2; a-- {
for b := a - 1; b >= 1; { for b := a - 1; b >= 1; b-- {
for c := b - 1; c >= 0; { for c := b - 1; c >= 0; c-- {
if a > b && b > c && a+b+c != 3 { fmt.Printf("%d%d%d", a, b, c)
fmt.Printf("%d%d%d, ", a, b, c) if a+b+c != 3 {
fmt.Print(", ")
} }
if a+b+c == 3 {
fmt.Printf("%d%d%d\n", a, b, c)
}
c--
} }
b--
} }
a--
} }
fmt.Println()
} }

5
go/tests/printreversealphabet/correct/main.go

@ -3,8 +3,5 @@ package main
import "fmt" import "fmt"
func main() { func main() {
for r := 'z'; r >= 'a'; r-- { fmt.Println("zyxwvutsrqponmlkjihgfedcba")
fmt.Print(r)
}
fmt.Println()
} }

9
go/tests/printstr/main.go

@ -7,14 +7,9 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func printStr(s string) {
fmt.Print(s)
}
func main() { func main() {
table := lib.MultRandASCII() table := append(lib.MultRandASCII(), "Hello World!")
table = append(table, "Hello World!")
for _, arg := range table { for _, arg := range table {
lib.Challenge("PrintStr", student.PrintStr, printStr, arg) lib.Challenge("PrintStr", student.PrintStr, fmt.Print, arg)
} }
} }

7
go/tests/printwordstables/main.go

@ -14,16 +14,13 @@ func printWordsTables(a []string) {
} }
func main() { func main() {
table := [][]string{} table := [][]string{{"Hello", "how", "are", "you?"}}
// 30 random slice of slice of strings
// 30 random slice of slice of strings
for i := 0; i < 30; i++ { for i := 0; i < 30; i++ {
table = append(table, lib.MultRandASCII()) table = append(table, lib.MultRandASCII())
} }
table = append(table,
[]string{"Hello", "how", "are", "you?"})
for _, arg := range table { for _, arg := range table {
lib.Challenge("PrintWordsTables", student.PrintWordsTables, printWordsTables, arg) lib.Challenge("PrintWordsTables", student.PrintWordsTables, printWordsTables, arg)
} }

5
go/tests/priorprime/main.go

@ -23,15 +23,14 @@ func priorPrime(x int) int {
} }
func main() { func main() {
table := []int{ table := append(lib.MultRandIntBetween(0, 1000),
50, 50,
13, 13,
10, 10,
0, 0,
1, 1,
2, 2,
} )
table = append(table, lib.MultRandIntBetween(0, 1000))
for _, arg := range table { for _, arg := range table {
lib.Challenge("PriorPrime", student.PriorPrime, priorPrime, arg) lib.Challenge("PriorPrime", student.PriorPrime, priorPrime, arg)
} }

29
go/tests/range/correct/main.go

@ -4,34 +4,21 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
)
func rangeOf(start, end int) []int { "github.com/01-edu/public/go/lib"
var ran []int )
if start >= end {
for i := start; i >= end; i-- {
ran = append(ran, i)
}
return ran
}
for i := start; i <= end; i++ {
ran = append(ran, i)
}
return ran
}
func main() { func main() {
if len(os.Args) != 3 { if len(os.Args) != 3 {
return return
} }
secondArg := 0 a, err := strconv.Atoi(os.Args[1])
firstArg, err := strconv.Atoi(os.Args[1]) if err != nil {
if err == nil { panic("ERROR: " + err.Error())
secondArg, err = strconv.Atoi(os.Args[2])
} }
b, err := strconv.Atoi(os.Args[2])
if err != nil { if err != nil {
fmt.Println(err) panic("ERROR: " + err.Error())
return
} }
fmt.Println(rangeOf(firstArg, secondArg)) fmt.Println(lib.IntRange(a, b))
} }

2
go/tests/reachablenumber/main.go

@ -30,7 +30,7 @@ func main() {
2, 2,
} }
for i := 0; i < 25; i++ { for i := 0; i < 25; i++ {
table = append(table, lib.MultRandIntBetween(1, 877)) table = append(table, lib.MultRandIntBetween(1, 877)...)
} }
for _, arg := range table { for _, arg := range table {
lib.Challenge("ReachableNumber", student.ReachableNumber, reachableNumber, arg) lib.Challenge("ReachableNumber", student.ReachableNumber, reachableNumber, arg)

4
go/tests/rectangle/correct/main.go

@ -42,7 +42,7 @@ func defineRectangle(vPoint []point, n int) *rectangle {
return ptr return ptr
} }
func calArea(ptr *rectangle) int { func calcArea(ptr *rectangle) int {
return (ptr.upLeft.x - ptr.downRight.x) * (ptr.downRight.y - ptr.upLeft.y) return (ptr.upLeft.x - ptr.downRight.x) * (ptr.downRight.y - ptr.upLeft.y)
} }
@ -60,5 +60,5 @@ func main() {
} }
rectangle = defineRectangle(vPoint, n) rectangle = defineRectangle(vPoint, n)
fmt.Println("area of the rectangle:", calArea(rectangle)) fmt.Println("area of the rectangle:", calcArea(rectangle))
} }

2
go/tests/recursivefactorial/main.go

@ -15,7 +15,7 @@ func recursiveFactorial(nb int) int {
if nb == 0 { if nb == 0 {
return 1 return 1
} }
return nb * RecursiveFactorial(nb-1) return nb * recursiveFactorial(nb-1)
} }
func main() { func main() {

4
go/tests/recursivepower/main.go

@ -22,6 +22,6 @@ func main() {
lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, nb, power) lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, nb, power)
i++ i++
} }
lib.Challenge("RecursivePower", student.RecursivePower, correct.RecursivePower, 0, 0) lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, 0, 0)
lib.Challenge("RecursivePower", student.RecursivePower, correct.RecursivePower, 0, 1) lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, 0, 1)
} }

4
go/tests/reduceint/main.go

@ -7,7 +7,7 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func reduceInt(f func(int, int) int, a []int) { func reduceInt(a []int, f func(int, int) int) {
acc := a[0] acc := a[0]
for i := 1; i < len(a); i++ { for i := 1; i < len(a); i++ {
acc = f(acc, a[i]) acc = f(acc, a[i])
@ -45,7 +45,7 @@ func main() {
for _, v := range table { for _, v := range table {
for _, f := range v.functions { for _, f := range v.functions {
lib.Challenge("ReduceInt", student.ReduceInt, reduceInt, f, v.a) lib.Challenge("ReduceInt", student.ReduceInt, reduceInt, v.a, f)
} }
} }
} }

36
go/tests/reverserange/correct/main.go

@ -4,35 +4,21 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"github.com/01-edu/public/go/lib"
) )
func main() { func main() {
if len(os.Args) == 3 { if len(os.Args) != 3 {
secondArg := 0 return
firstArg, err := strconv.Atoi(os.Args[1])
if err == nil {
secondArg, err = strconv.Atoi(os.Args[2])
}
if err != nil {
fmt.Println(err)
return
}
fmt.Println(reverseRange(firstArg, secondArg))
} else {
fmt.Println()
} }
} a, err := strconv.Atoi(os.Args[1])
if err != nil {
func reverseRange(start, end int) []int { panic("ERROR: " + err.Error())
var rran []int
if end >= start {
for i := end; i >= start; i-- {
rran = append(rran, i)
}
return rran
} }
for i := end; i <= start; i++ { b, err := strconv.Atoi(os.Args[2])
rran = append(rran, i) if err != nil {
panic("ERROR: " + err.Error())
} }
return rran fmt.Println(lib.IntRange(a, b))
} }

34
go/tests/reversestrcap/correct/main.go

@ -3,37 +3,17 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"unicode"
) )
func upperCase(ch rune) rune {
if ch >= 'a' && ch <= 'z' {
return ch - ('a' - 'A')
}
return ch
}
func lowerCase(ch rune) rune {
if ch >= 'A' && ch <= 'Z' {
return ch + ('a' - 'A')
}
return ch
}
func main() { func main() {
if len(os.Args) < 2 { for _, arg := range os.Args[1:] {
fmt.Println() arg := []rune(arg)
os.Exit(0) for j, r := range arg {
} if j+1 == len(arg) || arg[j+1] == ' ' {
arg[j] = unicode.ToUpper(r)
for i := 1; i < len(os.Args); i++ {
arg := []rune(os.Args[i])
for j, c := range arg {
if j+1 < len(arg) && arg[j+1] == ' ' {
arg[j] = upperCase(c)
} else if j+1 == len(arg) {
arg[j] = upperCase(c)
} else { } else {
arg[j] = lowerCase(c) arg[j] = unicode.ToLower(r)
} }
} }
fmt.Println(string(arg)) fmt.Println(string(arg))

3
go/tests/reversestrcap/main.go

@ -8,14 +8,13 @@ func main() {
args := [][]string{ args := [][]string{
{"First SMALL TesT"}, {"First SMALL TesT"},
{"SEconD Test IS a LItTLE EasIEr", "bEwaRe IT'S NoT HARd WhEN ", " Go a dernier 0123456789 for the road e"}, {"SEconD Test IS a LItTLE EasIEr", "bEwaRe IT'S NoT HARd WhEN ", " Go a dernier 0123456789 for the road e"},
{""},
} }
for i := 0; i < 15; i++ { for i := 0; i < 15; i++ {
args = append(args, lib.MultRandAlnum()) args = append(args, lib.MultRandAlnum())
} }
args = append(args, []string{""})
for _, v := range args { for _, v := range args {
lib.ChallengeMain("reversestrcap", v...) lib.ChallengeMain("reversestrcap", v...)
} }

36
go/tests/revivethreenums/main.go

@ -5,42 +5,32 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func more(a, b int) int { func max(ints ...int) int {
if a < b { if len(ints) == 0 {
return b panic("max() is invalid")
} }
return a max := ints[0]
} for _, i := range ints[1:] {
if i > max {
func max(a, b, c, d int) int { max = i
if a >= b && a >= c && a >= d { }
return a
}
if b >= a && b >= c && b >= d {
return b
}
if c >= a && c >= b && c >= d {
return c
}
if d >= a && d >= b && d >= c {
return d
} }
return -1 return max
} }
func reviveThreeNums(a, b, c, d int) int { func reviveThreeNums(a, b, c, d int) int {
maxi := -111 maxi := -111
if a != max(a, b, c, d) { if a != max(a, b, c, d) {
maxi = more(maxi, max(a, b, c, d)-a) maxi = max(maxi, max(a, b, c, d)-a)
} }
if b != max(a, b, c, d) { if b != max(a, b, c, d) {
maxi = more(maxi, max(a, b, c, d)-b) maxi = max(maxi, max(a, b, c, d)-b)
} }
if c != max(a, b, c, d) { if c != max(a, b, c, d) {
maxi = more(maxi, max(a, b, c, d)-c) maxi = max(maxi, max(a, b, c, d)-c)
} }
if d != max(a, b, c, d) { if d != max(a, b, c, d) {
maxi = more(maxi, max(a, b, c, d)-d) maxi = max(maxi, max(a, b, c, d)-d)
} }
return maxi return maxi
} }

10
go/tests/revwstr/correct/main.go

@ -7,12 +7,10 @@ import (
) )
func main() { func main() {
if len(os.Args) != 2 { if len(os.Args) == 2 {
fmt.Println() a := strings.Split(os.Args[1], " ")
} else { for i := len(a) - 1; i >= 0; i-- {
arrString := strings.Split(os.Args[1], " ") fmt.Print(a[i])
for i := len(arrString) - 1; i >= 0; i-- {
fmt.Print(arrString[i])
if i != 0 { if i != 0 {
fmt.Print(" ") fmt.Print(" ")
} }

2
go/tests/romannumbers/correct/main.go

@ -17,7 +17,7 @@ func main() {
nbr, err := strconv.Atoi(os.Args[1]) nbr, err := strconv.Atoi(os.Args[1])
if err != nil || nbr >= 4000 || nbr == 0 { if err != nil || nbr >= 4000 || nbr == 0 {
fmt.Println("ERROR: can not convert to roman digit") fmt.Println("ERROR: can not convert to roman digit")
os.Exit(0) return
} }
patter := []roman{ patter := []roman{
{num: 1000, romanDigit: "M"}, {num: 1000, romanDigit: "M"},

4
go/tests/rostring/correct/main.go

@ -6,9 +6,9 @@ import (
"strings" "strings"
) )
func deleteExtraSpaces(arr []string) []string { func deleteExtraSpaces(a []string) []string {
var res []string var res []string
for _, v := range arr { for _, v := range a {
if v != "" { if v != "" {
res = append(res, v) res = append(res, v)
} }

36
go/tests/rotatevowels/correct/main.go

@ -3,41 +3,35 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"regexp" "strings"
) )
func main() { func main() {
var arr []rune var a1, a2, rev []rune
var revarr []rune for _, arg := range os.Args[1:] {
vowels := regexp.MustCompile(`[aeiouAEIOU]`) for _, k := range arg {
for i := 1; i < len(os.Args); i++ { if strings.ContainsRune("aeiouAEIOU", k) {
for _, k := range os.Args[i] { a1 = append(a1, k)
mached := vowels.MatchString(string(k))
if mached {
arr = append(arr, rune(k))
} }
} }
} }
for i := len(arr) - 1; i >= 0; i-- { for i := len(a1) - 1; i >= 0; i-- {
revarr = append(revarr, arr[i]) rev = append(rev, a1[i])
} }
arr2 := []rune{}
m := 0 m := 0
for i := 1; i < len(os.Args); i++ { for i, arg := range os.Args[1:] {
for _, j := range os.Args[i] { for _, j := range arg {
mached := vowels.MatchString(string(j)) if strings.ContainsRune("aeiouAEIOU", j) {
if mached { a2 = append(a2, rev[m])
arr2 = append(arr2, rune(revarr[m]))
m++ m++
} else { } else {
arr2 = append(arr2, rune(j)) a2 = append(a2, j)
} }
} }
if i != len(os.Args)-1 { if i != len(os.Args)-1 {
arr2 = append(arr2, ' ') a2 = append(a2, ' ')
} }
} }
fmt.Println(string(arr2)) fmt.Println(string(a2))
} }

12
go/tests/rotatevowels/main.go

@ -7,17 +7,13 @@ import (
) )
func main() { func main() {
Lower := lib.RuneRange('a', 'z') letters := lib.Lower + lib.Upper + " "
Upper := lib.RuneRange('A', 'Z') a := []string{""}
letters := Lower + Upper + " "
var arr []string
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
str := lib.RandStr(lib.RandIntBetween(2, 20), letters) a = append(a, lib.RandStr(lib.RandIntBetween(2, 20), letters))
arr = append(arr, str)
} }
arr = append(arr, "")
for _, v := range arr { for _, v := range a {
lib.ChallengeMain("rotatevowels", strings.Fields(v)...) lib.ChallengeMain("rotatevowels", strings.Fields(v)...)
} }
lib.ChallengeMain("rotatevowels", "Hello World") lib.ChallengeMain("rotatevowels", "Hello World")

94
go/tests/rpncalc/correct/main.go

@ -7,70 +7,60 @@ import (
"strings" "strings"
) )
func isOp(s string) bool { func deleteExtraSpaces(a []string) (res []string) {
return s == "+" || for _, v := range a {
s == "-" ||
s == "*" ||
s == "/" ||
s == "%"
}
func deleteExtraSpaces(arr []string) []string {
var res []string
for _, v := range arr {
if v != "" { if v != "" {
res = append(res, v) res = append(res, v)
} }
} }
return res return
} }
func main() { func main() {
if len(os.Args) == 2 { if len(os.Args) != 2 {
var values []int fmt.Println("Error")
var n int return
op := strings.Split(os.Args[1], " ") }
op = deleteExtraSpaces(op) var values []int
for _, v := range op { op := strings.Split(os.Args[1], " ")
val, err := strconv.Atoi(v) op = deleteExtraSpaces(op)
for _, v := range op {
if err == nil { val, err := strconv.Atoi(v)
values = append(values, val)
continue
}
n = len(values) if err == nil {
if isOp(v) && n < 2 { values = append(values, val)
fmt.Println("Error") continue
os.Exit(0) }
}
switch v { n := len(values)
case "+": if n < 2 {
values[n-2] += values[n-1] fmt.Println("Error")
values = values[:n-1] return
case "-":
values[n-2] -= values[n-1]
values = values[:n-1]
case "*":
values[n-2] *= values[n-1]
values = values[:n-1]
case "/":
values[n-2] /= values[n-1]
values = values[:n-1]
case "%":
values[n-2] %= values[n-1]
values = values[:n-1]
default:
fmt.Println("Error")
os.Exit(0)
}
} }
if len(values) == 1 {
fmt.Println(values[0]) switch v {
} else { case "+":
values[n-2] += values[n-1]
values = values[:n-1]
case "-":
values[n-2] -= values[n-1]
values = values[:n-1]
case "*":
values[n-2] *= values[n-1]
values = values[:n-1]
case "/":
values[n-2] /= values[n-1]
values = values[:n-1]
case "%":
values[n-2] %= values[n-1]
values = values[:n-1]
default:
fmt.Println("Error") fmt.Println("Error")
return
} }
}
if len(values) == 1 {
fmt.Println(values[0])
} else { } else {
fmt.Println("Error") fmt.Println("Error")
} }

8
go/tests/slice/main.go

@ -47,7 +47,7 @@ func slice(a []string, nbr ...int) []string {
} }
func main() { func main() {
arr := [][]interface{}{ elems := [][]interface{}{
{ {
[]string{"coding", "algorithm", "ascii", "package", "golang"}, []string{"coding", "algorithm", "ascii", "package", "golang"},
1, 1,
@ -72,14 +72,14 @@ func main() {
s := lib.MultRandWords() s := lib.MultRandWords()
arr = append(arr, []interface{}{s, -len(s) - 10, -len(s) - 5}) elems = append(elems, []interface{}{s, -len(s) - 10, -len(s) - 5})
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
s = lib.MultRandWords() s = lib.MultRandWords()
arr = append(arr, []interface{}{s, lib.RandIntBetween(-len(s)-10, len(s)+10), lib.RandIntBetween(-len(s)-8, len(s)+10)}) elems = append(elems, []interface{}{s, lib.RandIntBetween(-len(s)-10, len(s)+10), lib.RandIntBetween(-len(s)-8, len(s)+10)})
} }
for _, a := range arr { for _, a := range elems {
lib.Challenge("Slice", student.Slice, slice, a...) lib.Challenge("Slice", student.Slice, slice, a...)
} }
} }

22
go/tests/sortwordarr/main.go

@ -8,10 +8,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func sortWordArr(a []string) {
sort.Strings(a)
}
func main() { func main() {
table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}}
@ -21,22 +17,22 @@ func main() {
for _, org := range table { for _, org := range table {
// copy for using the solution function // copy for using the solution function
cp_sol := make([]string, len(org)) copySol := make([]string, len(org))
// copy for using the student function // copy for using the student function
cp_stu := make([]string, len(org)) copyStu := make([]string, len(org))
copy(cp_sol, org) copy(copySol, org)
copy(cp_stu, org) copy(copyStu, org)
sortWordArr(cp_sol) sort.Strings(copySol)
student.SortWordArr(cp_stu) student.SortWordArr(copyStu)
if !reflect.DeepEqual(cp_stu, cp_sol) { if !reflect.DeepEqual(copyStu, copySol) {
lib.Fatalf("%s(%v) == %v instead of %v\n", lib.Fatalf("%s(%v) == %v instead of %v\n",
"SortWordArr", "SortWordArr",
org, org,
cp_stu, copyStu,
cp_sol, copySol,
) )
} }
} }

6
go/tests/split/main.go

@ -8,10 +8,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func split(s, sep string) []string {
return strings.Split(s, sep)
}
func main() { func main() {
separators := []string{"!=HA=!", separators := []string{"!=HA=!",
"!==!", "!==!",
@ -42,6 +38,6 @@ func main() {
node{str: "HelloHAhowHAareHAyou?", sep: "HA"}) node{str: "HelloHAhowHAareHAyou?", sep: "HA"})
for _, arg := range table { for _, arg := range table {
lib.Challenge("Split", student.Split, split, arg.str, arg.sep) lib.Challenge("Split", student.Split, strings.Split, arg.str, arg.sep)
} }
} }

17
go/tests/splitwhitespaces/main.go

@ -7,23 +7,14 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func splitWhiteSpaces(s string) []string {
return strings.Fields(s)
}
func main() { func main() {
table := []string{} table := []string{"Hello how are you?"}
// 30 random slice of strings
// 30 random slice of strings
for i := 0; i < 30; i++ { for i := 0; i < 30; i++ {
val := strings.Join(lib.MultRandASCII(), " ") table = append(table, strings.Join(lib.MultRandASCII(), " "))
table = append(table, val)
} }
table = append(table,
"Hello how are you?")
for _, arg := range table { for _, arg := range table {
lib.Challenge("SplitWhiteSpaces", student.SplitWhiteSpaces, splitWhiteSpaces, arg) lib.Challenge("SplitWhiteSpaces", student.SplitWhiteSpaces, strings.Fields, arg)
} }
} }

3
go/tests/sqrt/main.go

@ -16,8 +16,7 @@ func sqrt(value int) int {
} }
func main() { func main() {
table := append( table := append(lib.MultRandIntBetween(-1000000, 1000000),
lib.MultRandIntBetween(-1000000, 1000000),
0, 0,
1, 1,
2, 2,

12
go/tests/strlen/main.go

@ -5,14 +5,8 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func strLen(str string) int { func strLen(s string) int {
len := 0 return len([]rune(s))
strConverted := []rune(str)
for i, _ := range strConverted {
len = i + 1
}
return len
} }
func main() { func main() {
@ -31,3 +25,5 @@ func main() {
lib.Challenge("StrLen", strLen, student.StrLen, s) lib.Challenge("StrLen", strLen, student.StrLen, s)
} }
} }
// TODO: refactor, simplify, no need for specifiy charset : check lib

4
go/tests/swap/main.go

@ -5,10 +5,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func Swap(a, b *int) {
*a, *b = *b, *a
}
func main() { func main() {
i := 0 i := 0
for i < 30 { for i < 30 {

5
go/tests/switchcase/correct/main.go

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

4
go/tests/tabmult/correct/main.go

@ -6,7 +6,7 @@ import (
"strconv" "strconv"
) )
func Tabmul(nbr int) { func tabmul(nbr int) {
i := 1 i := 1
for i < 10 { for i < 10 {
result := nbr * i result := nbr * i
@ -18,7 +18,7 @@ func Tabmul(nbr int) {
func main() { func main() {
if len(os.Args) == 2 { if len(os.Args) == 2 {
number, _ := strconv.Atoi(os.Args[1]) number, _ := strconv.Atoi(os.Args[1])
Tabmul(number) tabmul(number)
} else { } else {
fmt.Println() fmt.Println()
} }

11
go/tests/tolower/main.go

@ -7,16 +7,9 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func toLower(s string) string {
return strings.ToLower(s)
}
func main() { func main() {
table := append( table := append(lib.MultRandASCII(), "Hello! How are you?")
lib.MultRandASCII(),
"Hello! How are you?",
)
for _, arg := range table { for _, arg := range table {
lib.Challenge("ToLower", student.ToLower, toLower, arg) lib.Challenge("ToLower", student.ToLower, strings.ToLower, arg)
} }
} }

13
go/tests/toupper/main.go

@ -7,18 +7,9 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func toUpper(s string) string {
return strings.ToUpper(s)
}
func main() { func main() {
table := lib.MultRandASCII() table := append(lib.MultRandASCII(), "Hello! How are you?")
table = append(table,
"Hello! How are you?",
)
for _, arg := range table { for _, arg := range table {
lib.Challenge("ToUpper", student.ToUpper, toUpper, arg) lib.Challenge("ToUpper", student.ToUpper, strings.ToUpper, arg)
} }
} }

16
go/tests/trimatoi/main.go

@ -5,15 +5,15 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func trimAtoi(str string) int { func trimAtoi(s string) int {
chars := []rune(str) runes := []rune(s)
for i := range str { for i := range s {
chars[i] = rune(str[i]) runes[i] = rune(s[i])
} }
var numbers []rune var numbers []rune
for i := range chars { for _, r := range runes {
if (chars[i] >= '0' && chars[i] <= '9') || (len(numbers) == 0 && (chars[i]) == '-' || chars[i] == '+') { if (r >= '0' && r <= '9') || (len(numbers) == 0 && (r) == '-' || r == '+') {
numbers = append(numbers, chars[i]) numbers = append(numbers, r)
} }
} }
if len(numbers) == 0 || (len(numbers) == 1 && (numbers[0] == '-' || numbers[0] == '+')) { if len(numbers) == 0 || (len(numbers) == 1 && (numbers[0] == '-' || numbers[0] == '+')) {
@ -68,3 +68,5 @@ func main() {
lib.Challenge("TrimAtoi", student.TrimAtoi, trimAtoi, elem) lib.Challenge("TrimAtoi", student.TrimAtoi, trimAtoi, elem)
} }
} }
// TODO: refactor, including the subject

6
go/tests/ultimatedivmod/main.go

@ -5,12 +5,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func UltimateDivMod(a, b *int) {
temp := *a
*a = *a / *b
*b = temp % *b
}
func main() { func main() {
i := 0 i := 0
for i < lib.SliceLen { for i < lib.SliceLen {

4
go/tests/ultimatepointone/main.go

@ -5,10 +5,6 @@ import (
"github.com/01-edu/public/go/lib" "github.com/01-edu/public/go/lib"
) )
func UltimatePointOne(n ***int) {
***n = 1
}
func main() { func main() {
a := 0 a := 0
b := &a b := &a

33
go/tests/union/correct/main.go

@ -3,37 +3,26 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
) )
func isIn(a rune, arr []rune) bool {
for _, v := range arr {
if a == v {
return true
}
}
return false
}
func main() { func main() {
if len(os.Args) == 3 { if len(os.Args) == 3 {
var res []rune var res string
str1 := []rune(os.Args[1]) s1 := os.Args[1]
str2 := []rune(os.Args[2]) s2 := os.Args[2]
for _, v := range str1 { for _, v := range s1 {
if !isIn(v, res) { if !strings.ContainsRune(res, v) {
res = append(res, v) res += string(v)
} }
} }
for _, v := range s2 {
for _, v := range str2 { if !strings.ContainsRune(res, v) {
if !isIn(v, res) { res += string(v)
res = append(res, v)
} }
} }
fmt.Print(res)
fmt.Print(string(res))
} }
fmt.Println() fmt.Println()
} }

24
go/tests/union/main.go

@ -7,19 +7,19 @@ import (
) )
func main() { func main() {
arg1 := []string{"zpadinton", "paqefwtdjetyiytjneytjoeyjnejeyj"} s1 := lib.RandAlnum()
arg2 := []string{"ddf6vewg64f", "gtwthgdwthdwfteewhrtag6h4ffdhsd"} s2 := strings.Join([]string{lib.RandAlnum(), s1, lib.RandAlnum()}, "")
arg3 := []string{""}
arg4 := []string{"rien", "cette phrase ne cache rien"}
arg5 := []string{" this is ", " wait shr"}
arg6 := []string{" more ", "then", "two", "arguments"}
str1 := lib.RandAlnum() args := [][]string{
str2 := strings.Join([]string{lib.RandAlnum(), str1, lib.RandAlnum()}, "") {"zpadinton", "paqefwtdjetyiytjneytjoeyjnejeyj"},
{"ddf6vewg64f", "gtwthgdwthdwfteewhrtag6h4ffdhsd"},
arg7 := []string{str1, str2} {""},
arg8 := []string{lib.RandAlnum(), lib.RandAlnum()} {"rien", "cette phrase ne cache rien"},
args := [][]string{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8} {" this is ", " wait shr"},
{" more ", "then", "two", "arguments"},
{s1, s2},
{lib.RandAlnum(), lib.RandAlnum()},
}
for _, v := range args { for _, v := range args {
lib.ChallengeMain("union", v...) lib.ChallengeMain("union", v...)

28
go/tests/uniqueoccurences/correct/main.go

@ -5,14 +5,14 @@ import (
"os" "os"
) )
func solve(str string) bool { func solve(s string) bool {
arr := make([]int, 26) var a [26]int
for i := 0; i < len(str); i++ { for _, r := range s {
arr[str[i]-'a']++ a[r-'a']++
} }
for i := 0; i < 26; i++ { for i := 0; i < 26; i++ {
for j := i + 1; j < 26; j++ { for j := i + 1; j < 26; j++ {
if arr[i] == arr[j] && arr[i] != 0 { if a[i] == a[j] && a[i] != 0 {
return false return false
} }
} }
@ -20,22 +20,8 @@ func solve(str string) bool {
return true return true
} }
func print(str string) {
for _, v := range str {
fmt.Printf("%c", v)
}
}
func main() { func main() {
args := os.Args[1:] if len(os.Args) == 2 {
if len(args) != 1 { fmt.Println(solve(os.Args[1]))
fmt.Println()
return
}
result := solve(args[0])
if result {
print("true\n")
} else {
print("false\n")
} }
} }

35
go/tests/unmatch/main.go

@ -6,11 +6,11 @@ import (
) )
// Returns the element of the slice that doesn't have a correspondant pair // Returns the element of the slice that doesn't have a correspondant pair
func unmatch(arr []int) int { func unmatch(elems []int) int {
var quant int var quant int
for _, el := range arr { for _, el := range elems {
quant = 0 quant = 0
for _, v := range arr { for _, v := range elems {
if v == el { if v == el {
quant++ quant++
} }
@ -23,22 +23,19 @@ func unmatch(arr []int) int {
} }
func main() { func main() {
arg1 := []int{1, 1, 2, 3, 4, 3, 4} i1 := lib.RandIntBetween(-100, 100)
arg2 := []int{1, 1, 2, 4, 3, 4, 2, 3, 4} i2 := lib.RandIntBetween(-1000, 1000)
arg3 := []int{1, 2, 1, 1, 4, 5, 5, 4, 1, 7} i3 := lib.RandIntBetween(-10, 10)
arg4 := []int{1, 2, 3, 4, 5, 6, 7, 8} args := [][]int{
arg5 := []int{0, 20, 91, 23, 10, 34} {1, 1, 2, 3, 4, 3, 4},
arg6 := []int{1, 1, 2, 2, 3, 4, 3, 4, 5, 5, 8, 9, 8, 9} {1, 1, 2, 4, 3, 4, 2, 3, 4},
{1, 2, 1, 1, 4, 5, 5, 4, 1, 7},
randInt1 := lib.RandIntBetween(-100, 100) {1, 2, 3, 4, 5, 6, 7, 8},
randInt2 := lib.RandIntBetween(-1000, 1000) {0, 20, 91, 23, 10, 34},
randInt3 := lib.RandIntBetween(-10, 10) {1, 1, 2, 2, 3, 4, 3, 4, 5, 5, 8, 9, 8, 9},
{i1, i2, i1, i2, i1 + i3, i1 + i3},
arg7 := []int{randInt1, randInt2, randInt1, randInt2, randInt1 + randInt3, randInt1 + randInt3} {i1, i2, i1, i2, i1 + i3, i2 - i3},
arg8 := []int{randInt1, randInt2, randInt1, randInt2, randInt1 + randInt3, randInt2 - randInt3} }
args := [][]int{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8}
for _, v := range args { for _, v := range args {
lib.Challenge("Unmatch", student.Unmatch, unmatch, v) lib.Challenge("Unmatch", student.Unmatch, unmatch, v)
} }

27
go/tests/wdmatch/correct/main.go

@ -5,30 +5,27 @@ import (
"os" "os"
) )
func result(str1 string, str2 string) string { func ok(s1 string, s2 string) bool {
arraystr1 := []rune(str1) runes1 := []rune(s1)
arraystr2 := []rune(str2) runes2 := []rune(s2)
var rest string var rest string
count := 0 count := 0
for i := 0; i < len(arraystr1); i++ { for i := 0; i < len(runes1); i++ {
for j := count; j < len(arraystr2); j++ { for j := count; j < len(runes2); j++ {
if arraystr1[i] == arraystr2[j] { if runes1[i] == runes2[j] {
rest += string(arraystr1[i]) rest += string(runes1[i])
j = len(arraystr2) - 1 j = len(runes2) - 1
} }
count++ count++
} }
} }
if rest != str1 { return s1 == rest
return ""
}
return rest
} }
func main() { func main() {
if len(os.Args) == 3 { if len(os.Args) == 3 {
fmt.Println(result(os.Args[1], os.Args[2])) if ok(os.Args[1], os.Args[2]) {
} else { fmt.Println(os.Args[1])
fmt.Println() }
} }
} }

2
subjects/balancedstring.en.md

@ -7,7 +7,7 @@ Balanced string is a string that has equal quantity of 'C' and 'D' characters.
Write a program that takes a string and outputs maximum amount of balanced strings without ignoring any letters. Write a program that takes a string and outputs maximum amount of balanced strings without ignoring any letters.
Display output with `\n` at the end of line. Display output with `\n` at the end of line.
If the number of arguments is not 1, display `\n`. If the number of arguments is not 1, display nothing.
It will only be tested strings containing the characters 'C' and 'D'. It will only be tested strings containing the characters 'C' and 'D'.

2
subjects/displaya.en.md

@ -4,7 +4,7 @@
Write a program that takes a `string`, and displays the first `a` character it encounters in it, followed by a newline (`'\n'`). Write a program that takes a `string`, and displays the first `a` character it encounters in it, followed by a newline (`'\n'`).
If there are no `a` characters in the string, the program just writes `a` followed by a newline (`'\n'`). If there are no `a` characters in the string, the program just writes `a` followed by a newline (`'\n'`).
If the number of parameters is not 1, the program displays an `a` followed by a newline (`'\n'`). If the number of arguments is not 1, the program displays an `a` followed by a newline (`'\n'`).
### Usage ### Usage

2
subjects/displayfirstparam.en.md

@ -2,7 +2,7 @@
### Instructions ### Instructions
Write a program that takes `string` as arguments, and displays its first argument. Write a program that displays its first argument, if there is one.
### Usage ### Usage

Some files were not shown because too many files changed in this diff diff.show_more

Loading…
Cancel
Save