英文:
Finding string that matches specific requirements
问题
有一个函数应该返回true
:
func accessible(agent string) bool {
a := strings.Split(agent, " ")
if len(a) != 3 { return false }
b := a[0]
c := a[1]
d := a[2]
x := strings.EqualFold(b, c)
y := b != strings.ToLower(c)
z := strings.Index(d, b+c) == 1 && len(d) == 5
return x && y && z
}
然而,我无法找出哪个string
输入符合这些要求。我是否漏掉了什么?
PS:这是来自gocode.io的任务#3。
英文:
There is a function that should return true
:
func accessible(agent string) bool {
a := strings.Split(agent, " ")
if len(a) != 3 { return false }
b := a[0]
c := a[1]
d := a[2]
x := strings.EqualFold(b, c)
y := b != strings.ToLower(c)
z := strings.Index(d, b+c) == 1 && len(d) == 5
return x && y && z
}
However I can't figure out which string
input will match these requirements. Am I missing something?
PS: This is task #3 from gocode.io
答案1
得分: 2
agent
必须是由3个“单词”组成的,3个部分由空格分隔:
a := strings.Split(agent, " ")
if len(a) != 3 { return false }
第一个和第二个单词必须不区分大小写匹配:
x := strings.EqualFold(b, c)
但不区分大小写:
y := b != strings.ToLower(c)
第三个单词必须包含前两个单词的连接:
z := strings.Index(d, b+c) == 1 && len(d) == 5
从索引1
开始(前面添加任何字符),并且必须包含5个字符(5个字节)(后面添加以确保有5个字符/字节)。
示例:
fmt.Println(accessible("A a _Aa__"))
输出:
true
英文:
agent
must be 3 "words", 3 parts separated by spaces:
a := strings.Split(agent, " ")
if len(a) != 3 { return false }
1st and 2nd words must match case insensitive:
x := strings.EqualFold(b, c)
But not case sensitive:
y := b != strings.ToLower(c)
And 3rd word must contain the first 2 concatenated:
z := strings.Index(d, b+c) == 1 && len(d) == 5
Starting at index 1
(prepend with any character) and must contain 5 chars (5 bytes) (postpend to have 5 chars/bytes).
Example:
fmt.Println(accessible("A a _Aa__"))
Prints:
true
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论