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>
- 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>

2
go/lib/is/is.go

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

20
go/lib/lib.go

@ -150,11 +150,10 @@ func RandRune() rune {
r := table.R32[rand.Intn(len(table.R32))]
n := uint32(rand.Intn(int((r.Hi-r.Lo)/r.Stride) + 1))
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.
@ -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: remove the number of rand functions, refactor test cases (aka "table")

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

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

24
go/tests/addprimesum/main.go

@ -4,36 +4,16 @@ import (
"strconv"
"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() {
// adds random numbers
table := lib.MultRandIntBetween(1, 10000)
// fill with all prime numbers between 0 and 100
for i := 0; i < 100; i++ {
if isAPrime(i) {
if is.Prime(i) {
table = append(table, i)
}
}

5
go/tests/any/main.go

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

3
go/tests/appendrange/main.go

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

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

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

9
go/tests/basicjoin/main.go

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

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

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

11
go/tests/collatzcountdown/main.go

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

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

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

38
go/tests/compact/main.go

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

6
go/tests/compare/main.go

@ -7,10 +7,6 @@ import (
"github.com/01-edu/public/go/lib"
)
func compare(a, b string) int {
return strings.Compare(a, b)
}
func main() {
type node struct {
s string
@ -49,6 +45,6 @@ func main() {
)
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
import (
"fmt"
"./student"
"github.com/01-edu/public/go/lib"
)
func concat(a, b string) string {
return a + b
}
func main() {
table := [][]string{}
@ -21,6 +19,6 @@ func main() {
[]string{"Hello!", " How are you?"},
)
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
}
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) {
return d * max(e, f)
}
@ -51,5 +51,5 @@ func main() {
e, _ := strconv.Atoi(args[4])
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"
)
type node struct {
A, B, C, D, E, F int
}
func main() {
table := []node{}
for i := 0; i < 25; i++ {
a := lib.RandIntBetween(0, 1000)
b := lib.RandIntBetween(0, 1000)
c := lib.RandIntBetween(0, 1000)
d := lib.RandIntBetween(0, 1000)
e := lib.RandIntBetween(0, 1000)
f := lib.RandIntBetween(0, 1000)
table = append(table, node{a, b, c, d, e, f})
}
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)
lib.ChallengeMain("costumeprofit",
strconv.Itoa(lib.RandIntBetween(0, 1000)),
strconv.Itoa(lib.RandIntBetween(0, 1000)),
strconv.Itoa(lib.RandIntBetween(0, 1000)),
strconv.Itoa(lib.RandIntBetween(0, 1000)),
strconv.Itoa(lib.RandIntBetween(0, 1000)),
strconv.Itoa(lib.RandIntBetween(0, 1000)),
)
}
}

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

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

34
go/tests/countif/main.go

@ -6,9 +6,9 @@ import (
"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
for _, el := range arr {
for _, el := range a {
if f(el) {
counter++
}
@ -21,8 +21,8 @@ func main() {
functions := []func(string) bool{is.Digit, is.Lower, is.Upper}
type node struct {
f func(string) bool
arr []string
f func(string) bool
a []string
}
table := []node{}
@ -30,46 +30,46 @@ func main() {
for i := 0; i < 5; i++ {
function := functions[lib.RandIntBetween(0, len(functions)-1)]
val := node{
f: function,
arr: lib.MultRandWords(),
f: function,
a: lib.MultRandWords(),
}
table = append(table, val)
}
for i := 0; i < 5; i++ {
val := node{
f: is.Digit,
arr: lib.MultRandDigit(),
f: is.Digit,
a: lib.MultRandDigit(),
}
table = append(table, val)
}
for i := 0; i < 5; i++ {
val := node{
f: is.Lower,
arr: lib.MultRandLower(),
f: is.Lower,
a: lib.MultRandLower(),
}
table = append(table, val)
}
for i := 0; i < 5; i++ {
val := node{
f: is.Upper,
arr: lib.MultRandUpper(),
f: is.Upper,
a: lib.MultRandUpper(),
}
table = append(table, val)
}
table = append(table,
node{
f: is.Digit,
arr: []string{"Hello", "how", "are", "you"},
f: is.Digit,
a: []string{"Hello", "how", "are", "you"},
},
node{
f: is.Digit,
arr: []string{"This", "is", "4", "you"},
f: is.Digit,
a: []string{"This", "is", "4", "you"},
},
)
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() {
table := append(lib.MultRandWords(), "dsfda")
table = append(table, "")
table = append(table, "1")
table = append(table, "1")
table := append(lib.MultRandWords(),
"dsfda",
"",
"1",
"1",
)
for _, s := range table {
lib.ChallengeMain("displaya", strings.Fields(s)...)
}
lib.ChallengeMain("displaya", "1", "a")
}

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

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

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

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

11
go/tests/displayfirstparam/main.go

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

10
go/tests/displaylastparam/main.go

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

11
go/tests/displayz/main.go

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

5
go/tests/divmod/main.go

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

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

@ -8,50 +8,51 @@ import (
func main() {
if len(os.Args) == 4 {
var result int
firstArg, err := strconv.Atoi(os.Args[1])
a, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println(0)
return
}
operator := os.Args[2]
secondArg, err1 := strconv.Atoi(os.Args[3])
if err1 != nil {
b, err := strconv.Atoi(os.Args[3])
if err != nil {
fmt.Println(0)
return
}
if secondArg == 0 && operator == "/" {
fmt.Println("No division by 0")
return
} else if secondArg == 0 && operator == "%" {
fmt.Println("No modulo by 0")
return
} else if operator == "+" {
result = firstArg + secondArg
if !((result > firstArg) == (secondArg > 0)) {
operator := os.Args[2]
switch operator {
case "+":
result := a + b
if (result > a) != (b > 0) {
fmt.Println(0)
return
} else {
fmt.Println(result)
}
} else if operator == "-" {
result = firstArg - secondArg
if !((result < firstArg) == (secondArg > 0)) {
case "-":
result := a - b
if (result < a) != (b > 0) {
fmt.Println(0)
return
} else {
fmt.Println(result)
}
} else if operator == "/" {
result = firstArg / secondArg
} else if operator == "*" {
result = firstArg * secondArg
if firstArg != 0 && (result/firstArg != secondArg) {
case "*":
result := a * b
if a != 0 && (result/a != b) {
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"
)
func doppelGanger(s, substr string) int {
return strings.LastIndex(s, substr)
}
type node struct {
big, little string
}
@ -52,6 +48,6 @@ func main() {
}
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() {
x := 0
for x < size {
y := 0
for y < size {
for x := 0; x < size; x++ {
for y := 0; y < size; y++ {
if board[x][y] {
// We have found a queen, let's print her y
fmt.Printf("%c", rune(y)+'1')
}
y++
}
x++
}
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
// of the solution to the problem
func tryX(x int) {
y := 0
for y < size {
for y := 0; y < size; y++ {
if goodSquare(x, y) {
// Since the square is good for the queen, let's put one on it:
board[x][y] = true
@ -79,7 +74,6 @@ func tryX(x int) {
// remove the queen of the board, to try other y values
board[x][y] = false
}
y++
}
}

19
go/tests/enigma/main.go

@ -5,19 +5,8 @@ import (
"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()
func decript(a ***int, b *int, c *******int, d ****int) {
func decrypt(a ***int, b *int, c *******int, d ****int) {
vala := ***a
***a = *******c
valb := *b
@ -28,7 +17,7 @@ func decript(a ***int, b *int, c *******int, d ****int) {
}
func main() {
args := append([]int, lib.MultRandIntBetween(2, 20)...)
args := lib.MultRandIntBetween(2, 20)
aval := args[0]
x := args[0]
@ -58,7 +47,7 @@ func main() {
d := &n
student.Enigma(a, b, c, d)
decript(a, b, c, d)
decrypt(a, b, c, d)
if aval != ***a {
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"
)
func deleteExtraSpaces(arr []string) []string {
var res []string
for _, v := range arr {
func deleteExtraSpaces(a []string) (res []string) {
for _, v := range a {
if v != "" {
res = append(res, v)
}
}
return res
return
}
func main() {
if len(os.Args) != 2 {
fmt.Println()
os.Exit(0)
if len(os.Args) == 2 {
arg := strings.Split(os.Args[1], " ")
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
for i := 2; i <= n; i++ {
t1 += t2
tmp := t1
t1 = t2
t2 = tmp
t1, t2 = t2, t1
}
return t2
}
func main() {
table := []int{
table := append(lib.MultRandIntBetween(-100, 150),
20,
0,
9,
2,
}
table = append(table, lib.MultRandIntBetween(-100, 150)...)
)
for _, arg := range table {
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"
)
func fibonacci(value int) int {
if value < 0 {
func fibonacci(i int) int {
if i < 0 {
return -1
}
if value == 0 {
if i == 0 {
return 0
}
if value == 1 {
if i == 1 {
return 1
}
return Fibonacci(value-1) + Fibonacci(value-2)
return fibonacci(i-1) + fibonacci(i-2)
}
func main() {
table := append(
lib.MultRandIntBetween(0, 25),
table := append(lib.MultRandIntBetween(0, 25),
4,
5,
-5,

3
go/tests/findnextprime/main.go

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

4
go/tests/findprevprime/main.go

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

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

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

8
go/tests/game23/main.go

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

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

@ -4,23 +4,14 @@ import (
"fmt"
"os"
"strconv"
)
// Greatest common divisor
func gcd(num1, num2 int) int {
for i := num1; i > 0; i-- {
if num1%i == 0 && num2%i == 0 {
return i
}
}
return 1
}
"github.com/01-edu/public/go/lib"
)
func main() {
if len(os.Args) != 3 {
return
if len(os.Args) == 3 {
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"},
}
for i := 0; i < 25; i++ {
number1 := strconv.Itoa(lib.RandIntBetween(1, 100000))
number2 := strconv.Itoa(lib.RandIntBetween(1, 100))
args = append(args, []string{number1, number2})
a := strconv.Itoa(lib.RandIntBetween(1, 100000))
b := strconv.Itoa(lib.RandIntBetween(1, 100))
args = append(args, []string{a, b})
}
for _, v := range args {
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)
var result []string
if !(strings.ContainsRune(exp, '|')) {
if !strings.ContainsRune(exp, '|') {
helper := []string{exp}
result = append(singleSearch(helper, text))
} else {

10
go/tests/issorted/main.go

@ -7,18 +7,18 @@ import (
"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
descendingOrdered := true
for i := 1; i < len(arr); i++ {
if !(f(arr[i-1], arr[i]) >= 0) {
for i := 1; i < len(a); i++ {
if f(a[i-1], a[i]) < 0 {
ascendingOrdered = false
}
}
for i := 1; i < len(arr); i++ {
if !(f(arr[i-1], arr[i]) <= 0) {
for i := 1; i < len(a); i++ {
if f(a[i-1], a[i]) > 0 {
descendingOrdered = false
}
}

7
go/tests/itoa/main.go

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

18
go/tests/map/main.go

@ -10,7 +10,7 @@ func isPositive(i int) bool {
return i > 0
}
func isNegative0(i int) bool {
func isNegative(i int) bool {
return i < 0
}
@ -25,11 +25,11 @@ func _map(f func(int) bool, a []int) []bool {
}
func main() {
functions := []func(int) bool{isPositive, isNegative0, is.Prime}
functions := []func(int) bool{isPositive, isNegative, is.Prime}
type node struct {
f func(int) bool
arr []int
f func(int) bool
a []int
}
table := []node{}
@ -37,18 +37,18 @@ func main() {
for i := 0; i < 15; i++ {
function := functions[lib.RandIntBetween(0, len(functions)-1)]
val := node{
f: function,
arr: lib.MultRandIntBetween(-1000000, 1000000),
f: function,
a: lib.MultRandIntBetween(-1000000, 1000000),
}
table = append(table, val)
}
table = append(table, node{
f: is.Prime,
arr: []int{1, 2, 3, 4, 5, 6},
f: is.Prime,
a: []int{1, 2, 3, 4, 5, 6},
})
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"
"os"
"strconv"
"unicode"
)
func IsNumeric(s string) bool {
for _, r := range s {
if !unicode.IsDigit(r) {
return false
}
}
return true
}
func main() {
arguments := os.Args[1:]
for i := range arguments {
if IsNumeric(arguments[i]) {
number, _ := strconv.Atoi(arguments[i])
boole := false
if os.Args[1] == "--upper" {
boole = true
}
if number <= 26 && number >= 1 && !boole {
number += 96
fmt.Printf("%c", rune(number))
} else if number <= 26 && number >= 1 && boole {
number += 64
fmt.Printf("%c", rune(number))
} else {
fmt.Print(" ")
}
args := os.Args[1:]
if len(args) == 0 {
return
}
var upper bool
if args[0] == "--upper" {
upper = true
args = args[1:]
}
for _, arg := range args {
if nb, err := strconv.Atoi(arg); err != nil || nb < 1 || nb > 26 {
fmt.Print(" ")
} else {
if !(arguments[i] == "--upper" && i == 0) {
fmt.Print(" ")
if upper {
nb += 'A' - 1
} else {
nb += 'a' - 1
}
fmt.Printf("%c", rune(nb))
}
}
fmt.Println()

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

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

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

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

21
go/tests/printbits/main.go

@ -8,18 +8,19 @@ import (
)
func main() {
var arg []string
var args []string
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, "")
arg = append(arg, "a")
arg = append(arg, "bc")
arg = append(arg, "def")
arg = append(arg, "notanumber")
arg = append(arg, lib.RandBasic())
for _, v := range arg {
args = append(args,
"",
"a",
"bc",
"def",
"notanumber",
lib.RandBasic(),
)
for _, v := range args {
lib.ChallengeMain("printbits", strings.Fields(v)...)
}
}

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

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

30
go/tests/printchessboard/main.go

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

5
go/tests/printcomb/main.go

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

11
go/tests/printcomb2/main.go

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

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

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

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

@ -6,31 +6,12 @@ import (
"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() {
if len(os.Args) != 2 {
fmt.Println()
} else {
nbr, _ := strconv.Atoi(os.Args[1])
if nbr != 0 {
printBase(nbr, "0123456789abcdef")
fmt.Println()
if len(os.Args) == 2 {
if i, err := strconv.Atoi(os.Args[1]); err == nil && i > 0 {
fmt.Printf("%x\n", i)
} else {
fmt.Println(0)
fmt.Println("ERROR")
}
}
}

9
go/tests/printhex/main.go

@ -8,21 +8,18 @@ import (
)
func main() {
var table []string
table = append(table,
table := []string{
" ",
"123 132 1",
"1 5",
"0",
)
}
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++ {
table = append(table, strconv.Itoa(i))
}
for _, s := range table {
lib.ChallengeMain("printhex", strings.Fields(s)...)
}

12
go/tests/printmemory/main.go

@ -36,8 +36,8 @@ func printBase(nbr int) int {
return a
}
func printLine(arr [10]int, start int) {
size := len(arr)
func printLine(elems [10]int, start int) {
size := len(elems)
a := start
var aux, b int
@ -45,7 +45,7 @@ func printLine(arr [10]int, start int) {
if a%4 == 0 && a != 0 {
fmt.Println()
}
b = 8 - printBase(arr[a])
b = 8 - printBase(elems[a])
for aux != b {
if b == 6 {
fmt.Print("0")
@ -65,8 +65,8 @@ func printLine(arr [10]int, start int) {
fmt.Println()
c := start
for c < start+16 && c < size {
if unicode.IsPrint(rune(arr[c])) {
fmt.Printf("%c", rune(arr[c]))
if unicode.IsPrint(rune(elems[c])) {
fmt.Printf("%c", rune(elems[c]))
} else {
fmt.Print(".")
}
@ -93,7 +93,7 @@ func main() {
lib.Challenge("PrintMemory", student.PrintMemory, printMemory, table)
}
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

9
go/tests/printnbr/main.go

@ -7,18 +7,13 @@ import (
"github.com/01-edu/public/go/lib"
)
func printNbr(n int) {
fmt.Print(n)
}
func main() {
table := append(
lib.MultRandInt(),
table := append(lib.MultRandInt(),
lib.MinInt,
lib.MaxInt,
0,
)
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()
if err != nil {
lib.Fatalln(b)
lib.Fatalln(string(b))
}
if string(b) != name+"\n" {
lib.Fatalln("Failed to print the program name")

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

@ -3,19 +3,15 @@ package main
import "fmt"
func main() {
for a := 9; a >= 2; {
for b := a - 1; b >= 1; {
for c := b - 1; c >= 0; {
if a > b && b > c && a+b+c != 3 {
fmt.Printf("%d%d%d, ", a, b, c)
for a := 9; a >= 2; a-- {
for b := a - 1; b >= 1; b-- {
for c := b - 1; c >= 0; 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"
func main() {
for r := 'z'; r >= 'a'; r-- {
fmt.Print(r)
}
fmt.Println()
fmt.Println("zyxwvutsrqponmlkjihgfedcba")
}

9
go/tests/printstr/main.go

@ -7,14 +7,9 @@ import (
"github.com/01-edu/public/go/lib"
)
func printStr(s string) {
fmt.Print(s)
}
func main() {
table := lib.MultRandASCII()
table = append(table, "Hello World!")
table := append(lib.MultRandASCII(), "Hello World!")
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() {
table := [][]string{}
// 30 random slice of slice of strings
table := [][]string{{"Hello", "how", "are", "you?"}}
// 30 random slice of slice of strings
for i := 0; i < 30; i++ {
table = append(table, lib.MultRandASCII())
}
table = append(table,
[]string{"Hello", "how", "are", "you?"})
for _, arg := range table {
lib.Challenge("PrintWordsTables", student.PrintWordsTables, printWordsTables, arg)
}

5
go/tests/priorprime/main.go

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

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

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

2
go/tests/reachablenumber/main.go

@ -30,7 +30,7 @@ func main() {
2,
}
for i := 0; i < 25; i++ {
table = append(table, lib.MultRandIntBetween(1, 877))
table = append(table, lib.MultRandIntBetween(1, 877)...)
}
for _, arg := range table {
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
}
func calArea(ptr *rectangle) int {
func calcArea(ptr *rectangle) int {
return (ptr.upLeft.x - ptr.downRight.x) * (ptr.downRight.y - ptr.upLeft.y)
}
@ -60,5 +60,5 @@ func main() {
}
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 {
return 1
}
return nb * RecursiveFactorial(nb-1)
return nb * recursiveFactorial(nb-1)
}
func main() {

4
go/tests/recursivepower/main.go

@ -22,6 +22,6 @@ func main() {
lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, nb, power)
i++
}
lib.Challenge("RecursivePower", student.RecursivePower, correct.RecursivePower, 0, 0)
lib.Challenge("RecursivePower", student.RecursivePower, correct.RecursivePower, 0, 1)
lib.Challenge("RecursivePower", student.RecursivePower, recursivePower, 0, 0)
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"
)
func reduceInt(f func(int, int) int, a []int) {
func reduceInt(a []int, f func(int, int) int) {
acc := a[0]
for i := 1; i < len(a); i++ {
acc = f(acc, a[i])
@ -45,7 +45,7 @@ func main() {
for _, v := range table {
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"
"os"
"strconv"
"github.com/01-edu/public/go/lib"
)
func main() {
if len(os.Args) == 3 {
secondArg := 0
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()
if len(os.Args) != 3 {
return
}
}
func reverseRange(start, end int) []int {
var rran []int
if end >= start {
for i := end; i >= start; i-- {
rran = append(rran, i)
}
return rran
a, err := strconv.Atoi(os.Args[1])
if err != nil {
panic("ERROR: " + err.Error())
}
for i := end; i <= start; i++ {
rran = append(rran, i)
b, err := strconv.Atoi(os.Args[2])
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 (
"fmt"
"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() {
if len(os.Args) < 2 {
fmt.Println()
os.Exit(0)
}
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)
for _, arg := range os.Args[1:] {
arg := []rune(arg)
for j, r := range arg {
if j+1 == len(arg) || arg[j+1] == ' ' {
arg[j] = unicode.ToUpper(r)
} else {
arg[j] = lowerCase(c)
arg[j] = unicode.ToLower(r)
}
}
fmt.Println(string(arg))

3
go/tests/reversestrcap/main.go

@ -8,14 +8,13 @@ func main() {
args := [][]string{
{"First SMALL TesT"},
{"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++ {
args = append(args, lib.MultRandAlnum())
}
args = append(args, []string{""})
for _, v := range args {
lib.ChallengeMain("reversestrcap", v...)
}

36
go/tests/revivethreenums/main.go

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

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

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

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

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

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

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

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

@ -3,41 +3,35 @@ package main
import (
"fmt"
"os"
"regexp"
"strings"
)
func main() {
var arr []rune
var revarr []rune
vowels := regexp.MustCompile(`[aeiouAEIOU]`)
for i := 1; i < len(os.Args); i++ {
for _, k := range os.Args[i] {
mached := vowels.MatchString(string(k))
if mached {
arr = append(arr, rune(k))
var a1, a2, rev []rune
for _, arg := range os.Args[1:] {
for _, k := range arg {
if strings.ContainsRune("aeiouAEIOU", k) {
a1 = append(a1, k)
}
}
}
for i := len(arr) - 1; i >= 0; i-- {
revarr = append(revarr, arr[i])
for i := len(a1) - 1; i >= 0; i-- {
rev = append(rev, a1[i])
}
arr2 := []rune{}
m := 0
for i := 1; i < len(os.Args); i++ {
for _, j := range os.Args[i] {
mached := vowels.MatchString(string(j))
if mached {
arr2 = append(arr2, rune(revarr[m]))
for i, arg := range os.Args[1:] {
for _, j := range arg {
if strings.ContainsRune("aeiouAEIOU", j) {
a2 = append(a2, rev[m])
m++
} else {
arr2 = append(arr2, rune(j))
a2 = append(a2, j)
}
}
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() {
Lower := lib.RuneRange('a', 'z')
Upper := lib.RuneRange('A', 'Z')
letters := Lower + Upper + " "
var arr []string
letters := lib.Lower + lib.Upper + " "
a := []string{""}
for i := 0; i < 10; i++ {
str := lib.RandStr(lib.RandIntBetween(2, 20), letters)
arr = append(arr, str)
a = append(a, lib.RandStr(lib.RandIntBetween(2, 20), letters))
}
arr = append(arr, "")
for _, v := range arr {
for _, v := range a {
lib.ChallengeMain("rotatevowels", strings.Fields(v)...)
}
lib.ChallengeMain("rotatevowels", "Hello World")

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

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

8
go/tests/slice/main.go

@ -47,7 +47,7 @@ func slice(a []string, nbr ...int) []string {
}
func main() {
arr := [][]interface{}{
elems := [][]interface{}{
{
[]string{"coding", "algorithm", "ascii", "package", "golang"},
1,
@ -72,14 +72,14 @@ func main() {
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++ {
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...)
}
}

22
go/tests/sortwordarr/main.go

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

6
go/tests/split/main.go

@ -8,10 +8,6 @@ import (
"github.com/01-edu/public/go/lib"
)
func split(s, sep string) []string {
return strings.Split(s, sep)
}
func main() {
separators := []string{"!=HA=!",
"!==!",
@ -42,6 +38,6 @@ func main() {
node{str: "HelloHAhowHAareHAyou?", sep: "HA"})
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"
)
func splitWhiteSpaces(s string) []string {
return strings.Fields(s)
}
func main() {
table := []string{}
// 30 random slice of strings
table := []string{"Hello how are you?"}
// 30 random slice of strings
for i := 0; i < 30; i++ {
val := strings.Join(lib.MultRandASCII(), " ")
table = append(table, val)
table = append(table, strings.Join(lib.MultRandASCII(), " "))
}
table = append(table,
"Hello how are you?")
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() {
table := append(
lib.MultRandIntBetween(-1000000, 1000000),
table := append(lib.MultRandIntBetween(-1000000, 1000000),
0,
1,
2,

12
go/tests/strlen/main.go

@ -5,14 +5,8 @@ import (
"github.com/01-edu/public/go/lib"
)
func strLen(str string) int {
len := 0
strConverted := []rune(str)
for i, _ := range strConverted {
len = i + 1
}
return len
func strLen(s string) int {
return len([]rune(s))
}
func main() {
@ -31,3 +25,5 @@ func main() {
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"
)
func Swap(a, b *int) {
*a, *b = *b, *a
}
func main() {
i := 0
for i < 30 {

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

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

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

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

11
go/tests/tolower/main.go

@ -7,16 +7,9 @@ import (
"github.com/01-edu/public/go/lib"
)
func toLower(s string) string {
return strings.ToLower(s)
}
func main() {
table := append(
lib.MultRandASCII(),
"Hello! How are you?",
)
table := append(lib.MultRandASCII(), "Hello! How are you?")
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"
)
func toUpper(s string) string {
return strings.ToUpper(s)
}
func main() {
table := lib.MultRandASCII()
table = append(table,
"Hello! How are you?",
)
table := append(lib.MultRandASCII(), "Hello! How are you?")
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"
)
func trimAtoi(str string) int {
chars := []rune(str)
for i := range str {
chars[i] = rune(str[i])
func trimAtoi(s string) int {
runes := []rune(s)
for i := range s {
runes[i] = rune(s[i])
}
var numbers []rune
for i := range chars {
if (chars[i] >= '0' && chars[i] <= '9') || (len(numbers) == 0 && (chars[i]) == '-' || chars[i] == '+') {
numbers = append(numbers, chars[i])
for _, r := range runes {
if (r >= '0' && r <= '9') || (len(numbers) == 0 && (r) == '-' || r == '+') {
numbers = append(numbers, r)
}
}
if len(numbers) == 0 || (len(numbers) == 1 && (numbers[0] == '-' || numbers[0] == '+')) {
@ -68,3 +68,5 @@ func main() {
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"
)
func UltimateDivMod(a, b *int) {
temp := *a
*a = *a / *b
*b = temp % *b
}
func main() {
i := 0
for i < lib.SliceLen {

4
go/tests/ultimatepointone/main.go

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

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

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

24
go/tests/union/main.go

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

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

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

35
go/tests/unmatch/main.go

@ -6,11 +6,11 @@ import (
)
// 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
for _, el := range arr {
for _, el := range elems {
quant = 0
for _, v := range arr {
for _, v := range elems {
if v == el {
quant++
}
@ -23,22 +23,19 @@ func unmatch(arr []int) int {
}
func main() {
arg1 := []int{1, 1, 2, 3, 4, 3, 4}
arg2 := []int{1, 1, 2, 4, 3, 4, 2, 3, 4}
arg3 := []int{1, 2, 1, 1, 4, 5, 5, 4, 1, 7}
arg4 := []int{1, 2, 3, 4, 5, 6, 7, 8}
arg5 := []int{0, 20, 91, 23, 10, 34}
arg6 := []int{1, 1, 2, 2, 3, 4, 3, 4, 5, 5, 8, 9, 8, 9}
randInt1 := lib.RandIntBetween(-100, 100)
randInt2 := lib.RandIntBetween(-1000, 1000)
randInt3 := lib.RandIntBetween(-10, 10)
arg7 := []int{randInt1, randInt2, randInt1, randInt2, randInt1 + randInt3, randInt1 + randInt3}
arg8 := []int{randInt1, randInt2, randInt1, randInt2, randInt1 + randInt3, randInt2 - randInt3}
args := [][]int{arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8}
i1 := lib.RandIntBetween(-100, 100)
i2 := lib.RandIntBetween(-1000, 1000)
i3 := lib.RandIntBetween(-10, 10)
args := [][]int{
{1, 1, 2, 3, 4, 3, 4},
{1, 1, 2, 4, 3, 4, 2, 3, 4},
{1, 2, 1, 1, 4, 5, 5, 4, 1, 7},
{1, 2, 3, 4, 5, 6, 7, 8},
{0, 20, 91, 23, 10, 34},
{1, 1, 2, 2, 3, 4, 3, 4, 5, 5, 8, 9, 8, 9},
{i1, i2, i1, i2, i1 + i3, i1 + i3},
{i1, i2, i1, i2, i1 + i3, i2 - i3},
}
for _, v := range args {
lib.Challenge("Unmatch", student.Unmatch, unmatch, v)
}

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

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

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.
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'.

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'`).
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

2
subjects/displayfirstparam.en.md

@ -2,7 +2,7 @@
### 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

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

Loading…
Cancel
Save