创建Java组合锁(Creating a Java Combination Lock)
我正在从事计算机科学任务,我不能为我的生活弄清楚为什么这不起作用。
我们应该创建一个组合锁(通过构造函数),提示用户输出拼写密码的字母。
踢球者必须首先允许用户犯一些错误。 例如,如果密码是
D O G
用户可以输入
A B C D O G
它会解锁组合锁。
附加的代码可能是我的...第五次尝试,我不太确定为什么它不起作用。 有任何想法吗?
编辑:
Code on ideone: http://ideone.com/D3yFYt http://ideone.com/jzMNjJ
提前致谢!!
I'm working on a computer science assignment, and I can't for the life of me figure out why this isn't working.
We're supposed to create a combination lock (via a constructor) that prompts the user for letters that spell out the password.
The kicker is that it has to allow the user to make a few mistakes at first. For example, if the password were
D O G
the user could type in
A B C D O G
And it would unlock the combination lock.
The attached code is probably my... Fifth attempt at this, and i'm not quite sure why it's not working. Any ideas?
EDIT:
Code on ideone: http://ideone.com/D3yFYt http://ideone.com/jzMNjJ
Thanks in advance!!
原文:https://stackoverflow.com/questions/14892142
最满意答案
实现您所需要的一种方法是使用来自
zoo
包的rollapply
。library(zoo) rollapply(x, width = 7, by = 4, mean) #[1] 622.1429 682.8571 540.7143
数据
x <-c(267, 497, 836, 498, 923, 836, 498, 923, 267, 497, 836, 498, 923, 267, 497)
One way to achieve what you need is by using
rollapply
fromzoo
package.library(zoo) rollapply(x, width = 7, by = 4, mean) #[1] 622.1429 682.8571 540.7143
DATA
x <-c(267, 497, 836, 498, 923, 836, 498, 923, 267, 497, 836, 498, 923, 267, 497)
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我们需要使用is.na df$a_output <- replace(as.character(df$a), is.na(df$a), "") 另外,如果我们检查'a'列的class ,它是factor ,所以''应该是factor列中的一个级别 levels(df$a) <- c(levels(df$a), "") df$a[is.na(df$a)] <- "" 或者我们转换为character并将其replace为第一种方法 We need to use is.na df$a_output <- r ...
-
当向量长度为1时,R中的sample()不可预测[重复](sample() in R unpredictable when vector length is one [duplicate])[2022-02-23]
来自help("sample") : 如果x的长度为1,则为数字(在is.numeric意义上)且x> = 1,则样本采样从1:x进行。 因此,当你有remaining = 2 , sample(remaining)相当于sample(x = 1:2) 更新 从评论中可以清楚地看到,您也正在寻找解决此问题的方法。 以下是三个提到的替代方案的基准比较: library(microbenchmark) # if remaining is of length one remaining <- 2 microb ... -
实现您所需要的一种方法是使用来自zoo包的rollapply 。 library(zoo) rollapply(x, width = 7, by = 4, mean) #[1] 622.1429 682.8571 540.7143 数据 x <-c(267, 497, 836, 498, 923, 836, 498, 923, 267, 497, 836, 498, 923, 267, 497) One way to achieve what you need is by using rollapply ...
-
#with(rle(TF), sequence(lengths) * rep(values, lengths)) with(rle(TF), sequence(lengths) * TF) #Like Rich suggested in comments # [1] 0 1 2 3 0 0 1 2 0 1 0 1 2 3 4 5 6 7 0 #with(rle(TF), sequence(lengths) * rep(values, lengths)) with(rle(TF), sequence(len ...
-
如何在R中的向量中仅删除重复值的一个实例?(How to remove only one instance of a duplicate value in a vector in R?)[2022-10-14]
你还不完全清楚问题的范围是什么,所以我只想给出我想到的第一个建议。 使用sort函数按递减顺序获取值列表。 sorted <- sort(x,decreasing=TRUE,index.return=TRUE) 您现在可以迭代地从x删除最高项目。 在子集数据上反复使用sort功能效率很低 - 如果可能的话,最好保留x的永久副本并从中删除。 考虑这种方法 # random set of data with duplicates x <- floor(runif(50)*15) # sort with inde ... -
R中的重复向量[重复](Repetitive vectors in R [duplicate])[2023-12-13]
你需要rep的each参数: > rep(1:5, each = 3) [1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 You need the each parameter within rep: > rep(1:5, each = 3) [1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 -
尝试match基数R: with(df, B[match(sel, A)]) #[1] 5 1 5 5 Try with match in base R: with(df, B[match(sel, A)]) #[1] 5 1 5 5
-
我们不需要循环,只需使用pmax do.call(pmax, df1) #[1] 19 20 21 22 如果我们需要使用for循环,最好创建一个长度等于数据集行数('v')的vector ,并为每个'v'元素分配我们从循环遍历每个元素的max行 f <- function(dat) { v <- numeric(nrow(dat)) for (i in seq_len(nrow(dat))) { v[i] <- max(unlist(dat[i,])) } v } f(df1) ...
-
R:根据具有重复值的数字向量重新排序级别(R: reorder levels according to numeric vector with duplicate values)[2022-05-16]
要避免“重复”警告并在v3创建有序因子(按v2排序),您可以执行以下操作: df %>% mutate(v3 = factor(v3, ordered=TRUE, levels=unique(df[order(df$v2),"v3"][[1]]))) To avoid the "duplicate" warnings and also create an ordered factor over v3 (ordere ...