forked from root/public
![32063953+xpetit@users.noreply.github.com](/git/assets/img/avatar_default.png)
![xpetit](/git/assets/img/avatar_default.png)
50 changed files with 0 additions and 1266 deletions
@ -1,55 +0,0 @@
|
||||
package main |
||||
|
||||
import "strings" |
||||
|
||||
var m = map[rune]struct{}{} |
||||
|
||||
func uniqueChar(s string) bool { |
||||
for _, r := range s { |
||||
if _, ok := m[r]; ok { |
||||
return false |
||||
} |
||||
m[r] = struct{}{} |
||||
} |
||||
return true |
||||
} |
||||
|
||||
func validBase(base string) bool { |
||||
return len(base) >= 2 && !strings.ContainsAny(base, "+-") && uniqueChar(base) |
||||
} |
||||
|
||||
func power(nbr int, pwr int) int { |
||||
if pwr == 0 { |
||||
return 1 |
||||
} |
||||
if pwr == 1 { |
||||
return nbr |
||||
} |
||||
return nbr * power(nbr, pwr-1) |
||||
} |
||||
|
||||
func AtoiBase(s string, base string) int { |
||||
var result int |
||||
var i int |
||||
sign := 1 |
||||
length := len(s) |
||||
|
||||
if !validBase(base) { |
||||
return 0 |
||||
} |
||||
if s[i] == '-' { |
||||
sign = -1 |
||||
} |
||||
if s[i] == '-' || s[i] == '+' { |
||||
i++ |
||||
} |
||||
for i < len(s) { |
||||
result += strings.Index(base, s[i]) * power(len(base), length-1) |
||||
i++ |
||||
length-- |
||||
} |
||||
return result * sign |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,50 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"./base" |
||||
|
||||
"github.com/01-edu/z01" |
||||
) |
||||
|
||||
// this is the function that creates the TESTS
|
||||
func main() { |
||||
type node struct { |
||||
s string |
||||
base string |
||||
} |
||||
|
||||
table := []node{} |
||||
|
||||
// 5 random pairs of string numbers with valid bases
|
||||
for i := 0; i < 5; i++ { |
||||
validBaseToInput := base.Valid() |
||||
val := node{ |
||||
s: base.StringFrom(validBaseToInput), |
||||
base: validBaseToInput, |
||||
} |
||||
table = append(table, val) |
||||
} |
||||
// 5 random pairs of string numbers with invalid bases
|
||||
for i := 0; i < 5; i++ { |
||||
invalidBaseToInput := base.Invalid() |
||||
val := node{ |
||||
s: "thisinputshouldnotmatter", |
||||
base: invalidBaseToInput, |
||||
} |
||||
table = append(table, val) |
||||
} |
||||
table = append(table, |
||||
node{s: "125", base: "0123456789"}, |
||||
node{s: "1111101", base: "01"}, |
||||
node{s: "7D", base: "0123456789ABCDEF"}, |
||||
node{s: "uoi", base: "choumi"}, |
||||
node{s: "bbbbbab", base: "-ab"}, |
||||
) |
||||
for _, arg := range table { |
||||
z01.ChallengeMain("atoibaseprog", arg.s, arg.base) |
||||
} |
||||
z01.ChallengeMain("atoibaseprog") |
||||
z01.ChallengeMain("atoibaseprog", "125", "0123456789", "something") |
||||
} |
||||
|
||||
// TODO: fix base exercises
|
@ -1,11 +0,0 @@
|
||||
package main |
||||
|
||||
import "strconv" |
||||
|
||||
func Atoi(s string) int { |
||||
n, _ := strconv.Atoi(s) |
||||
return n |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,37 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"strconv" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
table := make([]string, 30) |
||||
for i := range table { |
||||
table[i] = strconv.Itoa(z01.RandInt()) |
||||
} |
||||
table = append(table, |
||||
strconv.Itoa(z01.MinInt), |
||||
strconv.Itoa(z01.MaxInt), |
||||
"", |
||||
"-", |
||||
"+", |
||||
"0", |
||||
"+0", |
||||
"-Invalid123", |
||||
"--123", |
||||
"-+123", |
||||
"++123", |
||||
"123-", |
||||
"123+", |
||||
"123.", |
||||
"123.0", |
||||
"123a45", |
||||
) |
||||
for _, arg := range table { |
||||
z01.Challenge("AtoiProg", Atoi, correct.Atoi, arg) |
||||
} |
||||
} |
@ -1,47 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"strings" |
||||
) |
||||
|
||||
func isAlphaNumerical(r rune) bool { |
||||
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') |
||||
} |
||||
|
||||
func isLowerRune(r rune) bool { |
||||
return r >= 'a' && r <= 'z' |
||||
} |
||||
|
||||
func toUpperRune(r rune) rune { |
||||
if r >= 'a' && r <= 'z' { |
||||
return r - 32 |
||||
} |
||||
return r |
||||
} |
||||
|
||||
func capitalize(s string) string { |
||||
r := []rune(strings.ToLower(s)) |
||||
|
||||
if isLowerRune(r[0]) { |
||||
r[0] = toUpperRune(r[0]) |
||||
} |
||||
|
||||
for i := 1; i < len(r); i++ { |
||||
if (!isAlphaNumerical(r[i-1])) && (isLowerRune(r[i])) { |
||||
r[i] = toUpperRune(r[i]) |
||||
} |
||||
} |
||||
return string(r) |
||||
} |
||||
|
||||
func main() { |
||||
if len(os.Args) == 2 { |
||||
fmt.Println(capitalize(os.Args[1])) |
||||
} else if len(os.Args) > 2 { |
||||
fmt.Println("Too many arguments") |
||||
} else { |
||||
fmt.Println() |
||||
} |
||||
} |
@ -1,20 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
table := append(z01.MultRandASCII(), |
||||
"Hello! How are you? How+are+things+4you?", |
||||
"Hello! How are you?", |
||||
"a", |
||||
"z", |
||||
"!", |
||||
"9a", |
||||
"9a LALALA!", |
||||
) |
||||
for _, arg := range table { |
||||
z01.ChallengeMain("capitalizeprog", arg) |
||||
} |
||||
z01.ChallengeMain("capitalizeprog", "hello", "hihihi") |
||||
z01.ChallengeMain("capitalizeprog") |
||||
} |
@ -1,20 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"strings" |
||||
) |
||||
|
||||
func main() { |
||||
if len(os.Args) == 3 { |
||||
fmt.Println(compare(os.Args[1], os.Args[2])) |
||||
} else { |
||||
fmt.Println() |
||||
} |
||||
} |
||||
|
||||
func compare(s string, toCompare string) int { |
||||
result := strings.Compare(s, toCompare) |
||||
return result |
||||
} |
@ -1,45 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
type node struct { |
||||
s string |
||||
toCompare string |
||||
} |
||||
|
||||
table := []node{} |
||||
|
||||
// the first 7 values are returning 0 for this test
|
||||
for i := 0; i < 7; i++ { |
||||
wordToTest := z01.RandASCII() |
||||
|
||||
val := node{ |
||||
s: wordToTest, |
||||
toCompare: wordToTest, |
||||
} |
||||
table = append(table, val) |
||||
} |
||||
|
||||
// the next 7 values are supposed to return 1 or -1 for this test
|
||||
for i := 0; i < 7; i++ { |
||||
wordToTest := z01.RandASCII() |
||||
wrongMatch := z01.RandASCII() |
||||
|
||||
table = append(table, node{ |
||||
s: wordToTest, |
||||
toCompare: wrongMatch, |
||||
}) |
||||
} |
||||
// those are the test values from the README examples
|
||||
table = append(table, |
||||
node{s: "Hello!", toCompare: "Hello!"}, |
||||
node{s: "Salut!", toCompare: "lut!"}, |
||||
node{s: "Ola!", toCompare: "Ol"}, |
||||
) |
||||
for _, arg := range table { |
||||
z01.ChallengeMain("compareprog", arg.s, arg.toCompare) |
||||
} |
||||
z01.ChallengeMain("compareprog") |
||||
z01.ChallengeMain("compareprog", "1 arg", "2args", "3args") |
||||
} |
@ -1,58 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"strconv" |
||||
) |
||||
|
||||
func main() { |
||||
if len(os.Args) == 4 { |
||||
var result int |
||||
firstArg, 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 { |
||||
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)) { |
||||
fmt.Println(0) |
||||
return |
||||
} |
||||
} else if operator == "-" { |
||||
result = firstArg - secondArg |
||||
if !((result < firstArg) == (secondArg > 0)) { |
||||
fmt.Println(0) |
||||
return |
||||
} |
||||
} else if operator == "/" { |
||||
result = firstArg / secondArg |
||||
} else if operator == "*" { |
||||
result = firstArg * secondArg |
||||
if firstArg != 0 && (result/firstArg != secondArg) { |
||||
fmt.Println(0) |
||||
return |
||||
} |
||||
} else if operator == "%" { |
||||
result = firstArg % secondArg |
||||
} |
||||
fmt.Println(result) |
||||
} |
||||
} |
@ -1,43 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"strings" |
||||
|
||||
"strconv" |
||||
|
||||
"github.com/01-edu/z01" |
||||
) |
||||
|
||||
func main() { |
||||
operatorsTable := []string{"+", "-", "*", "/", "%"} |
||||
|
||||
table := []string{} |
||||
|
||||
for i := 0; i < 4; i++ { |
||||
firstArg := strconv.Itoa(z01.RandIntBetween(-1000, 1000)) |
||||
secondArg := strconv.Itoa(z01.RandIntBetween(0, 1000)) |
||||
|
||||
for _, operator := range operatorsTable { |
||||
table = append(table, firstArg+" "+operator+" "+secondArg) |
||||
|
||||
} |
||||
} |
||||
|
||||
table = append(table, "1 + 1") |
||||
table = append(table, "hello + 1") |
||||
table = append(table, "1 p 1") |
||||
table = append(table, "1 # 1") |
||||
table = append(table, "1 / 0") |
||||
table = append(table, "1 % 0") |
||||
table = append(table, "1 * 1") |
||||
table = append(table, "1argument") |
||||
table = append(table, "2 arguments") |
||||
table = append(table, "4 arguments so invalid") |
||||
table = append(table, "9223372036854775807 + 1") |
||||
table = append(table, "9223372036854775809 - 3") |
||||
table = append(table, "9223372036854775807 * 3") |
||||
|
||||
for _, s := range table { |
||||
z01.ChallengeMain("doopprog", strings.Fields(s)...) |
||||
} |
||||
} |
@ -1,9 +0,0 @@
|
||||
package main |
||||
|
||||
func FirstRune(s string) rune { |
||||
runes := []rune(s) |
||||
return runes[0] |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,20 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
table := append( |
||||
z01.MultRandASCII(), |
||||
"Hello!", |
||||
"Salut!", |
||||
"Ola!", |
||||
"♥01", |
||||
) |
||||
for _, arg := range table { |
||||
z01.Challenge("FirstRuneProg", FirstRune, correct.FirstRune, arg) |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
func ForEach(f func(int), a []int) { |
||||
for _, el := range a { |
||||
f(el) |
||||
} |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,51 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func add0(i int) { |
||||
fmt.Println(i) |
||||
} |
||||
func add1(i int) { |
||||
fmt.Println(i + 1) |
||||
} |
||||
func add2(i int) { |
||||
fmt.Println(i + 2) |
||||
} |
||||
func add3(i int) { |
||||
fmt.Println(i + 3) |
||||
} |
||||
|
||||
func main() { |
||||
functions := []func(int){add0, add1, add2, add3} |
||||
|
||||
type node struct { |
||||
f func(int) |
||||
a []int |
||||
} |
||||
|
||||
table := []node{} |
||||
|
||||
// 15 random slice of random ints with a random function from selection
|
||||
for i := 0; i < 15; i++ { |
||||
function := functions[z01.RandIntBetween(0, len(functions)-1)] |
||||
table = append(table, node{ |
||||
f: function, |
||||
a: z01.MultRandIntBetween(-1000000, 1000000), |
||||
}) |
||||
} |
||||
|
||||
table = append(table, node{ |
||||
f: add0, |
||||
a: []int{1, 2, 3, 4, 5, 6}, |
||||
}) |
||||
|
||||
for _, arg := range table { |
||||
z01.Challenge("ForEachProg", ForEach, correct.ForEach, arg.f, arg.a) |
||||
} |
||||
} |
@ -1,26 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strconv" |
||||
"strings" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
student "../../student" |
||||
) |
||||
|
||||
func ItoaBase(value, base int) string { |
||||
if base < 2 || base > 16 { |
||||
return "" |
||||
} |
||||
return strings.ToUpper(strconv.FormatInt(int64(value), base)) |
||||
} |
||||
|
||||
func main() { |
||||
value := z01.RandIntBetween(-1000000, 1000000) |
||||
base := z01.RandIntBetween(2, 16) |
||||
fmt.Println(student.ItoaBase(141895, 11)) |
||||
|
||||
fmt.Println(ItoaBase(value, base)) |
||||
} |
@ -1,20 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
for i := 0; i < 30; i++ { |
||||
value := z01.RandIntBetween(-1000000, 1000000) |
||||
base := z01.RandIntBetween(2, 16) |
||||
z01.Challenge("ItoaBaseProg", ItoaBase, correct.ItoaBase, value, base) |
||||
} |
||||
for i := 0; i < 5; i++ { |
||||
base := z01.RandIntBetween(2, 16) |
||||
z01.Challenge("ItoaBaseProg", ItoaBase, correct.ItoaBase, z01.MaxInt, base) |
||||
z01.Challenge("ItoaBaseProg", ItoaBase, correct.ItoaBase, z01.MinInt, base) |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "strconv" |
||||
|
||||
func Itoa(v int) string { |
||||
return strconv.Itoa(v) |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
for i := 0; i < 50; i++ { |
||||
arg := z01.RandIntBetween(-2000000000, 2000000000) |
||||
z01.Challenge("ItoaProg", Itoa, correct.Itoa, arg) |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
func LastRune(s string) rune { |
||||
runes := []rune(s) |
||||
index := len(runes) - 1 |
||||
return runes[index] |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,20 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
table := z01.MultRandASCII() |
||||
table = append(table, |
||||
"Hello!", |
||||
"Salut!", |
||||
"Ola!", |
||||
z01.RandStr(z01.RandIntBetween(1, 15), z01.RandAlnum()), |
||||
) |
||||
for _, arg := range table { |
||||
z01.Challenge("LastRuneProg", LastRune, correct.LastRune, arg) |
||||
} |
||||
} |
@ -1,33 +0,0 @@
|
||||
package main |
||||
|
||||
type NodeL struct { |
||||
Data interface{} |
||||
Next *NodeL |
||||
} |
||||
|
||||
type List struct { |
||||
Head *NodeL |
||||
Tail *NodeL |
||||
} |
||||
|
||||
// removes all elements that are equal to the data_ref
|
||||
func ListRemoveIf(l *List, data_ref interface{}) { |
||||
temp := l.Head |
||||
prev := l.Head |
||||
|
||||
for temp != nil && temp.Data == data_ref { |
||||
l.Head = temp.Next |
||||
temp = l.Head |
||||
} |
||||
for temp != nil { |
||||
if temp.Data != data_ref { |
||||
prev = temp |
||||
} |
||||
|
||||
prev.Next = temp.Next |
||||
temp = prev.Next |
||||
} |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,105 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"strconv" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
type Node10 = NodeL |
||||
type List10 = correct.List |
||||
type NodeS10 = correct.NodeL |
||||
type ListS10 = List |
||||
|
||||
func listToStringStu12(l *ListS10) string { |
||||
var res string |
||||
it := l.Head |
||||
for it != nil { |
||||
switch it.Data.(type) { |
||||
case int: |
||||
res += strconv.Itoa(it.Data.(int)) + "-> " |
||||
case string: |
||||
res += it.Data.(string) + "-> " |
||||
} |
||||
it = it.Next |
||||
} |
||||
res += "<nil>" |
||||
return res |
||||
} |
||||
|
||||
func listPushBackTest10(l1 *ListS10, l2 *List10, data interface{}) { |
||||
n := &Node10{Data: data} |
||||
n1 := &NodeS10{Data: data} |
||||
if l1.Head == nil { |
||||
l1.Head = n |
||||
} else { |
||||
iterator := l1.Head |
||||
for iterator.Next != nil { |
||||
iterator = iterator.Next |
||||
} |
||||
iterator.Next = n |
||||
} |
||||
if l2.Head == nil { |
||||
l2.Head = n1 |
||||
} else { |
||||
iterator1 := l2.Head |
||||
for iterator1.Next != nil { |
||||
iterator1 = iterator1.Next |
||||
} |
||||
iterator1.Next = n1 |
||||
} |
||||
} |
||||
|
||||
func comparFuncList10(l1 *List10, l2 *ListS10, data interface{}) { |
||||
for l1.Head != nil || l2.Head != nil { |
||||
if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) { |
||||
z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", |
||||
data, listToStringStu12(l2), correct.ListToString(l1.Head), l2.Head, l1.Head) |
||||
} |
||||
if l1.Head.Data != l2.Head.Data { |
||||
z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n", |
||||
data, listToStringStu12(l2), correct.ListToString(l1.Head), l2.Head.Data, l1.Head.Data) |
||||
} |
||||
l1.Head = l1.Head.Next |
||||
l2.Head = l2.Head.Next |
||||
} |
||||
} |
||||
|
||||
// removes all the elements that are equal to a value
|
||||
func main() { |
||||
link1 := &List10{} |
||||
link2 := &ListS10{} |
||||
table := []correct.NodeTest{} |
||||
|
||||
table = correct.ElementsToTest(table) |
||||
|
||||
table = append(table, |
||||
correct.NodeTest{ |
||||
Data: []interface{}{"hello", "hello1", "hello2", "hello3"}, |
||||
}, |
||||
) |
||||
|
||||
for _, arg := range table { |
||||
for i := 0; i < len(arg.Data); i++ { |
||||
listPushBackTest10(link2, link1, arg.Data[i]) |
||||
} |
||||
aux := len(arg.Data) - 1 |
||||
|
||||
index := z01.RandIntBetween(0, aux) |
||||
if link1.Head != nil && link2.Head != nil { |
||||
cho := arg.Data[index] |
||||
ListRemoveIf(link2, cho) |
||||
correct.ListRemoveIf(link1, cho) |
||||
comparFuncList10(link1, link2, cho) |
||||
} else { |
||||
ListRemoveIf(link2, 1) |
||||
correct.ListRemoveIf(link1, 1) |
||||
comparFuncList10(link1, link2, 1) |
||||
} |
||||
|
||||
link1 = &List10{} |
||||
link2 = &ListS10{} |
||||
} |
||||
} |
@ -1,24 +0,0 @@
|
||||
package main |
||||
|
||||
type NodeL struct { |
||||
Data interface{} |
||||
Next *NodeL |
||||
} |
||||
|
||||
type List struct { |
||||
Head *NodeL |
||||
Tail *NodeL |
||||
} |
||||
|
||||
func ListSize(l *List) int { |
||||
count := 0 |
||||
iterator := l.Head |
||||
for iterator != nil { |
||||
count++ |
||||
iterator = iterator.Next |
||||
} |
||||
return count |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,60 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
type Node2 = NodeL |
||||
type List2 = correct.List |
||||
type NodeS2 = correct.NodeL |
||||
type ListS2 = List |
||||
|
||||
func listPushBackTest2(l *ListS2, l1 *List2, data interface{}) { |
||||
n := &Node2{Data: data} |
||||
n1 := &NodeS2{Data: data} |
||||
if l.Head == nil { |
||||
l.Head = n |
||||
} else { |
||||
iterator := l.Head |
||||
for iterator.Next != nil { |
||||
iterator = iterator.Next |
||||
} |
||||
iterator.Next = n |
||||
} |
||||
|
||||
if l1.Head == nil { |
||||
l1.Head = n1 |
||||
} else { |
||||
iterator1 := l1.Head |
||||
for iterator1.Next != nil { |
||||
iterator1 = iterator1.Next |
||||
} |
||||
iterator1.Next = n1 |
||||
} |
||||
} |
||||
|
||||
func main() { |
||||
link := &List2{} |
||||
link2 := &ListS2{} |
||||
table := []correct.NodeTest{} |
||||
table = correct.ElementsToTest(table) |
||||
table = append(table, |
||||
correct.NodeTest{ |
||||
Data: []interface{}{"Hello", "man", "how are you"}, |
||||
}, |
||||
) |
||||
for _, arg := range table { |
||||
for i := 0; i < len(arg.Data); i++ { |
||||
listPushBackTest2(link2, link, arg.Data[i]) |
||||
} |
||||
aux := correct.ListSize(link) |
||||
aux2 := ListSize(link2) |
||||
if aux != aux2 { |
||||
z01.Fatalf("ListSize(%v) == %d instead of %d\n", correct.ListToString(link.Head), aux2, aux) |
||||
} |
||||
link = &List2{} |
||||
link2 = &ListS2{} |
||||
} |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
import "sort" |
||||
|
||||
func Max(a []int) int { |
||||
if len(a) == 0 { |
||||
return 0 |
||||
} |
||||
sort.Ints(a) |
||||
return a[len(a)-1] |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,17 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
args := []int{z01.RandInt()} |
||||
limit := z01.RandIntBetween(20, 50) |
||||
for i := 0; i < limit; i++ { |
||||
args = append(args, z01.RandInt()) |
||||
} |
||||
|
||||
z01.Challenge("MaxProg", Max, correct.Max, args) |
||||
} |
@ -1,38 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"strconv" |
||||
|
||||
correct ".." |
||||
) |
||||
|
||||
func NRune(s string, n int) rune { |
||||
if n > len(s) || n < 1 { |
||||
return 0 |
||||
} |
||||
runes := []rune(s) |
||||
return runes[n-1] |
||||
} |
||||
|
||||
func main() { |
||||
if len(os.Args) != 3 { |
||||
return |
||||
} |
||||
val, err := strconv.Atoi(os.Args[2]) |
||||
|
||||
if err != nil { |
||||
fmt.Printf("\"%s\" is not an integer value\n", os.Args[2]) |
||||
return |
||||
} |
||||
|
||||
rune := correct.NRune(os.Args[1], val) |
||||
|
||||
if rune == 0 { |
||||
fmt.Printf("Invalid position: \"%d\" in \"%s\"\n", val, os.Args[1]) |
||||
return |
||||
} |
||||
|
||||
fmt.Printf("%c\n", rune) |
||||
} |
@ -1,43 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"math/rand" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
type node struct { |
||||
word string |
||||
n int |
||||
} |
||||
|
||||
table := []node{} |
||||
|
||||
for i := 0; i < 30; i++ { |
||||
wordToInput := z01.RandASCII() |
||||
val := node{ |
||||
word: wordToInput, |
||||
n: rand.Intn(len(wordToInput)) + 1, |
||||
} |
||||
table = append(table, val) |
||||
} |
||||
|
||||
table = append(table, |
||||
node{word: "Hello!", n: 3}, |
||||
node{word: "Salut!", n: 2}, |
||||
node{word: "Ola!", n: 4}, |
||||
node{word: "♥01!", n: 1}, |
||||
node{word: "Not", n: 6}, |
||||
node{word: "Also not", n: 9}, |
||||
node{word: "Tree house", n: 5}, |
||||
node{word: "Whatever", n: 0}, |
||||
node{word: "Whatshisname", n: -2}, |
||||
) |
||||
|
||||
for _, arg := range table { |
||||
z01.Challenge("NRuneProg", NRune, correct.NRune, arg.word, arg.n) |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "fmt" |
||||
|
||||
func main() { |
||||
for r := 'a'; r <= 'z'; r++ { |
||||
fmt.Print(r) |
||||
} |
||||
fmt.Println() |
||||
} |
@ -1,7 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
z01.ChallengeMain("printalphabetprog") |
||||
} |
@ -1,25 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func printComb() { |
||||
for i := '0'; i <= '7'; i++ { |
||||
for j := i + 1; j <= '8'; j++ { |
||||
for k := j + 1; k <= '9'; k++ { |
||||
z01.PrintRune(i) |
||||
z01.PrintRune(j) |
||||
z01.PrintRune(k) |
||||
if i < '7' { |
||||
z01.PrintRune(',') |
||||
z01.PrintRune(' ') |
||||
} else { |
||||
z01.PrintRune('\n') |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
func main() { |
||||
printComb() |
||||
} |
@ -1,7 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
z01.ChallengeMain("printcombprog") |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
for i := '0'; i <= '9'; i++ { |
||||
z01.PrintRune(i) |
||||
} |
||||
z01.PrintRune('\n') |
||||
} |
@ -1,7 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
z01.ChallengeMain("printdigitsprog") |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "fmt" |
||||
|
||||
func main() { |
||||
for r := 'z'; r >= 'a'; r-- { |
||||
fmt.Print(r) |
||||
} |
||||
fmt.Println() |
||||
} |
@ -1,7 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
z01.ChallengeMain("printreversealphabetprog") |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
) |
||||
|
||||
func main() { |
||||
if len(os.Args) != 2 { |
||||
return |
||||
} |
||||
|
||||
fmt.Println(os.Args[1]) |
||||
} |
@ -1,11 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
table := z01.MultRandASCII() |
||||
for _, arg := range table { |
||||
z01.ChallengeMain("printstrprog", arg) |
||||
} |
||||
z01.ChallengeMain("printstrprog", "Hello World!") |
||||
} |
@ -1,32 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
) |
||||
|
||||
func main() { |
||||
if len(os.Args) != 2 { |
||||
return |
||||
} |
||||
|
||||
var result string |
||||
|
||||
for _, r := range os.Args[1] { |
||||
if r >= 'a' && r <= 'z' { |
||||
if r >= 'm' { |
||||
r -= 12 |
||||
} else { |
||||
r += 14 |
||||
} |
||||
} else if r >= 'A' && r <= 'Z' { |
||||
if r >= 'M' { |
||||
r -= 12 |
||||
} else { |
||||
r += 14 |
||||
} |
||||
} |
||||
result += string(r) |
||||
} |
||||
fmt.Println(result) |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
table := append(z01.MultRandWords(), |
||||
z01.MultRandWords()..., |
||||
) |
||||
|
||||
for _, arg := range table { |
||||
z01.ChallengeMain("rot14prog", arg) |
||||
} |
||||
z01.ChallengeMain("rot14prog", "", "something", "something1") |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "sort" |
||||
|
||||
func SortWordArr(a []string) { |
||||
sort.Strings(a) |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,39 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"reflect" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}} |
||||
|
||||
for i := 0; i < 15; i++ { |
||||
table = append(table, z01.MultRandWords()) |
||||
} |
||||
|
||||
for _, org := range table { |
||||
// copy for using the solution function
|
||||
cp_sol := make([]string, len(org)) |
||||
// copy for using the student function
|
||||
cp_stu := make([]string, len(org)) |
||||
|
||||
copy(cp_sol, org) |
||||
copy(cp_stu, org) |
||||
|
||||
correct.SortWordArr(cp_sol) |
||||
SortWordArr(cp_stu) |
||||
|
||||
if !reflect.DeepEqual(cp_stu, cp_sol) { |
||||
z01.Fatalf("%s(%v) == %v instead of %v\n", |
||||
"SortWordArr", |
||||
org, |
||||
cp_stu, |
||||
cp_sol, |
||||
) |
||||
} |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "strings" |
||||
|
||||
func Split(s, sep string) []string { |
||||
return strings.Split(s, sep) |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,46 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"math/rand" |
||||
"strings" |
||||
|
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
separators := []string{ |
||||
"!=HA=!", |
||||
"!==!", |
||||
" ", |
||||
"|=choumi=|", |
||||
"|<=>|", |
||||
z01.RandStr(3, z01.RuneRange('A', 'Z')), |
||||
"<<==123==>>", |
||||
"[<>abc<>]", |
||||
} |
||||
|
||||
type node struct { |
||||
str string |
||||
sep string |
||||
} |
||||
table := []node{} |
||||
// 15 random slice of strings
|
||||
|
||||
for i := 0; i < 15; i++ { |
||||
separator := separators[rand.Intn(len(separators))] |
||||
val := node{ |
||||
str: strings.Join(z01.MultRandAlnum(), separator), |
||||
sep: separator, |
||||
} |
||||
table = append(table, val) |
||||
} |
||||
|
||||
table = append(table, |
||||
node{str: "HelloHAhowHAareHAyou?", sep: "HA"}) |
||||
|
||||
for _, arg := range table { |
||||
z01.Challenge("SplitProg", Split, correct.Split, arg.str, arg.sep) |
||||
} |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
func StrLen(str string) int { |
||||
len := 0 |
||||
|
||||
strConverted := []rune(str) |
||||
for i := range strConverted { |
||||
len = i + 1 |
||||
} |
||||
return len |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,24 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/01-edu/z01" |
||||
|
||||
correct "./correct" |
||||
) |
||||
|
||||
func main() { |
||||
randomStringCharset := "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ" |
||||
|
||||
table := []string{} |
||||
for i := 0; i < 10; i++ { |
||||
randomLenghtOfWord := z01.RandIntBetween(1, 20) |
||||
randomStrRandomLenght := z01.RandStr(randomLenghtOfWord, randomStringCharset) |
||||
table = append(table, randomStrRandomLenght) |
||||
} |
||||
table = append(table, "Héllo!") |
||||
table = append(table, randomStringCharset) |
||||
|
||||
for _, s := range table { |
||||
z01.Challenge("StrLenProg", StrLen, correct.StrLen, s) |
||||
} |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
) |
||||
|
||||
func main() { |
||||
if len(os.Args) != 2 { |
||||
return |
||||
} |
||||
|
||||
fmt.Println(correct.StrRev(os.Args[1])) |
||||
} |
@ -1,14 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
table := append(z01.MultRandASCII(), |
||||
"Hello!", |
||||
"Bonjour!", |
||||
"Hola!", |
||||
) |
||||
for _, arg := range table { |
||||
z01.ChallengeMain("strrevprog", arg) |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
func Swap(a, b *int) { |
||||
temp := *a |
||||
*a = *b |
||||
*b = temp |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,21 +0,0 @@
|
||||
package main |
||||
|
||||
import "github.com/01-edu/z01" |
||||
|
||||
func main() { |
||||
i := 0 |
||||
for i < 30 { |
||||
a := z01.RandInt() |
||||
b := z01.RandInt() |
||||
aCopy := a |
||||
bCopy := b |
||||
Swap(&a, &b) |
||||
if a != bCopy { |
||||
z01.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy) |
||||
} |
||||
if b != aCopy { |
||||
z01.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy) |
||||
} |
||||
i++ |
||||
} |
||||
} |
Loading…
Reference in new issue