From cb053ae19093c058af925514f425ae2812687c04 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Tue, 12 May 2020 18:59:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=B5=20Le=20reEEEfactOOOOr=20est=20touJ?= =?UTF-8?q?OUUUrs=20plUUS=20fOOORT=20=F0=9F=8E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/addition_of_exercise_draft.md | 2 +- go/lib/is/is.go | 2 +- go/lib/lib.go | 20 +++- go/tests/addprimesum/correct/main.go | 25 +---- go/tests/addprimesum/main.go | 24 +---- go/tests/any/main.go | 5 +- go/tests/appendrange/main.go | 3 - go/tests/balancedstring/correct/main.go | 17 ++-- go/tests/basicjoin/main.go | 9 +- go/tests/brackets/correct/main.go | 4 +- go/tests/collatzcountdown/main.go | 11 +-- go/tests/comcheck/correct/main.go | 4 +- go/tests/compact/main.go | 38 ++++---- go/tests/compare/main.go | 6 +- go/tests/concat/main.go | 8 +- go/tests/costumeprofit/correct/main.go | 4 +- go/tests/costumeprofit/main.go | 31 ++---- go/tests/countdown/correct/main.go | 7 +- go/tests/countif/main.go | 34 +++---- go/tests/displaya/main.go | 12 +-- go/tests/displayalpham/correct/main.go | 10 +- go/tests/displayalrevm/correct/main.go | 10 +- go/tests/displayfirstparam/main.go | 11 ++- go/tests/displaylastparam/main.go | 10 +- go/tests/displayz/main.go | 11 ++- go/tests/divmod/main.go | 5 - go/tests/doop/correct/main.go | 63 +++++++------ go/tests/doppelganger/main.go | 6 +- go/tests/eightqueens/main.go | 12 +-- go/tests/enigma/main.go | 19 +--- go/tests/expandstr/correct/main.go | 24 ++--- go/tests/fib/main.go | 9 +- go/tests/fibonacci/main.go | 13 ++- go/tests/findnextprime/main.go | 3 +- go/tests/findprevprime/main.go | 4 +- go/tests/firstword/correct/main.go | 15 +-- go/tests/game23/main.go | 8 +- go/tests/gcd/correct/main.go | 21 ++--- go/tests/gcd/main.go | 6 +- go/tests/grouping/correct/main.go | 2 +- go/tests/issorted/main.go | 10 +- go/tests/itoa/main.go | 7 +- go/tests/map/main.go | 18 ++-- go/tests/nbrconvertalpha/correct/main.go | 47 ++++------ go/tests/piglatin/correct/main.go | 31 ++---- go/tests/printalphabet/correct/main.go | 5 +- go/tests/printbits/main.go | 21 +++-- go/tests/printchessboard/correct/main.go | 4 +- go/tests/printchessboard/main.go | 30 +++--- go/tests/printcomb/main.go | 5 +- go/tests/printcomb2/main.go | 11 +-- go/tests/printdigits/correct/main.go | 5 +- go/tests/printhex/correct/main.go | 27 +----- go/tests/printhex/main.go | 9 +- go/tests/printmemory/main.go | 12 +-- go/tests/printnbr/main.go | 9 +- go/tests/printprogramname/main.go | 2 +- go/tests/printrevcomb/correct/main.go | 18 ++-- go/tests/printreversealphabet/correct/main.go | 5 +- go/tests/printstr/main.go | 9 +- go/tests/printwordstables/main.go | 7 +- go/tests/priorprime/main.go | 5 +- go/tests/range/correct/main.go | 29 ++---- go/tests/reachablenumber/main.go | 2 +- go/tests/rectangle/correct/main.go | 4 +- go/tests/recursivefactorial/main.go | 2 +- go/tests/recursivepower/main.go | 4 +- go/tests/reduceint/main.go | 4 +- go/tests/reverserange/correct/main.go | 36 +++---- go/tests/reversestrcap/correct/main.go | 34 ++----- go/tests/reversestrcap/main.go | 3 +- go/tests/revivethreenums/main.go | 36 +++---- go/tests/revwstr/correct/main.go | 10 +- go/tests/romannumbers/correct/main.go | 2 +- go/tests/rostring/correct/main.go | 4 +- go/tests/rotatevowels/correct/main.go | 36 +++---- go/tests/rotatevowels/main.go | 12 +-- go/tests/rpncalc/correct/main.go | 94 +++++++++---------- go/tests/slice/main.go | 8 +- go/tests/sortwordarr/main.go | 22 ++--- go/tests/split/main.go | 6 +- go/tests/splitwhitespaces/main.go | 17 +--- go/tests/sqrt/main.go | 3 +- go/tests/strlen/main.go | 12 +-- go/tests/swap/main.go | 4 - go/tests/switchcase/correct/main.go | 5 +- go/tests/tabmult/correct/main.go | 4 +- go/tests/tolower/main.go | 11 +-- go/tests/toupper/main.go | 13 +-- go/tests/trimatoi/main.go | 16 ++-- go/tests/ultimatedivmod/main.go | 6 -- go/tests/ultimatepointone/main.go | 4 - go/tests/union/correct/main.go | 33 +++---- go/tests/union/main.go | 24 ++--- go/tests/uniqueoccurences/correct/main.go | 28 ++---- go/tests/unmatch/main.go | 35 ++++--- go/tests/wdmatch/correct/main.go | 27 +++--- subjects/balancedstring.en.md | 2 +- subjects/displaya.en.md | 2 +- subjects/displayfirstparam.en.md | 2 +- subjects/displaylastparam.en.md | 4 +- subjects/displayz.en.md | 2 +- subjects/expandstr.en.md | 3 +- subjects/firstword.en.md | 2 +- subjects/gcd.en.md | 2 +- subjects/hiddenp.en.md | 2 +- subjects/iterativepower.en.md | 4 +- subjects/lastword.en.md | 2 +- subjects/nbrconvertalpha.en.md | 2 +- subjects/piglatin.en.md | 2 +- subjects/point.en.md | 2 +- subjects/printbits.en.md | 2 +- subjects/printhex.en.md | 11 +-- subjects/printmemory.en.md | 3 +- subjects/printnbrinorder.en.md | 2 +- subjects/range.en.md | 2 +- subjects/rectangle.en.md | 2 +- subjects/recursivepower.en.md | 4 +- subjects/reduceint.en.md | 10 +- subjects/reversestrcap.en.md | 12 +-- subjects/revwstr.en.md | 4 +- subjects/sqrt.en.md | 7 +- subjects/uniqueoccurences.en.md | 10 +- subjects/unmatch.en.md | 8 +- subjects/wdmatch.en.md | 14 +-- 125 files changed, 566 insertions(+), 973 deletions(-) diff --git a/docs/addition_of_exercise_draft.md b/docs/addition_of_exercise_draft.md index 4d2a5db1..7614115d 100644 --- a/docs/addition_of_exercise_draft.md +++ b/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 `*`. (formating requirement) -- If the number of parameters is different from 1, the program displays a newline. (special case requirement, this case will need to be tested) +- If the number of arguments is different from 1, the program displays a newline. (special case requirement, this case will need to be tested) - The input, when there is one, will always be valid. (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) diff --git a/go/lib/is/is.go b/go/lib/is/is.go index a80df059..09fb1893 100644 --- a/go/lib/is/is.go +++ b/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 } } diff --git a/go/lib/lib.go b/go/lib/lib.go index 03eb723d..2be6bf85 100644 --- a/go/lib/lib.go +++ b/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") diff --git a/go/tests/addprimesum/correct/main.go b/go/tests/addprimesum/correct/main.go index e722cd38..7cc0d0d0 100644 --- a/go/tests/addprimesum/correct/main.go +++ b/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 } } diff --git a/go/tests/addprimesum/main.go b/go/tests/addprimesum/main.go index 0ab7920e..5f31018f 100644 --- a/go/tests/addprimesum/main.go +++ b/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) } } diff --git a/go/tests/any/main.go b/go/tests/any/main.go index 7cfbd5a7..03cf5053 100644 --- a/go/tests/any/main.go +++ b/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 } diff --git a/go/tests/appendrange/main.go b/go/tests/appendrange/main.go index 10a631fb..c1f2cf46 100644 --- a/go/tests/appendrange/main.go +++ b/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 } diff --git a/go/tests/balancedstring/correct/main.go b/go/tests/balancedstring/correct/main.go index 21583a2e..92623c66 100644 --- a/go/tests/balancedstring/correct/main.go +++ b/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) } diff --git a/go/tests/basicjoin/main.go b/go/tests/basicjoin/main.go index 49386d90..c0b1f79f 100644 --- a/go/tests/basicjoin/main.go +++ b/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() { diff --git a/go/tests/brackets/correct/main.go b/go/tests/brackets/correct/main.go index 27c094d9..54403216 100644 --- a/go/tests/brackets/correct/main.go +++ b/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++ diff --git a/go/tests/collatzcountdown/main.go b/go/tests/collatzcountdown/main.go index 6abc2e40..256e48f7 100644 --- a/go/tests/collatzcountdown/main.go +++ b/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) } diff --git a/go/tests/comcheck/correct/main.go b/go/tests/comcheck/correct/main.go index b3084b56..1ba7c1e9 100644 --- a/go/tests/comcheck/correct/main.go +++ b/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++ } } diff --git a/go/tests/compact/main.go b/go/tests/compact/main.go index 856944bc..0179fe48 100644 --- a/go/tests/compact/main.go +++ b/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, ) } } diff --git a/go/tests/compare/main.go b/go/tests/compare/main.go index 99bd2b34..6d5b7c2f 100644 --- a/go/tests/compare/main.go +++ b/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) } } diff --git a/go/tests/concat/main.go b/go/tests/concat/main.go index 7b224265..28be36ec 100644 --- a/go/tests/concat/main.go +++ b/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]) } } diff --git a/go/tests/costumeprofit/correct/main.go b/go/tests/costumeprofit/correct/main.go index 443b0b0a..0202d20b 100644 --- a/go/tests/costumeprofit/correct/main.go +++ b/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)) } diff --git a/go/tests/costumeprofit/main.go b/go/tests/costumeprofit/main.go index 6960a239..52cd541c 100644 --- a/go/tests/costumeprofit/main.go +++ b/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)), + ) } } diff --git a/go/tests/countdown/correct/main.go b/go/tests/countdown/correct/main.go index aec32ddd..ecb2baf7 100644 --- a/go/tests/countdown/correct/main.go +++ b/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) } diff --git a/go/tests/countif/main.go b/go/tests/countif/main.go index 6e1a2bde..46e0e25d 100644 --- a/go/tests/countif/main.go +++ b/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) } } diff --git a/go/tests/displaya/main.go b/go/tests/displaya/main.go index 7eb3e025..e9e35cd4 100644 --- a/go/tests/displaya/main.go +++ b/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") } diff --git a/go/tests/displayalpham/correct/main.go b/go/tests/displayalpham/correct/main.go index 67f54a2b..a10580a2 100644 --- a/go/tests/displayalpham/correct/main.go +++ b/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") } diff --git a/go/tests/displayalrevm/correct/main.go b/go/tests/displayalrevm/correct/main.go index 87f45afb..248906a6 100644 --- a/go/tests/displayalrevm/correct/main.go +++ b/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") } diff --git a/go/tests/displayfirstparam/main.go b/go/tests/displayfirstparam/main.go index f3a2c59d..a7b06b9d 100644 --- a/go/tests/displayfirstparam/main.go +++ b/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)...) } diff --git a/go/tests/displaylastparam/main.go b/go/tests/displaylastparam/main.go index 93c9e6c4..deccee2e 100644 --- a/go/tests/displaylastparam/main.go +++ b/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)...) } diff --git a/go/tests/displayz/main.go b/go/tests/displayz/main.go index b09a8684..f15a95da 100644 --- a/go/tests/displayz/main.go +++ b/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)...) } diff --git a/go/tests/divmod/main.go b/go/tests/divmod/main.go index 5535c7f5..b2d4b59f 100644 --- a/go/tests/divmod/main.go +++ b/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 { diff --git a/go/tests/doop/correct/main.go b/go/tests/doop/correct/main.go index b3667d3d..d1c06328 100644 --- a/go/tests/doop/correct/main.go +++ b/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) } } diff --git a/go/tests/doppelganger/main.go b/go/tests/doppelganger/main.go index e6c89b96..f220dd15 100644 --- a/go/tests/doppelganger/main.go +++ b/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) } } diff --git a/go/tests/eightqueens/main.go b/go/tests/eightqueens/main.go index fabc544f..3de77767 100644 --- a/go/tests/eightqueens/main.go +++ b/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++ } } diff --git a/go/tests/enigma/main.go b/go/tests/enigma/main.go index c6246964..5dc4a369 100644 --- a/go/tests/enigma/main.go +++ b/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... diff --git a/go/tests/expandstr/correct/main.go b/go/tests/expandstr/correct/main.go index fbe1a284..9752d404 100644 --- a/go/tests/expandstr/correct/main.go +++ b/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() } diff --git a/go/tests/fib/main.go b/go/tests/fib/main.go index f7bd0a9f..369afa60 100644 --- a/go/tests/fib/main.go +++ b/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) } diff --git a/go/tests/fibonacci/main.go b/go/tests/fibonacci/main.go index b92c0093..4ce51bd9 100644 --- a/go/tests/fibonacci/main.go +++ b/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, diff --git a/go/tests/findnextprime/main.go b/go/tests/findnextprime/main.go index dfc4a295..c02e143e 100644 --- a/go/tests/findnextprime/main.go +++ b/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, diff --git a/go/tests/findprevprime/main.go b/go/tests/findprevprime/main.go index d1977323..d91b57fa 100644 --- a/go/tests/findprevprime/main.go +++ b/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) } } diff --git a/go/tests/firstword/correct/main.go b/go/tests/firstword/correct/main.go index cbdbb6b7..1c711163 100644 --- a/go/tests/firstword/correct/main.go +++ b/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]) } } diff --git a/go/tests/game23/main.go b/go/tests/game23/main.go index 61f3be03..303fde8b 100644 --- a/go/tests/game23/main.go +++ b/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 } diff --git a/go/tests/gcd/correct/main.go b/go/tests/gcd/correct/main.go index f6cd7eb3..2e20c6a3 100644 --- a/go/tests/gcd/correct/main.go +++ b/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)) } diff --git a/go/tests/gcd/main.go b/go/tests/gcd/main.go index b709a7d9..020c68fa 100644 --- a/go/tests/gcd/main.go +++ b/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...) diff --git a/go/tests/grouping/correct/main.go b/go/tests/grouping/correct/main.go index 93560058..b953ef0d 100644 --- a/go/tests/grouping/correct/main.go +++ b/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 { diff --git a/go/tests/issorted/main.go b/go/tests/issorted/main.go index 0a40d79d..c5a75051 100644 --- a/go/tests/issorted/main.go +++ b/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 } } diff --git a/go/tests/itoa/main.go b/go/tests/itoa/main.go index 5fa81244..5a8fc2d9 100644 --- a/go/tests/itoa/main.go +++ b/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()) } } diff --git a/go/tests/map/main.go b/go/tests/map/main.go index 444da880..f42a6628 100644 --- a/go/tests/map/main.go +++ b/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) } } diff --git a/go/tests/nbrconvertalpha/correct/main.go b/go/tests/nbrconvertalpha/correct/main.go index 85fc73b7..952fba16 100644 --- a/go/tests/nbrconvertalpha/correct/main.go +++ b/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() diff --git a/go/tests/piglatin/correct/main.go b/go/tests/piglatin/correct/main.go index 3dba5587..70d16630 100644 --- a/go/tests/piglatin/correct/main.go +++ b/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") } } diff --git a/go/tests/printalphabet/correct/main.go b/go/tests/printalphabet/correct/main.go index ba71b1b2..7927c0f4 100644 --- a/go/tests/printalphabet/correct/main.go +++ b/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") } diff --git a/go/tests/printbits/main.go b/go/tests/printbits/main.go index fa888f0b..baf4a454 100644 --- a/go/tests/printbits/main.go +++ b/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)...) } } diff --git a/go/tests/printchessboard/correct/main.go b/go/tests/printchessboard/correct/main.go index 3971380b..3915fc94 100644 --- a/go/tests/printchessboard/correct/main.go +++ b/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) } diff --git a/go/tests/printchessboard/main.go b/go/tests/printchessboard/main.go index 7b2cb388..6cfac0da 100644 --- a/go/tests/printchessboard/main.go +++ b/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 { diff --git a/go/tests/printcomb/main.go b/go/tests/printcomb/main.go index 49042e7c..026ea396 100644 --- a/go/tests/printcomb/main.go +++ b/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() { diff --git a/go/tests/printcomb2/main.go b/go/tests/printcomb2/main.go index 4a9eca18..de1602da 100644 --- a/go/tests/printcomb2/main.go +++ b/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() } diff --git a/go/tests/printdigits/correct/main.go b/go/tests/printdigits/correct/main.go index d67da467..872307c1 100644 --- a/go/tests/printdigits/correct/main.go +++ b/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") } diff --git a/go/tests/printhex/correct/main.go b/go/tests/printhex/correct/main.go index 5218b8fd..0c0cf278 100644 --- a/go/tests/printhex/correct/main.go +++ b/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") } } } diff --git a/go/tests/printhex/main.go b/go/tests/printhex/main.go index 71eb5f3f..6599aa3e 100644 --- a/go/tests/printhex/main.go +++ b/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)...) } diff --git a/go/tests/printmemory/main.go b/go/tests/printmemory/main.go index b8ea7400..27a3b8ee 100644 --- a/go/tests/printmemory/main.go +++ b/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 diff --git a/go/tests/printnbr/main.go b/go/tests/printnbr/main.go index 924b28ee..277be00c 100644 --- a/go/tests/printnbr/main.go +++ b/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) } } diff --git a/go/tests/printprogramname/main.go b/go/tests/printprogramname/main.go index 4a955d23..6c508e25 100644 --- a/go/tests/printprogramname/main.go +++ b/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") diff --git a/go/tests/printrevcomb/correct/main.go b/go/tests/printrevcomb/correct/main.go index 110ad84a..0ca625b4 100644 --- a/go/tests/printrevcomb/correct/main.go +++ b/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() } diff --git a/go/tests/printreversealphabet/correct/main.go b/go/tests/printreversealphabet/correct/main.go index 3a1e62ce..5ef689aa 100644 --- a/go/tests/printreversealphabet/correct/main.go +++ b/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") } diff --git a/go/tests/printstr/main.go b/go/tests/printstr/main.go index 5876ab0b..2112ac56 100644 --- a/go/tests/printstr/main.go +++ b/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) } } diff --git a/go/tests/printwordstables/main.go b/go/tests/printwordstables/main.go index fbddf533..f9466150 100644 --- a/go/tests/printwordstables/main.go +++ b/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) } diff --git a/go/tests/priorprime/main.go b/go/tests/priorprime/main.go index 50c9504a..33f699eb 100644 --- a/go/tests/priorprime/main.go +++ b/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) } diff --git a/go/tests/range/correct/main.go b/go/tests/range/correct/main.go index 8081bf37..1ec42854 100644 --- a/go/tests/range/correct/main.go +++ b/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)) } diff --git a/go/tests/reachablenumber/main.go b/go/tests/reachablenumber/main.go index eb1e3da6..10773f77 100644 --- a/go/tests/reachablenumber/main.go +++ b/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) diff --git a/go/tests/rectangle/correct/main.go b/go/tests/rectangle/correct/main.go index 8cf99852..ea66623e 100644 --- a/go/tests/rectangle/correct/main.go +++ b/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)) } diff --git a/go/tests/recursivefactorial/main.go b/go/tests/recursivefactorial/main.go index 98ae8f6d..be19122e 100644 --- a/go/tests/recursivefactorial/main.go +++ b/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() { diff --git a/go/tests/recursivepower/main.go b/go/tests/recursivepower/main.go index 4c595883..feba2414 100644 --- a/go/tests/recursivepower/main.go +++ b/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) } diff --git a/go/tests/reduceint/main.go b/go/tests/reduceint/main.go index 57d50b71..efe712a0 100644 --- a/go/tests/reduceint/main.go +++ b/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) } } } diff --git a/go/tests/reverserange/correct/main.go b/go/tests/reverserange/correct/main.go index a86af8c8..1ec42854 100644 --- a/go/tests/reverserange/correct/main.go +++ b/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)) } diff --git a/go/tests/reversestrcap/correct/main.go b/go/tests/reversestrcap/correct/main.go index e4ae86fb..3b2b11f2 100644 --- a/go/tests/reversestrcap/correct/main.go +++ b/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)) diff --git a/go/tests/reversestrcap/main.go b/go/tests/reversestrcap/main.go index c9198ae7..b92370eb 100644 --- a/go/tests/reversestrcap/main.go +++ b/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...) } diff --git a/go/tests/revivethreenums/main.go b/go/tests/revivethreenums/main.go index 104bc621..57fb038e 100644 --- a/go/tests/revivethreenums/main.go +++ b/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 } diff --git a/go/tests/revwstr/correct/main.go b/go/tests/revwstr/correct/main.go index 62d1534b..0ffae714 100644 --- a/go/tests/revwstr/correct/main.go +++ b/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(" ") } diff --git a/go/tests/romannumbers/correct/main.go b/go/tests/romannumbers/correct/main.go index 604a0d6f..bc2319e8 100644 --- a/go/tests/romannumbers/correct/main.go +++ b/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"}, diff --git a/go/tests/rostring/correct/main.go b/go/tests/rostring/correct/main.go index 7c37e877..896c44af 100644 --- a/go/tests/rostring/correct/main.go +++ b/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) } diff --git a/go/tests/rotatevowels/correct/main.go b/go/tests/rotatevowels/correct/main.go index 04a555cf..979d777e 100644 --- a/go/tests/rotatevowels/correct/main.go +++ b/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)) } diff --git a/go/tests/rotatevowels/main.go b/go/tests/rotatevowels/main.go index db9f57b3..e7d3f775 100644 --- a/go/tests/rotatevowels/main.go +++ b/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") diff --git a/go/tests/rpncalc/correct/main.go b/go/tests/rpncalc/correct/main.go index 7a21a9d3..74224b54 100644 --- a/go/tests/rpncalc/correct/main.go +++ b/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") } diff --git a/go/tests/slice/main.go b/go/tests/slice/main.go index 59c27221..0e9c5a82 100644 --- a/go/tests/slice/main.go +++ b/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...) } } diff --git a/go/tests/sortwordarr/main.go b/go/tests/sortwordarr/main.go index bc2312fd..906dfac0 100644 --- a/go/tests/sortwordarr/main.go +++ b/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, ) } } diff --git a/go/tests/split/main.go b/go/tests/split/main.go index a9e9c785..05503585 100644 --- a/go/tests/split/main.go +++ b/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) } } diff --git a/go/tests/splitwhitespaces/main.go b/go/tests/splitwhitespaces/main.go index 043018c1..d7783e9f 100644 --- a/go/tests/splitwhitespaces/main.go +++ b/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) } } diff --git a/go/tests/sqrt/main.go b/go/tests/sqrt/main.go index 4b5cb2da..6c80ef53 100644 --- a/go/tests/sqrt/main.go +++ b/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, diff --git a/go/tests/strlen/main.go b/go/tests/strlen/main.go index 93a50829..ce948684 100644 --- a/go/tests/strlen/main.go +++ b/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 diff --git a/go/tests/swap/main.go b/go/tests/swap/main.go index a3a51972..bdb67c08 100644 --- a/go/tests/swap/main.go +++ b/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 { diff --git a/go/tests/switchcase/correct/main.go b/go/tests/switchcase/correct/main.go index 1caf09a1..0dece4ff 100644 --- a/go/tests/switchcase/correct/main.go +++ b/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) { diff --git a/go/tests/tabmult/correct/main.go b/go/tests/tabmult/correct/main.go index 12fa2241..52fb3ea1 100644 --- a/go/tests/tabmult/correct/main.go +++ b/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() } diff --git a/go/tests/tolower/main.go b/go/tests/tolower/main.go index d5b3a563..ea6879c0 100644 --- a/go/tests/tolower/main.go +++ b/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) } } diff --git a/go/tests/toupper/main.go b/go/tests/toupper/main.go index a26de262..c136c194 100644 --- a/go/tests/toupper/main.go +++ b/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) } } diff --git a/go/tests/trimatoi/main.go b/go/tests/trimatoi/main.go index 9b57f801..a4c1215b 100644 --- a/go/tests/trimatoi/main.go +++ b/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 diff --git a/go/tests/ultimatedivmod/main.go b/go/tests/ultimatedivmod/main.go index 1e93068a..52222380 100644 --- a/go/tests/ultimatedivmod/main.go +++ b/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 { diff --git a/go/tests/ultimatepointone/main.go b/go/tests/ultimatepointone/main.go index 6404d05f..a1d5344f 100644 --- a/go/tests/ultimatepointone/main.go +++ b/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 diff --git a/go/tests/union/correct/main.go b/go/tests/union/correct/main.go index 4d46f00e..7a151b57 100644 --- a/go/tests/union/correct/main.go +++ b/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() } diff --git a/go/tests/union/main.go b/go/tests/union/main.go index 8550d602..1bef8f49 100644 --- a/go/tests/union/main.go +++ b/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...) diff --git a/go/tests/uniqueoccurences/correct/main.go b/go/tests/uniqueoccurences/correct/main.go index 1b24a108..3317c2e2 100644 --- a/go/tests/uniqueoccurences/correct/main.go +++ b/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])) } } diff --git a/go/tests/unmatch/main.go b/go/tests/unmatch/main.go index 05e907d6..d7457d9c 100644 --- a/go/tests/unmatch/main.go +++ b/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) } diff --git a/go/tests/wdmatch/correct/main.go b/go/tests/wdmatch/correct/main.go index 95f8482e..b7bd2b2d 100644 --- a/go/tests/wdmatch/correct/main.go +++ b/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]) + } } } diff --git a/subjects/balancedstring.en.md b/subjects/balancedstring.en.md index e9b589a8..b8a1702b 100644 --- a/subjects/balancedstring.en.md +++ b/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'. diff --git a/subjects/displaya.en.md b/subjects/displaya.en.md index 41a393d9..631cfe67 100644 --- a/subjects/displaya.en.md +++ b/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 diff --git a/subjects/displayfirstparam.en.md b/subjects/displayfirstparam.en.md index c4ab0470..da6d6564 100644 --- a/subjects/displayfirstparam.en.md +++ b/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 diff --git a/subjects/displaylastparam.en.md b/subjects/displaylastparam.en.md index 1bb4d36a..abcbcba6 100644 --- a/subjects/displaylastparam.en.md +++ b/subjects/displaylastparam.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a program that takes `string` as arguments, and displays its last argument. +Write a program that displays its last argument, if there is one. -### Expected output +### Usage ```console student@ubuntu:~/[[ROOT]]/test$ go build diff --git a/subjects/displayz.en.md b/subjects/displayz.en.md index 46fef229..bb2c3547 100644 --- a/subjects/displayz.en.md +++ b/subjects/displayz.en.md @@ -4,7 +4,7 @@ Write a program that takes a `string`, and displays the first `z` character it encounters in it, followed by a newline (`'\n'`). If there are no `z` characters in the string, the program just writes `z` followed by a newline (`'\n'`). -If the number of parameters is not 1, the program displays an `z` followed by a newline (`'\n'`). +If the number of arguments is not 1, the program displays an `z` followed by a newline (`'\n'`). ### Usage diff --git a/subjects/expandstr.en.md b/subjects/expandstr.en.md index 847864a4..af7561ac 100644 --- a/subjects/expandstr.en.md +++ b/subjects/expandstr.en.md @@ -8,7 +8,7 @@ The `string` will be followed by a newline (`'\n'`). A word is a sequence of alphanumerical characters. -If the number of parameters is not 1, or if there are no word, the program displays nothing. +If the number of arguments is not 1, or if there are no word, the program displays nothing. ### Usage @@ -19,7 +19,6 @@ you see it's easy to display the same thing$ student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr " only it's harder " | cat -e only it's harder$ student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr " how funny it is" "did you hear, Mathilde ?" | cat -e -$ student@ubuntu:~/[[ROOT]]/expandstr$ ./expandstr student@ubuntu:~/[[ROOT]]/expandstr$ ``` diff --git a/subjects/firstword.en.md b/subjects/firstword.en.md index 59565629..8aa226f8 100644 --- a/subjects/firstword.en.md +++ b/subjects/firstword.en.md @@ -8,7 +8,7 @@ Write a program that takes a `string` and displays its first word, followed by a - The output will be followed by a newline (`'\n'`). -- If the number of parameters is not 1, or if there are no words, the program displays nothing. +- If the number of arguments is not 1, or if there are no words, the program displays nothing. ### Usage diff --git a/subjects/gcd.en.md b/subjects/gcd.en.md index 44ebe08a..d725f79c 100644 --- a/subjects/gcd.en.md +++ b/subjects/gcd.en.md @@ -6,7 +6,7 @@ Write a program that takes two `string` representing two strictly positive integ The program displays their greatest common divisor followed by a newline (`'\n'`). -If the number of parameters is different from 2, the program displays nothing. +If the number of arguments is different from 2, the program displays nothing. All arguments tested will be positive `int` values. diff --git a/subjects/hiddenp.en.md b/subjects/hiddenp.en.md index 9b0d7505..f17821e4 100644 --- a/subjects/hiddenp.en.md +++ b/subjects/hiddenp.en.md @@ -8,7 +8,7 @@ Let s1 and s2 be `string`. It is considered that s1 is hidden in s2 if it is pos If s1 is an empty `string` it is considered hidden in any `string`. -If the number of parameters is different from 2, the program displays nothing. +If the number of arguments is different from 2, the program displays nothing. ### Usage diff --git a/subjects/iterativepower.en.md b/subjects/iterativepower.en.md index 99be7810..02618065 100644 --- a/subjects/iterativepower.en.md +++ b/subjects/iterativepower.en.md @@ -28,9 +28,7 @@ import ( func main() { - arg1 := 4 - arg2 := 3 - fmt.Println(piscine.IterativePower(arg1, arg2)) + fmt.Println(piscine.IterativePower(4, 3)) } ``` diff --git a/subjects/lastword.en.md b/subjects/lastword.en.md index 4bc69a8e..5525dec6 100644 --- a/subjects/lastword.en.md +++ b/subjects/lastword.en.md @@ -8,7 +8,7 @@ Write a program that takes a `string` and displays its last word, followed by a - The output will be followed by a newline (`'\n'`). -- If the number of parameters is different from 1, or if there are no word, the program displays nothing. +- If the number of arguments is different from 1, or if there are no word, the program displays nothing. ### Usage diff --git a/subjects/nbrconvertalpha.en.md b/subjects/nbrconvertalpha.en.md index 65e701e5..89c1750f 100644 --- a/subjects/nbrconvertalpha.en.md +++ b/subjects/nbrconvertalpha.en.md @@ -6,7 +6,7 @@ Write a **program** that prints the corresponding letter in the `n` position of For example `1` matches `a`, `2` matches `b`, etc. If `n` does not match a valid position of the alphabet or if the argument is not an integer, the **program** should print a space (" "). -A flag `--upper` should be implemented. When used the program prints the result in upper case. +A flag `--upper` should be implemented. When used the program prints the result in upper case. The flag will always be the first argument. ### Usage diff --git a/subjects/piglatin.en.md b/subjects/piglatin.en.md index d12029d7..c823c0a2 100644 --- a/subjects/piglatin.en.md +++ b/subjects/piglatin.en.md @@ -27,5 +27,5 @@ unchcray$ student@ubuntu:~/student/test$ ./piglatin crnch | cat -e No vowels$ student@ubuntu:~/student/test$ ./piglatin something else | cat -e -$ +student@ubuntu:~/student/test$ ``` diff --git a/subjects/point.en.md b/subjects/point.en.md index 85bae913..35cc4a56 100644 --- a/subjects/point.en.md +++ b/subjects/point.en.md @@ -27,7 +27,7 @@ func main() { } ``` -### Expected output +### Usage ```console student@ubuntu:~/[[ROOT]]/point$ go build diff --git a/subjects/printbits.en.md b/subjects/printbits.en.md index 259e2186..67cf8150 100644 --- a/subjects/printbits.en.md +++ b/subjects/printbits.en.md @@ -6,7 +6,7 @@ Write a program that takes a number as argument, and prints it in binary value * - If the the argument is not a number the program should print `00000000`. -### Expected output : +### Usage : ```console student@ubuntu:~/printbits$ go build diff --git a/subjects/printhex.en.md b/subjects/printhex.en.md index 31ca6614..4c33edac 100644 --- a/subjects/printhex.en.md +++ b/subjects/printhex.en.md @@ -4,22 +4,21 @@ Write a program that takes a positive (or zero) number expressed in base 10, and displays it in base 16 (with lowercase letters) followed by a newline (`'\n'`). -- If the number of parameters is different from 1, the program displays a newline. +- If the number of arguments is different from 1, the program displays nothing. - Error cases have to be handled as shown in the example below. ### Usage ```console student@ubuntu:~/[[ROOT]]/test$ go build -student@ubuntu:~/[[ROOT]]/test$ ./test "10" +student@ubuntu:~/[[ROOT]]/test$ ./test 10 a -student@ubuntu:~/[[ROOT]]/test$ ./test "255" +student@ubuntu:~/[[ROOT]]/test$ ./test 255 ff -student@ubuntu:~/[[ROOT]]/test$ ./test "5156454" +student@ubuntu:~/[[ROOT]]/test$ ./test 5156454 4eae66 student@ubuntu:~/[[ROOT]]/test$ ./test - student@ubuntu:~/[[ROOT]]/test$ ./test "123 132 1" | cat -e -0$ +ERROR$ student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/printmemory.en.md b/subjects/printmemory.en.md index d62fc65a..24360504 100644 --- a/subjects/printmemory.en.md +++ b/subjects/printmemory.en.md @@ -20,8 +20,7 @@ Here is a possible program to test your function : package main func main() { - arr := [10]int{104, 101, 108, 108, 111, 16, 21, 42} - PrintMemory(arr) + PrintMemory([10]int{104, 101, 108, 108, 111, 16, 21, 42}) } ``` diff --git a/subjects/printnbrinorder.en.md b/subjects/printnbrinorder.en.md index 42ee8b7d..fa77895d 100644 --- a/subjects/printnbrinorder.en.md +++ b/subjects/printnbrinorder.en.md @@ -4,7 +4,7 @@ Write a function which prints the digits of an `int` passed in parameter in ascending order. All possible values of type `int` have to go through, besides negative numbers. -Convertion to `int64` is not allowed. +Conversion to `int64` is not allowed. ### Expected function diff --git a/subjects/range.en.md b/subjects/range.en.md index 5d0985e8..3c9fa9a0 100644 --- a/subjects/range.en.md +++ b/subjects/range.en.md @@ -14,7 +14,7 @@ Errors should be handled. If the number of arguments is different from 2 the program prints nothing. -### Expected output : +### Usage : ```console student@ubuntu:~/range$ go build diff --git a/subjects/rectangle.en.md b/subjects/rectangle.en.md index ea1abc02..d8269ad6 100644 --- a/subjects/rectangle.en.md +++ b/subjects/rectangle.en.md @@ -42,7 +42,7 @@ func main() { } ``` -### Expected output +### Usage ```console student@ubuntu:~/[[ROOT]]/test$ go build diff --git a/subjects/recursivepower.en.md b/subjects/recursivepower.en.md index 9f83dbdf..65022253 100644 --- a/subjects/recursivepower.en.md +++ b/subjects/recursivepower.en.md @@ -29,9 +29,7 @@ import ( ) func main() { - arg1 := 4 - arg2 := 3 - fmt.Println(piscine.RecursivePower(arg1, arg2)) + fmt.Println(piscine.RecursivePower(4, 3)) } ``` diff --git a/subjects/reduceint.en.md b/subjects/reduceint.en.md index 7e28ec4a..2f0fa139 100644 --- a/subjects/reduceint.en.md +++ b/subjects/reduceint.en.md @@ -4,12 +4,12 @@ Write a function called `reduceint` that simulates the behaviour of reduce from JavaScript. -The function should have as parameters a function, `f func(int, int) int` and a slice of integers, `arr []int`. You should apply for each element of the slice the arithmetic function, saving it and printing. +The function should have as parameters a slice of integers, `a []int` and a function `f func(int, int) int`. You should apply for each element of the slice the arithmetic function, saving it and printing. ### Expected function ```go -func ReduceInt(f func(int, int) int, arr []int) { +func ReduceInt(a []int, f func(int, int) int) { } ``` @@ -32,9 +32,9 @@ func main() { return acc / cur } as := []int{500, 2} - ReduceInt(mul, as) - ReduceInt(sum, as) - ReduceInt(div, as) + ReduceInt(as, mul) + ReduceInt(as, sum) + ReduceInt(as, div) } ``` diff --git a/subjects/reversestrcap.en.md b/subjects/reversestrcap.en.md index a028f3b1..c636c726 100644 --- a/subjects/reversestrcap.en.md +++ b/subjects/reversestrcap.en.md @@ -2,12 +2,9 @@ ### Instructions -Write a program that takes one or more `string` as arguments and that, **for each argument**: --puts the last character of each word (if it is a letter) in uppercase and the rest -in lowercase --then it displays the result followed by a newline (`'\n'`). +Write a program that takes one or more arguments and that, for each argument, puts the last letter of each word in uppercase and the rest in lowercase. It displays the result followed by a newline (`'\n'`). -If there are no parameter, the program displays a newline. +If there are no argument, the program displays nothing. ### Usage @@ -15,11 +12,10 @@ If there are no parameter, the program displays a newline. student@ubuntu:~/[[ROOT]]/reversestrcap$ go build student@ubuntu:~/[[ROOT]]/reversestrcap$ ./reversestrcap "First SMALL TesT" | cat -e firsT smalL tesT$ -student@ubuntu:~/[[ROOT]]/reversestrcap$ ./reversestrcap go run reversestrcap.go "SEconD Test IS a LItTLE EasIEr" "bEwaRe IT'S NoT HARd WhEN " " Go a dernier 0123456789 for the road e" | cat -e +student@ubuntu:~/[[ROOT]]/reversestrcap$ ./reversestrcap "SEconD Test IS a LItTLE EasIEr" "bEwaRe IT'S NoT HARd WhEN " " Go a dernier 0123456789 for the road e" | cat -e seconD tesT iS A littlE easieR$ bewarE it'S noT harD wheN $ gO A dernieR 0123456789 foR thE roaD E$ -student@ubuntu:~/[[ROOT]]/reversestrcap$ ./reversestrcap | cat -e -$ +student@ubuntu:~/[[ROOT]]/reversestrcap$ ./reversestrcap student@ubuntu:~/[[ROOT]]/reversestrcap$ ``` diff --git a/subjects/revwstr.en.md b/subjects/revwstr.en.md index 749f8f57..4123f40f 100644 --- a/subjects/revwstr.en.md +++ b/subjects/revwstr.en.md @@ -1,4 +1,4 @@ -## revWstr +## revwstr ### Instructions @@ -6,7 +6,7 @@ Write a program that takes a `string` as a parameter, and prints its words in re - A word is a sequence of **alphanumerical** characters. -- If the number of parameters is different from 1, the program will display newline (`'\n'`). +- If the number of arguments is different from 1, the program will display nothing. - In the parameters that are going to be tested, there will not be any extra spaces. (meaning that there will not be additional spaces at the beginning or at the end of the `string` and that words will always be separated by exactly one space). diff --git a/subjects/sqrt.en.md b/subjects/sqrt.en.md index dbfe7c80..19165b78 100644 --- a/subjects/sqrt.en.md +++ b/subjects/sqrt.en.md @@ -25,11 +25,8 @@ import ( ) func main() { - arg1 := 4 - arg2 := 3 - fmt.Println(piscine.Sqrt(arg1)) - fmt.Println(piscine.Sqrt(arg2)) - + fmt.Println(piscine.Sqrt(4)) + fmt.Println(piscine.Sqrt(3)) } ``` diff --git a/subjects/uniqueoccurences.en.md b/subjects/uniqueoccurences.en.md index 3cc94f06..c8a3a520 100644 --- a/subjects/uniqueoccurences.en.md +++ b/subjects/uniqueoccurences.en.md @@ -2,9 +2,9 @@ ### Instructions -Write a program that outputs `true` if the number of occurrences of each character is unique, otherwise `false`. `\n` should be at the of line. +Write a program that outputs `true` if the number of occurrences of each character is unique, otherwise `false`. `\n` should be at the end of the line. -If number of arguments is not 1 output `\n`. +If number of arguments is not 1 output nothing. Only lower case characters will be given. @@ -12,11 +12,11 @@ Only lower case characters will be given. ```console student@ubuntu:~/[[ROOT]]/test$ go build -student@ubuntu:~/[[ROOT]]/test$ ./main "abbaac" +student@ubuntu:~/[[ROOT]]/test$ ./main abbaac true -student@ubuntu:~/[[ROOT]]/test$ ./main "ab" +student@ubuntu:~/[[ROOT]]/test$ ./main ab false -student@ubuntu:~/[[ROOT]]/test$ ./main "abcacccazb" +student@ubuntu:~/[[ROOT]]/test$ ./main abcacccazb true ``` diff --git a/subjects/unmatch.en.md b/subjects/unmatch.en.md index d28f63bb..e58cfb52 100644 --- a/subjects/unmatch.en.md +++ b/subjects/unmatch.en.md @@ -2,14 +2,14 @@ ### Instructions -Write a function, `Unmatch`, that returns the element of the slice (arr) that does not have a correspondent pair. +Write a function, `Unmatch`, that returns the element of the slice that does not have a correspondent pair. - If all the number have a correspondent pair, it shoud return `-1`. ### Expected function ```go -func Unmatch(arr []int) int { +func Unmatch(a []int) int { } ``` @@ -27,8 +27,8 @@ import ( ) func main() { - arr := []int{1, 2, 3, 1, 2, 3, 4} - unmatch := piscine.Unmatch(arr) + a := []int{1, 2, 3, 1, 2, 3, 4} + unmatch := piscine.Unmatch(a) fmt.Println(unmatch) } ``` diff --git a/subjects/wdmatch.en.md b/subjects/wdmatch.en.md index a40ef0d5..cbca204f 100644 --- a/subjects/wdmatch.en.md +++ b/subjects/wdmatch.en.md @@ -4,24 +4,20 @@ Write a program that takes two `string` and checks whether it is possible to write the first `string` with characters from the second `string`, while respecting the order in which these characters appear in the second `string`. -If it is possible, the program displays the `string` followed by a newline (`'\n'`), otherwise it simply displays a newline. +If it is possible, the program displays the `string` followed by a newline (`'\n'`), otherwise it simply displays nothing. -If the number of arguments is different from 2, the program displays a newline. +If the number of arguments is different from 2, the program displays nothing. ### Usage ```console student@ubuntu:~/[[ROOT]]/test$ go build -student@ubuntu:~/[[ROOT]]/test$ ./test "faya" "fgvvfdxcacpolhyghbreda" +student@ubuntu:~/[[ROOT]]/test$ ./test faya fgvvfdxcacpolhyghbreda faya -student@ubuntu:~/[[ROOT]]/test$ ./test "faya" "fgvvfdxcacpolhyghbred" - -student@ubuntu:~/[[ROOT]]/test$ ./test "error" rrerrrfiiljdfxjyuifrrvcoojh - +student@ubuntu:~/[[ROOT]]/test$ ./test faya fgvvfdxcacpolhyghbred +student@ubuntu:~/[[ROOT]]/test$ ./test error rrerrrfiiljdfxjyuifrrvcoojh student@ubuntu:~/[[ROOT]]/test$ ./test "quarante deux" "qfqfsudf arzgsayns tsregfdgs sjytdekuoixq " quarante deux - student@ubuntu:~/[[ROOT]]/test$ ./test - student@ubuntu:~/[[ROOT]]/test$ ```