N2ILL7A2E7WCFJEDCMNX6EQHA7EWSJSIN5T4YNTRQZC7KGWJ332AC
package sublist
type Relation string
func Sublist(A, B []int) Relation {
// log.Println(A, B)
switch {
case equal(A, B):
return "equal"
case sublist(A, B):
return "sublist"
case sublist(B, A):
return "superlist"
default:
return "unequal"
}
}
func sublist(short, long []int) bool {
// if short is longer than long it can not be a sublist of long
if len(short) > len(long) {
return false
}
for i := range long {
var subset = true
for offset := range short {
if i+offset >= len(long) {
return false
}
if long[i+offset] != short[offset] {
subset = false
break
}
}
if subset {
return true
}
}
return false
}
func equal(A, B []int) bool {
if len(A) == len(B) {
for i, elem := range A {
if elem != B[i] {
return false
}
}
} else {
return false
}
return true
}