【发布时间】:2025-12-26 10:50:07
【问题描述】:
从一个随机的数字序列{"1", "2", "3", "4", "5"}中,要求确定3个连续数字组出现的次数,表示, 已生成的次数基数 = c ("1", "2", "3", "4", "5") 以下任意组 {"123", "234", " 345" }。
# I undertand that I have generate a sample with 5 numbers
a<-c(sample(1:5,5))
a
#I generated the list, as you can see I didn't fix a seed because I know that in every single sequence I will have differents grupos of 3 consecutive numbers, so I should obtain something like this
b<-c(2,3,4,5,1) #this example gives me just one that it would be {2,3,4}
b
#answer expected
1
#Then, I don't know how to obtain the sequence I have tried with permutations and combinations but I don't get it.
【问题讨论】:
-
你计算重叠的组吗?如果你有一个序列 1、2、3、4、5,你会数出 123、234、345 吗?还是只有 1 个 123?
-
{2,4,5} 不连续。它们只是在增加。你想要哪个,连续的还是增加的?
-
“连续”是否包括环绕? 451, 512?