假设100个人以1到100的顺序站成一个圆圈.1号有一把剑.他杀死了下一个人(即第2号)并将剑交给下一个人(即第3号).所有人都这样做,直到只有1人幸存.最后一个幸存的是哪个号码?
有100人从1到100.
我试过了
persons <- c(1:100)
for (i in 1:100) {
qu <- persons[seq_along(persons) %% 2 > 0]
if (q2 == 2) {
print(q2[2])
}
}
Run Code Online (Sandbox Code Playgroud)
还有这个
q=0
while(q==0){ persons=persons[seq_along(persons) %% 2 > 0]
if(length(persons)==2){ print(persons[2])
q=1}}
Run Code Online (Sandbox Code Playgroud)
但这给出了答案,因为65这是错误的,并没有解决目的.
如何做到这一点的任何解决方案?
我有一个字符串,我想提取两个文本之间的所有单词,这样:
var str="This is the number I want +2143334 !, again this is the next number I want +234343443 !, last number I want +76645 !, fininshed";
var ext = str.split('want').pop().split('!,').shift();
alert(ext);
Run Code Online (Sandbox Code Playgroud)
但这只是给出了+2143334.我想要的是三个匹配,即:
+2143334, +234343443, +76645
Run Code Online (Sandbox Code Playgroud)
怎么做到呢?