forked from root/public
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.0 KiB
61 lines
1.0 KiB
![]()
4 years ago
|
package main
|
||
![]()
4 years ago
|
|
||
![]()
4 years ago
|
import (
|
||
![]()
4 years ago
|
student "student"
|
||
|
|
||
|
"lib"
|
||
![]()
4 years ago
|
)
|
||
![]()
4 years ago
|
|
||
|
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
|
||
|
}
|
||
![]()
4 years ago
|
|
||
![]()
4 years ago
|
func main() {
|
||
![]()
4 years ago
|
type node struct {
|
||
|
min int
|
||
|
max int
|
||
|
}
|
||
|
table := []node{}
|
||
|
|
||
![]()
4 years ago
|
// 15 random pairs of ints for a Valid Range
|
||
![]()
4 years ago
|
for i := 0; i < 15; i++ {
|
||
![]()
4 years ago
|
minVal := lib.RandIntBetween(-10000000, 1000000)
|
||
|
gap := lib.RandIntBetween(1, 20)
|
||
![]()
4 years ago
|
val := node{
|
||
|
min: minVal,
|
||
|
max: minVal + gap,
|
||
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
![]()
4 years ago
|
|
||
|
// 15 random pairs of ints with ||invalid range||
|
||
![]()
4 years ago
|
for i := 0; i < 15; i++ {
|
||
![]()
4 years ago
|
minVal := lib.RandIntBetween(-10000000, 1000000)
|
||
|
gap := lib.RandIntBetween(1, 20)
|
||
![]()
4 years ago
|
val := node{
|
||
|
min: minVal,
|
||
|
max: minVal - gap,
|
||
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
|
||
|
table = append(table,
|
||
|
node{min: 0, max: 1},
|
||
|
node{min: 0, max: 0},
|
||
|
node{min: 5, max: 10},
|
||
|
node{min: 10, max: 5},
|
||
|
)
|
||
|
|
||
|
for _, arg := range table {
|
||
![]()
4 years ago
|
lib.Challenge("AppendRange", student.AppendRange, appendRange, arg.min, arg.max)
|
||
![]()
4 years ago
|
}
|
||
|
}
|